rusefi/firmware/development/perf_trace.h

115 lines
2.5 KiB
C
Raw Permalink Normal View History

2019-11-24 21:57:36 -08:00
/**
* @file perf_trace.h
*
2021-12-29 12:38:35 -08:00
* https://github.com/rusefi/rusefi/wiki/Developer-Performance-Tracing
*
2019-11-24 21:57:36 -08:00
*/
2019-10-11 17:43:21 -07:00
#pragma once
#include "big_buffer.h"
2019-10-11 17:43:21 -07:00
#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 occurred.
2019-10-11 17:43:21 -07:00
enum class PE : uint8_t {
2020-10-03 21:15:40 -07:00
// The tag below is consumed by PerfTraceTool.java which generates EnumNames.java
2019-11-24 21:57:36 -08:00
// enum_start_tag
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,
AdcProcessSlow,
2019-10-11 17:43:21 -07:00
AdcConversionSlow,
AdcConversionFast,
AdcSubscriptionUpdateSubscribers,
2019-10-13 13:14:08 -07:00
GetRunningFuel,
GetInjectionDuration,
HandleFuel,
MainTriggerCallback,
OnTriggerEventSparkLogic,
ShaftPositionListeners,
GetBaseFuel,
GetTpsEnrichment,
GetSpeedDensityFuel,
WallFuelAdjust,
MapAveragingTriggerCallback,
Unused1,
2019-10-13 13:14:08 -07:00
SingleTimerExecutorScheduleByTimestamp,
2019-12-10 18:18:35 -08:00
GetTimeNowUs,
2019-10-13 13:14:08 -07:00
EventQueueExecuteCallback,
PwmGeneratorCallback,
2019-10-14 23:34:12 -07:00
TunerStudioHandleCrcCommand,
Unused,
2019-10-14 23:34:12 -07:00
PwmConfigStateChangeCallback,
2019-12-10 19:18:37 -08:00
Temporary1,
Temporary2,
Temporary3,
Temporary4,
EngineSniffer,
PrepareIgnitionSchedule,
Hip9011IntHoldCallback,
GlobalLock,
GlobalUnlock,
SoftwareKnockProcess,
2020-10-03 21:15:40 -07:00
LogTriggerTooth,
LuaTickFunction,
LuaOneCanRxFunction,
LuaAllCanRxFunction,
LuaOneCanRxCallback,
LuaOneCanTxFunction,
2019-11-24 21:57:36 -08:00
// enum_end_tag
// The tag above is consumed by PerfTraceTool.java
// please note that the tool requires a comma at the end of last value
2019-10-11 17:43:21 -07:00
};
void perfEventBegin(PE event);
void perfEventEnd(PE event);
void perfEventInstantGlobal(PE event);
2019-10-11 17:43:21 -07:00
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();
2019-10-14 23:34:12 -07:00
// Retrieve the trace buffer
const BigBufferHandle perfTraceGetBuffer();
2019-10-11 17:43:21 -07:00
#if ENABLE_PERF_TRACE
2019-10-11 17:43:21 -07:00
class ScopePerf
{
public:
ScopePerf(PE event) : m_event(event) {
perfEventBegin(event);
2019-10-11 17:43:21 -07:00
}
~ScopePerf()
{
perfEventEnd(m_event);
2019-10-11 17:43:21 -07:00
}
private:
const PE m_event;
};
#else /* if ENABLE_PERF_TRACE */
struct ScopePerf {
ScopePerf(PE) {}
};
#endif /* ENABLE_PERF_TRACE */