KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_chooser_timing.h
Go to the documentation of this file.
1/*
2 * Symbol chooser timing instrumentation.
3 *
4 * Enable with environment variable:
5 * KICAD_TRACE=KI_TRACE_SYM_CHOOSER
6 *
7 * Logs lines of the form:
8 * KI_TRACE_SYM_CHOOSER | step=<name> step_ms=XX.XXX total_ms=YY.YYY mode=cold|warm [extra]
9 *
10 * "cold" = first symbol chooser session (initial library load)
11 * "warm" = subsequent sessions (should mostly hit caches)
12 */
13
14#pragma once
15
16#include <chrono>
17#include <wx/string.h>
18#include <trace_helpers.h>
19
21{
22 using clock = std::chrono::steady_clock;
23 using ms = std::chrono::duration<double, std::milli>;
24
25 inline clock::time_point g_start_time; // Set at beginning of PickSymbolFromLibrary
26 inline bool g_started = false;
27 inline bool g_firstRun = true; // Cleared after first full AddLibraries call
28
29 inline void Start()
30 {
31 g_start_time = clock::now();
32 g_started = true;
33 }
34
35 inline double TotalMs()
36 {
37 if( !g_started )
38 return 0.0;
39 return ms( clock::now() - g_start_time ).count();
40 }
41
42 // Helper object to measure and log incremental steps relative to g_start_time
44 {
45 public:
47 {
48 m_last = g_started ? g_start_time : clock::now();
49 }
50
51 void Log( const char* aStep, const wxString& aExtra = wxEmptyString )
52 {
53 auto now = clock::now();
54 double step_ms = ms( now - m_last ).count();
55 double total_ms = g_started ? ms( now - g_start_time ).count() : step_ms;
56 m_last = now;
57
58 KI_TRACE( wxT("KI_TRACE_SYM_CHOOSER"), wxT("step=%s step_ms=%.3f total_ms=%.3f mode=%s%s%s\n"),
59 wxString::FromUTF8( aStep ).c_str(), step_ms, total_ms,
60 g_firstRun ? wxT("cold") : wxT("warm"),
61 aExtra.IsEmpty() ? wxT("") : wxT(" "),
62 aExtra.c_str() );
63 }
64
65 private:
66 clock::time_point m_last;
67 };
68
69 inline void LogRaw( const char* aStep, double aStepMs, double aTotalMs, const wxString& aExtra = wxEmptyString )
70 {
71 KI_TRACE( wxT("KI_TRACE_SYM_CHOOSER"), wxT("step=%s step_ms=%.3f total_ms=%.3f mode=%s%s%s\n"),
72 wxString::FromUTF8( aStep ).c_str(), aStepMs, aTotalMs,
73 g_firstRun ? wxT("cold") : wxT("warm"),
74 aExtra.IsEmpty() ? wxT("") : wxT(" "),
75 aExtra.c_str() );
76 }
77}
void Log(const char *aStep, const wxString &aExtra=wxEmptyString)
void LogRaw(const char *aStep, double aStepMs, double aTotalMs, const wxString &aExtra=wxEmptyString)
std::chrono::steady_clock clock
std::chrono::duration< double, std::milli > ms
clock::time_point g_start_time
wxLogTrace helper definitions.
#define KI_TRACE(aWhat,...)