diff options
| author | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2026-09-26 23:24:03 +0200 |
| commit | 059831534c7e884f0a607ed86b582fd00d821731 (patch) | |
| tree | 76bcb67a78f8aa2654fd34c2ad801a62136b0170 /PerformanceTrace.hpp | |
| parent | d83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff) | |
New upstream version 3.2.0~rc1+dfsgupstream/3.2.0_rc1+dfsg
Diffstat (limited to 'PerformanceTrace.hpp')
| -rw-r--r-- | PerformanceTrace.hpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/PerformanceTrace.hpp b/PerformanceTrace.hpp new file mode 100644 index 00000000..81ff56a2 --- /dev/null +++ b/PerformanceTrace.hpp @@ -0,0 +1,54 @@ +#ifndef PERFORMANCE_TRACE_HPP_ +#define PERFORMANCE_TRACE_HPP_ + +#include <QtGlobal> +#include <QString> + +namespace PerformanceTrace +{ + using RunId = quint64; + + // Measurements use one process-wide monotonic clock and are logged at INFO + // severity. The functions are thread-safe, but an individual Phase object + // must remain on one thread. Runs are retained until process exit so delayed + // asynchronous milestones can still be attributed to their originating run. + // Enable WSJT-X Diagnostic logging to capture the emitted "PERF" records. + + // A run groups related measurements on a shared monotonic timeline. The + // category and kind are emitted verbatim, so keep them stable and free of + // whitespace for log analysis. Records identify milestones, timed phases, + // and run ends explicitly through the event field. + RunId begin_run (char const * category, char const * kind); + RunId current_run (); + void finish_run (RunId run, char const * phase, QString const& details = {}); + qint64 elapsed_ms (); + + // Pass an explicit run from asynchronous work. current_run() may refer to a + // newer operation by the time a worker thread or queued callback completes. + // A finished run still accepts such explicitly attributed measurements. + void milestone (char const * phase, QString const& details = {}); + void milestone (RunId run, char const * phase, QString const& details = {}); + + // Phase records its duration when destroyed. Call finish() when details must + // accompany the measurement; subsequent calls and destruction are no-ops. + class Phase final + { + public: + explicit Phase (char const * phase); + Phase (RunId run, char const * phase); + ~Phase () noexcept; + + Phase (Phase const&) = delete; + Phase& operator= (Phase const&) = delete; + + void finish (QString const& details = {}); + + private: + RunId run_; + QString phase_; + qint64 started_ms_; + bool finished_ {false}; + }; +} + +#endif |
