diff options
| author | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
| commit | c25cbdf6fb6d946175f4335fab77bfea601b56db (patch) | |
| tree | 6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /PerformanceTrace.hpp | |
| parent | 71f5689252c9f13e70e1c24856904475b2307809 (diff) | |
| parent | 0685fcada9f95fe90f70b387cd7d757da8209624 (diff) | |
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
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 |
