rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Enumerations | Functions | Variables
perf_trace.cpp File Reference

Detailed Description

https://github.com/rusefi/rusefi/wiki/Developer-Performance-Tracing

See JsonOutput.java in rusEfi console

Definition in file perf_trace.cpp.

Enumerations

enum class  EPhase : char { Start , End , InstantThread , InstantGlobal }
 

Functions

static void stopTrace ()
 
static void perfEventImpl (PE event, EPhase phase)
 
void perfEventBegin (PE event)
 
void perfEventEnd (PE event)
 
void perfEventInstantGlobal (PE event)
 
void perfTraceEnable ()
 
const BigBufferHandle perfTraceGetBuffer ()
 

Variables

static BigBufferHandle s_traceBuffer
 
static size_t s_nextIdx = 0
 
static bool s_isTracing = false
 

Enumeration Type Documentation

◆ EPhase

enum class EPhase : char
strong
Enumerator
Start 
End 
InstantThread 
InstantGlobal 

Definition at line 15 of file perf_trace.cpp.

16{
17 Start,
18 End,
21};
@ InstantGlobal
@ InstantThread

Function Documentation

◆ perfEventBegin()

void perfEventBegin ( PE  event)

Definition at line 107 of file perf_trace.cpp.

107 {
109}
static void perfEventImpl(PE event, EPhase phase)

Referenced by irqEnterHook(), and ScopePerf::ScopePerf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfEventEnd()

void perfEventEnd ( PE  event)

Definition at line 111 of file perf_trace.cpp.

111 {
113}

Referenced by irqExitHook(), and ScopePerf::~ScopePerf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfEventImpl()

static void perfEventImpl ( PE  event,
EPhase  phase 
)
static

Definition at line 48 of file perf_trace.cpp.

48 {
49#if EFI_PROD_CODE
50 // Bail if we aren't allowed to trace
51 if constexpr (!ENABLE_PERF_TRACE) {
52 return;
53 }
54
55 // Bail if we aren't tracing
56 if (!s_isTracing || !s_traceBuffer) {
57 return;
58 }
59
60 // todo: why doesn't getTimeNowLowerNt() work here?
61 // It returns 0 like we're in a unit test
62 uint32_t timestamp = port_rt_get_counter_value();
63
64 size_t idx;
65
66 // Critical section: disable interrupts to reserve an index.
67 // We could lock, but this gets called a LOT - so locks could
68 // significantly alter the results of the measurement.
69 // In addition, if we want to trace lock/unlock events, we can't
70 // be locking ourselves from the trace functionality.
71 {
72 uint32_t prim = __get_PRIMASK();
73 __disable_irq();
74
75 idx = s_nextIdx++;
76 if (s_nextIdx >= TRACE_BUFFER_LENGTH) {
77 stopTrace();
78 }
79
80 // Restore previous interrupt state - don't restore if they weren't enabled
81 if (!prim) {
82 __enable_irq();
83 }
84 }
85
86 // We can safely write data out of the lock, our spot is reserved
87 volatile TraceEntry& entry = s_traceBuffer.get<TraceEntry>()[idx];
88
89 entry.Event = event;
90 entry.Phase = phase;
91 // Get the current active interrupt - this is the "process ID"
92 auto isr = static_cast<int8_t>(SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk);
93 entry.IsrId = isr - 16;
94
95 // Get the current thread (if not interrupt) and use as the thread ID
96 if (isr == 0) {
97 entry.ThreadId = chThdGetSelfX()->threadId;
98 } else {
99 // Interrupts have no thread - all are T0
100 entry.ThreadId = 0;
101 }
102
103 entry.Timestamp = timestamp;
104#endif // EFI_PROD_CODE
105}
const TBuffer * get() const
Definition big_buffer.h:34
static bool s_isTracing
static BigBufferHandle s_traceBuffer
static size_t s_nextIdx
static void stopTrace()

Referenced by perfEventBegin(), perfEventEnd(), and perfEventInstantGlobal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfEventInstantGlobal()

void perfEventInstantGlobal ( PE  event)

Definition at line 115 of file perf_trace.cpp.

115 {
117}

Referenced by contextSwitchHook(), onLockHook(), and onUnlockHook().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfTraceEnable()

void perfTraceEnable ( )

Definition at line 119 of file perf_trace.cpp.

119 {
120#if EFI_TOOTH_LOGGER
121 // force release of the buffer if occupied by the tooth logger
122 if (IsToothLoggerEnabled()) {
123 // don't worry, it will be automatically enabled
124 // when the next TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY command arrives
126 }
127#endif // EFI_TOOTH_LOGGER
129 s_isTracing = true;
130}
BigBufferHandle getBigBuffer(BigBufferUser user)
void DisableToothLogger()
bool IsToothLoggerEnabled()

Referenced by TunerStudio::handleCrcCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perfTraceGetBuffer()

const BigBufferHandle perfTraceGetBuffer ( )

Definition at line 132 of file perf_trace.cpp.

132 {
133 // stop tracing if you try to get the buffer early
134 stopTrace();
135
136 // transfer ownership of the buffer to the caller
137 return efi::move(s_traceBuffer);
138}
constexpr remove_reference_t< _Ty > && move(_Ty &&_Arg) noexcept
Definition efilib.h:126

Referenced by TunerStudio::handleCrcCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopTrace()

static void stopTrace ( )
static

Definition at line 43 of file perf_trace.cpp.

43 {
44 s_isTracing = false;
45 s_nextIdx = 0;
46}

Referenced by perfEventImpl(), and perfTraceGetBuffer().

Here is the caller graph for this function:

Variable Documentation

◆ s_isTracing

bool s_isTracing = false
static

Definition at line 41 of file perf_trace.cpp.

Referenced by perfEventImpl(), perfTraceEnable(), and stopTrace().

◆ s_nextIdx

size_t s_nextIdx = 0
static

Definition at line 39 of file perf_trace.cpp.

Referenced by perfEventImpl(), and stopTrace().

◆ s_traceBuffer

BigBufferHandle s_traceBuffer
static

Definition at line 38 of file perf_trace.cpp.

Referenced by perfEventImpl(), perfTraceEnable(), and perfTraceGetBuffer().

Go to the source code of this file.