rusefi-1/firmware/development/perf_trace.h

104 lines
2.3 KiB
C
Raw Normal View History

2019-10-11 17:43:21 -07:00
#pragma once
#include <cstdint>
2019-10-14 23:34:12 -07:00
#include <cstddef>
2019-10-11 17:43:21 -07:00
// Defines different events we want to trace. These can be an interval (begin -> end), or an
// instant. Instants can be global, or specific to one thread. You probably don't want to use
// each element in PE more than once, as they should each indicate that a specific thing began,
// ended, or occured.
enum class PE : uint8_t {
2019-10-13 13:14:08 -07:00
INVALID,
2019-10-11 17:43:21 -07:00
ISR,
ContextSwitch,
OutputPinSetValue,
DecodeTriggerEvent,
EnginePeriodicFastCallback,
EnginePeriodicSlowCallback,
EngineStatePeriodicFastCallback,
HandleShaftSignal,
EventQueueInsertTask,
EventQueueExecuteAll,
SingleTimerExecutorDoExecute,
SingleTimerExecutorScheduleTimerCallback,
PeriodicControllerPeriodicTask,
PeriodicTimerControllerPeriodicTask,
AdcCallbackFast,
AdcCallbackSlow,
AdcConversionSlow,
AdcConversionFast,
AdcSubscriptionUpdateSubscribers,
2019-10-13 13:14:08 -07:00
GetRunningFuel,
GetInjectionDuration,
HandleFuel,
MainTriggerCallback,
OnTriggerEventSparkLogic,
ShaftPositionListeners,
GetBaseFuel,
GetTpsEnrichment,
GetSpeedDensityFuel,
WallFuelAdjust,
MapAveragingTriggerCallback,
AdcCallbackFastComplete,
SingleTimerExecutorScheduleByTimestamp,
ScheduleByAngle,
EventQueueExecuteCallback,
PwmGeneratorCallback,
2019-10-14 23:34:12 -07:00
TunerStudioHandleCrcCommand,
PwmConfigTogglePwmState,
PwmConfigStateChangeCallback,
2019-10-11 17:43:21 -07:00
};
void perfEventBegin(PE event, uint8_t data);
void perfEventEnd(PE event, uint8_t data);
void perfEventInstantGlobal(PE event, uint8_t data);
inline void perfEventBegin(PE event) {
perfEventBegin(event, 0);
}
inline void perfEventEnd(PE event) {
perfEventEnd(event, 0);
}
inline void perfEventInstantGlobal(PE event) {
perfEventInstantGlobal(event, 0);
}
2019-10-14 23:34:12 -07:00
// Enable one buffer's worth of perf tracing, and retrieve the buffer size in bytes
2019-10-14 23:40:51 -07:00
void perfTraceEnable();
struct TraceBufferResult
{
const uint8_t* const Buffer;
const size_t Size;
};
2019-10-14 23:34:12 -07:00
// Retrieve the trace buffer
2019-10-14 23:40:51 -07:00
const TraceBufferResult perfTraceGetBuffer();
2019-10-11 17:43:21 -07:00
class ScopePerf
{
public:
ScopePerf(PE event) : ScopePerf(event, 0) {}
2019-10-13 13:14:08 -07:00
ScopePerf(PE event, uint8_t data) : m_event(event), m_data(data)
2019-10-11 17:43:21 -07:00
{
#if ENABLE_PERF_TRACE
2019-10-11 17:43:21 -07:00
perfEventBegin(event, data);
#endif /* ENABLE_PERF_TRACE */
2019-10-11 17:43:21 -07:00
}
~ScopePerf()
{
#if ENABLE_PERF_TRACE
2019-10-13 13:14:08 -07:00
perfEventEnd(m_event, m_data);
#endif /* ENABLE_PERF_TRACE */
2019-10-11 17:43:21 -07:00
}
private:
const PE m_event;
2019-10-13 13:14:08 -07:00
const uint8_t m_data;
2019-10-11 17:43:21 -07:00
};