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
20
namespace
SYM_CHOOSER_TIMING
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
43
class
STEP_LOGGER
44
{
45
public
:
46
STEP_LOGGER
()
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
wxLogTrace( 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
wxLogTrace( 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
}
SYM_CHOOSER_TIMING::STEP_LOGGER::Log
void Log(const char *aStep, const wxString &aExtra=wxEmptyString)
Definition
symbol_chooser_timing.h:51
SYM_CHOOSER_TIMING::STEP_LOGGER::m_last
clock::time_point m_last
Definition
symbol_chooser_timing.h:66
SYM_CHOOSER_TIMING::STEP_LOGGER::STEP_LOGGER
STEP_LOGGER()
Definition
symbol_chooser_timing.h:46
SYM_CHOOSER_TIMING
Definition
symbol_chooser_timing.h:21
SYM_CHOOSER_TIMING::g_firstRun
bool g_firstRun
Definition
symbol_chooser_timing.h:27
SYM_CHOOSER_TIMING::g_started
bool g_started
Definition
symbol_chooser_timing.h:26
SYM_CHOOSER_TIMING::LogRaw
void LogRaw(const char *aStep, double aStepMs, double aTotalMs, const wxString &aExtra=wxEmptyString)
Definition
symbol_chooser_timing.h:69
SYM_CHOOSER_TIMING::clock
std::chrono::steady_clock clock
Definition
symbol_chooser_timing.h:22
SYM_CHOOSER_TIMING::ms
std::chrono::duration< double, std::milli > ms
Definition
symbol_chooser_timing.h:23
SYM_CHOOSER_TIMING::g_start_time
clock::time_point g_start_time
Definition
symbol_chooser_timing.h:25
SYM_CHOOSER_TIMING::Start
void Start()
Definition
symbol_chooser_timing.h:29
SYM_CHOOSER_TIMING::TotalMs
double TotalMs()
Definition
symbol_chooser_timing.h:35
trace_helpers.h
wxLogTrace helper definitions.
src
eeschema
symbol_chooser_timing.h
Generated on Sun Apr 26 2026 00:06:47 for KiCad PCB EDA Suite by
1.13.2