1818#define DEBUG_PRINT (...)
1919#endif
2020
21+
22+ static inline void start_ticks_cpu () {
23+ CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
24+ DWT->CYCCNT = 0 ;
25+ DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
26+ }
27+
28+ static inline uint32_t ticks_cpu () {
29+ return DWT->CYCCNT ;
30+ }
31+
32+ static uint32_t ticks[10 ];
33+ static uint32_t ticks_index = 0 ;
34+ static bool ticks_start_average = false ;
35+ static inline uint32_t calcTicks (uint32_t ticks_start, uint32_t ticks_end) {
36+ ticks[ticks_index] = ticks_end - ticks_start;
37+ ticks_index++;
38+ if (ticks_index >= 9 ) {
39+ ticks_start_average = true ;
40+ ticks_index = 0 ;
41+ }
42+
43+ if (!ticks_start_average) {
44+ return 0 ;
45+ }
46+
47+ uint32_t ticksAverage = 0 ;
48+ for (size_t i = 0 ; i < 10 ; i++) {
49+ ticksAverage += ticks[i];
50+ }
51+ return ticksAverage / 10 ;
52+ }
53+
54+
2155namespace testrunner {
2256 static ml_actions_t *actions = NULL ;
2357 static ml_predictions_t *predictions = NULL ;
@@ -43,7 +77,9 @@ namespace testrunner {
4377
4478 unsigned int time_start = system_timer_current_time_us ();
4579
80+ int32_t ticks_start = ticks_cpu () & 0x7FFFFFFF ;
4681 float *modelData = mlDataProcessor.getProcessedData ();
82+ int32_t ticks_end = ticks_cpu () & 0x7FFFFFFF ;
4783 if (modelData == NULL ) {
4884 DEBUG_PRINT (" Failed to processed data for the model\n " );
4985 uBit.panic (TEST_RUNNER_ERROR + 21 );
@@ -60,8 +96,8 @@ namespace testrunner {
6096
6197 unsigned int time_end = system_timer_current_time_us ();
6298
63- DEBUG_PRINT (" Prediction (%d micros + %d micros): " ,
64- time_mid - time_start, time_end - time_mid);
99+ DEBUG_PRINT (" Prediction (%d micros + %d micros, %d ticks ): " ,
100+ time_mid - time_start, time_end - time_mid, calcTicks (ticks_start, ticks_end) );
65101 if (predictions->index >= 0 ) {
66102 DEBUG_PRINT (" %d %s\n " ,
67103 predictions->index ,
@@ -218,6 +254,8 @@ namespace testrunner {
218254 uBit.messageBus .listen (TEST_RUNNER_ID_TIMER, ML_CODAL_TIMER_VALUE, &recordAccData, MESSAGE_BUS_LISTENER_DROP_IF_BUSY);
219255 uBit.timer .eventEvery (samplesPeriodMillisec, TEST_RUNNER_ID_TIMER, ML_CODAL_TIMER_VALUE);
220256
257+ start_ticks_cpu ();
258+
221259 initialised = true ;
222260
223261 DEBUG_PRINT (" \t Model loaded\n " );
0 commit comments