Debug timers added (use -DDEBUG_TIMERS=YES to enable and CLI command "print dt" to see them)

This commit is contained in:
Damjan Adamic
2016-04-03 19:27:47 +02:00
parent a8aa6148e5
commit 2990e9b9a3
11 changed files with 517 additions and 276 deletions
+89
View File
@@ -256,5 +256,94 @@ extern void CoTaskSwitchHook(uint8_t taskID);
#endif // #if defined(DEBUG_TASKS)
#if defined(DEBUG_TIMERS)
#if defined(__cplusplus)
typedef uint32_t debug_timer_t;
class DebugTimer
{
private:
debug_timer_t min;
debug_timer_t max;
// debug_timer_t avg;
debug_timer_t last; //unit 1us
uint16_t _start_hiprec;
uint32_t _start_loprec;
void evalStats() {
if (min > last) min = last;
if (max < last) max = last;
//todo avg
}
public:
DebugTimer(): min(-1), max(0), /*avg(0),*/ last(0), _start_hiprec(0), _start_loprec(0) {};
void start();
void stop();
void sample() { stop(); start(); }
void reset() { min = -1; max = last = 0; }
debug_timer_t getMin() const { return min; }
debug_timer_t getMax() const { return max; }
debug_timer_t getLast() const { return last; }
};
enum DebugTimers {
debugTimerIntPulses,
debugTimerIntPulsesDuration,
debugTimerPer10ms,
debugTimerRotEnc,
debugTimerHaptic,
debugTimerMixer,
debugTimerTelemetryWakeup,
debugTimerPerMain,
debugTimerPerMain1,
debugTimerGuiMain,
debugTimerLuaBg,
debugTimerLcdRefreshWait,
debugTimerLuaFg,
debugTimerLcdRefresh,
debugTimerMenus,
debugTimerMenuHandlers,
debugTimerVersion,
debugTimerSimpleMenu,
debugTimerDrawText,
debugTimerDrawText1,
debugTimerGetAdc,
debugTimerGetSwitches,
debugTimerEvalMixes,
debugTimerMixes10ms,
debugTimerAdcRead,
debugTimerAdcLoop,
debugTimerAdcWait,
DEBUG_TIMERS_COUNT
};
extern DebugTimer debugTimers[DEBUG_TIMERS_COUNT];
extern const char * debugTimerNames[DEBUG_TIMERS_COUNT];
#endif // #if defined(__cplusplus)
#define DEBUG_TIMER_START(timer) debugTimers[timer].start()
#define DEBUG_TIMER_STOP(timer) debugTimers[timer].stop()
#define DEBUG_TIMER_SAMPLE(timer) debugTimers[timer].sample()
#else //#if defined(DEBUG_TIMERS)
#define DEBUG_TIMER_START(timer)
#define DEBUG_TIMER_STOP(timer)
#define DEBUG_TIMER_SAMPLE(timer)
#endif //#if defined(DEBUG_TIMERS)
#endif // _DEBUG_H_