Timing expansion: measurements per function (CLAUDE)

This commit is contained in:
Niklas Jensen
2025-12-26 20:19:54 +01:00
parent 27efdbb69d
commit cfc686e984
3 changed files with 58 additions and 7 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ class IMU : public SensorBase<IMUAnglesMsg> {
#endif
#if FT_ENABLED(USE_ICM20948)
#if FT_ENABLED(USE_ICM20948_SPIMODE) > 0
SPI_PORT.begin(SPI_SCK, SPI_MISO, SPI_MOSI, -1);
SPI_PORT.begin(SPI_SCK, SPI_MISO, SPI_MOSI, -1); // TODO: Move to global spi start
_imu = (ICM_20948_SPI*)_arg;
#ifndef ICM20948_ALIVE
#define ICM20948_ALIVE
+46
View File
@@ -39,3 +39,49 @@
name##_count = 0; \
last_time = esp_timer_get_time() / 1000; \
}
#define CALLS_PER_SECOND_TIMED_START_TICK(name, function) \
static uint64_t name##_##function##_start = 0; \
static uint64_t name##_##function##_total_time = 0; \
static uint64_t name##_##function##_call_count = 0; \
name##_##function##_start = esp_timer_get_time();
#define CALLS_PER_SECOND_TIMED_END_TICK(name, function) \
name##_##function##_total_time += (esp_timer_get_time() - name##_##function##_start); \
name##_##function##_call_count++;
#define CALLS_PER_SECOND_TIMED_CALL(name, function, call) \
static uint64_t name##_##function##_total_time = 0; \
static uint64_t name##_##function##_call_count = 0; \
do { \
uint64_t name##_##function##_start = esp_timer_get_time(); \
call; \
name##_##function##_total_time += (esp_timer_get_time() - name##_##function##_start); \
name##_##function##_call_count++; \
} while (0)
#define CALLS_PER_SECOND_TIMED_FUNC_PRINT(name, function) \
if (name##_##function##_call_count > 0) { \
uint64_t avg = name##_##function##_total_time / name##_##function##_call_count; \
if (avg < 1000) { \
ESP_LOGI("Timing", " %s: %llu us (avg over %llu calls)", \
#function, avg, name##_##function##_call_count); \
} else { \
ESP_LOGI("Timing", " %s: %llu ms (avg over %llu calls)", \
#function, avg / 1000, name##_##function##_call_count); \
} \
name##_##function##_total_time = 0; \
name##_##function##_call_count = 0; \
}
#define CALLS_PER_SECOND_TIMED(name, ...) \
do { \
static uint64_t name##_last_print = 0; \
uint64_t name##_current_time = esp_timer_get_time() / 1000; \
if (name##_current_time - name##_last_print >= 1000) { \
ESP_LOGI("Timing", "=== %s Average Timings ===", #name); \
__VA_ARGS__ \
name##_last_print = name##_current_time; \
} \
} while (0)
+11 -6
View File
@@ -124,15 +124,20 @@ void IRAM_ATTR SpotControlLoopEntry(void *) {
motionService.begin();
for (;;) {
CALLS_PER_SECOND(SpotControlLoopEntry);
peripherals.update();
motionService.update(&peripherals);
servoController.setAngles(motionService.getAngles());
servoController.update();
CALLS_PER_SECOND_TIMED_CALL(SpotControlLoopEntry, peripherals_update, peripherals.update());
CALLS_PER_SECOND_TIMED_CALL(SpotControlLoopEntry, motionService_update, motionService.update(&peripherals));
CALLS_PER_SECOND_TIMED_CALL(SpotControlLoopEntry, servoController_setAngles, servoController.setAngles(motionService.getAngles()));
CALLS_PER_SECOND_TIMED_CALL(SpotControlLoopEntry, servoController_update, servoController.update());
#if FT_ENABLED(USE_WS2812)
ledService.loop();
#endif
vTaskDelayUntil(&xLastWakeTime, xFrequency);
CALLS_PER_SECOND_TIMED(SpotControlLoopEntry,
CALLS_PER_SECOND_TIMED_FUNC_PRINT(SpotControlLoopEntry, peripherals_update)
CALLS_PER_SECOND_TIMED_FUNC_PRINT(SpotControlLoopEntry, motionService_update)
CALLS_PER_SECOND_TIMED_FUNC_PRINT(SpotControlLoopEntry, servoController_setAngles)
CALLS_PER_SECOND_TIMED_FUNC_PRINT(SpotControlLoopEntry, servoController_update)
);
// vTaskDelayUntil(&xLastWakeTime, xFrequency);
}
}