From 4b4678074b15556d6afa7326ffdd2a338be5e2ff Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 21 Nov 2019 15:31:55 -0500 Subject: [PATCH] Perf trace maybe fix - "We were trying to trace before the os was awake" --- firmware/development/perf_trace.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/firmware/development/perf_trace.cpp b/firmware/development/perf_trace.cpp index 3e1f328cda..84302a5d4c 100644 --- a/firmware/development/perf_trace.cpp +++ b/firmware/development/perf_trace.cpp @@ -26,19 +26,23 @@ struct TraceEntry uint32_t Timestamp; }; +// Ensure that the struct is the size we think it is - the binary layout is important static_assert(sizeof(TraceEntry) == 8); +// This buffer stores a trace - we write the full buffer once, then disable tracing static TraceEntry s_traceBuffer[TRACE_BUFFER_LENGTH]; static size_t s_nextIdx = 0; -static bool s_isTracing = true; +static bool s_isTracing = false; void perfEventImpl(PE event, EPhase phase, uint8_t data) { + // Bail if we aren't allowed to trace if constexpr (!ENABLE_PERF_TRACE) { return; } + // Bail if we aren't tracing if (!s_isTracing) { return; } @@ -67,6 +71,7 @@ void perfEventImpl(PE event, EPhase phase, uint8_t data) entry.Event = event; entry.Phase = phase; + // Get the current active interrupt - this is the "thread ID" entry.ThreadId = static_cast(SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk); entry.Timestamp = timestamp; entry.Data = data;