diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index eb4dc6e5b4..20b5cd3e17 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -72,6 +72,7 @@ extern bool main_loop_started; #include "flash_main.h" #include "max31855.h" #include "vehicle_speed.h" +#include "SingleTimerExecutor.h" #endif static bool subscription[(int) RO_LAST_ELEMENT]; @@ -672,6 +673,10 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ int rpm = 0; #endif +#if EFI_PROD_CODE || defined(__DOXYGEN__) + executorStatistics(); +#endif + float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); float coolant = getCoolantTemperature(PASS_ENGINE_PARAMETER_SIGNATURE); float intake = getIntakeAirTemperature(PASS_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/system/SingleTimerExecutor.cpp b/firmware/controllers/system/SingleTimerExecutor.cpp index 683e91c473..09ac9be85a 100644 --- a/firmware/controllers/system/SingleTimerExecutor.cpp +++ b/firmware/controllers/system/SingleTimerExecutor.cpp @@ -17,8 +17,9 @@ #include "efitime.h" #include "efilib2.h" -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) #include "microsecond_timer.h" +#include "tunerstudio_configuration.h" #endif #if (EFI_SIGNAL_EXECUTOR_ONE_TIMER && EFI_PROD_CODE )|| defined(__DOXYGEN__) @@ -52,6 +53,7 @@ static void executorCallback(void *arg) { Executor::Executor() { reentrantFlag = false; + doExecuteCounter = scheduleCounter = timerCallbackCounter = 0; /** * todo: a good comment */ @@ -60,6 +62,7 @@ Executor::Executor() { void Executor::scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) { + scheduleCounter++; // if (delayUs < 0) { // firmwareError(OBD_PCM_Processor_Fault, "Negative delayUs %s: %d", prefix, delayUs); // return; @@ -85,6 +88,7 @@ void Executor::scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schf } void Executor::onTimerCallback() { + timerCallbackCounter++; bool alreadyLocked = lockAnyContext(); doExecute(); scheduleTimerCallback(); @@ -96,6 +100,7 @@ void Executor::onTimerCallback() { * this private method is executed under lock */ void Executor::doExecute() { + doExecuteCounter++; /** * Let's execute actions we should execute at this point. * reentrantFlag takes care of the use case where the actions we are executing are scheduling @@ -162,10 +167,21 @@ void scheduleByTime(scheduling_s *scheduling, efitimeus_t time, schfunc_t callba void initSignalExecutorImpl(void) { globalTimerCallback = executorCallback; -#if EFI_PROD_CODE initMicrosecondTimer(); -#endif /* EFI_PROD_CODE */ } -#endif +extern TunerStudioOutputChannels tsOutputChannels; +#include "engine.h" +EXTERN_ENGINE; + + +void executorStatistics() { + if (engineConfiguration->debugMode == DM_18) { + tsOutputChannels.debugIntField1 = instance.timerCallbackCounter; + tsOutputChannels.debugIntField2 = instance.doExecuteCounter; + tsOutputChannels.debugIntField3 = instance.scheduleCounter; + } +} + +#endif /* EFI_SIGNAL_EXECUTOR_ONE_TIMER */ diff --git a/firmware/controllers/system/SingleTimerExecutor.h b/firmware/controllers/system/SingleTimerExecutor.h index 3362496bba..ae2252e051 100644 --- a/firmware/controllers/system/SingleTimerExecutor.h +++ b/firmware/controllers/system/SingleTimerExecutor.h @@ -16,6 +16,9 @@ public: Executor(); void scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param); void onTimerCallback(); + int timerCallbackCounter; + int scheduleCounter; + int doExecuteCounter; private: EventQueue queue; bool reentrantFlag; @@ -24,5 +27,6 @@ private: }; void initSignalExecutorImpl(void); +void executorStatistics(); #endif /* SINGLETIMEREXECUTOR_H_ */