Libs/Common/Profiling.h
Namespaces
| Name |
|---|
| shapeworks User usage reporting (telemetry) |
Classes
| Name | |
|---|---|
| struct | shapeworks::ProfileEntry |
| struct | shapeworks::TraceEvent |
| class | shapeworks::TimerStackEntry |
| class | shapeworks::Profiler |
| class | shapeworks::ScopedTimer |
Defines
| Name | |
|---|---|
| TIME_START(name) | |
| TIME_STOP(name) | |
| TIME_SCOPE(name) | |
| TIME_FINALIZE() |
Macros Documentation
define TIME_START
```cpp
define TIME_START(
name
) shapeworks::Profiler::instance().start_timer(name); ```
define TIME_STOP
```cpp
define TIME_STOP(
name
) shapeworks::Profiler::instance().stop_timer(name); ```
define TIME_SCOPE
```cpp
define TIME_SCOPE(
name
) shapeworks::ScopedTimer scoped_timer##LINE(name) ```
define TIME_FINALIZE
```cpp
define TIME_FINALIZE(
) shapeworks::Profiler::instance().finalize() ```
Source code
```cpp
pragma once
include
include
include
include
include
include
namespace shapeworks {
//--------------------------------------------------------------------------- struct ProfileEntry { QString name; double exclusive_time_ms; double inclusive_time_ms; int call_count; int subcall_count; Qt::HANDLE thread_id; };
//--------------------------------------------------------------------------- struct TraceEvent { QString name; QString phase; // "B" for begin, "E" for end qint64 timestamp_us; Qt::HANDLE thread_id; int process_id; };
//--------------------------------------------------------------------------- class TimerStackEntry { public: TimerStackEntry(const QString& name, qint64 start_time_us);
QString name; qint64 start_time_us; double accumulated_child_time_ms; };
//--------------------------------------------------------------------------- class Profiler { public: static Profiler& instance();
void start_timer(const QString& name); void stop_timer(const QString& name); void finalize();
bool is_profiling_enabled() const { return profiling_enabled_; } bool is_tracing_enabled() const { return tracing_enabled_; }
private: Profiler(); ~Profiler();
void write_profile_report(); void write_trace_file(); QString format_time(double ms);
bool profiling_enabled_; bool tracing_enabled_; qint64 start_time_us_;
QMutex mutex_;
std::unordered_map
QElapsedTimer elapsed_timer_; };
//--------------------------------------------------------------------------- class ScopedTimer { public: ScopedTimer(const QString& name); ~ScopedTimer();
private: QString name_; bool enabled_; };
} // namespace shapeworks
// Profiling macros
define TIME_START(name) shapeworks::Profiler::instance().start_timer(name);
define TIME_STOP(name) shapeworks::Profiler::instance().stop_timer(name);
define TIME_SCOPE(name) shapeworks::ScopedTimer scoped_timer##LINE(name)
define TIME_FINALIZE() shapeworks::Profiler::instance().finalize()
```
Updated on 2026-03-31 at 16:02:11 +0000