From cc3552b03287095131af5328373f575b1c62e322 Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Wed, 2 Mar 2022 00:30:04 +0000 Subject: [PATCH] Report true average task execution time in tasks report --- src/main/cli/cli.c | 6 +++--- src/main/io/dashboard.c | 6 +++--- src/main/scheduler/scheduler.c | 3 ++- src/main/scheduler/scheduler.h | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index e8a919a520..5830f77b51 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -4929,20 +4929,20 @@ static void cliTasks(const char *cmdName, char *cmdline) int taskFrequency = taskInfo.averageDeltaTime10thUs == 0 ? 0 : lrintf(1e7f / taskInfo.averageDeltaTime10thUs); cliPrintf("%02d - (%15s) ", taskId, taskInfo.taskName); const int maxLoad = taskInfo.maxExecutionTimeUs == 0 ? 0 : (taskInfo.maxExecutionTimeUs * taskFrequency) / 1000; - const int averageLoad = taskInfo.averageExecutionTimeUs == 0 ? 0 : (taskInfo.averageExecutionTimeUs * taskFrequency) / 1000; + const int averageLoad = taskInfo.averageExecutionTime10thUs == 0 ? 0 : (taskInfo.averageExecutionTime10thUs * taskFrequency) / 10000; if (taskId != TASK_SERIAL) { averageLoadSum += averageLoad; } if (systemConfig()->task_statistics) { #if defined(USE_LATE_TASK_STATISTICS) cliPrintLinef("%6d %7d %7d %4d.%1d%% %4d.%1d%% %9d %6d %6d %7d", - taskFrequency, taskInfo.maxExecutionTimeUs, taskInfo.averageExecutionTimeUs, + taskFrequency, taskInfo.maxExecutionTimeUs, taskInfo.averageExecutionTime10thUs / 10, maxLoad/10, maxLoad%10, averageLoad/10, averageLoad%10, taskInfo.totalExecutionTimeUs / 1000, taskInfo.lateCount, taskInfo.runCount, taskInfo.execTime); #else cliPrintLinef("%6d %7d %7d %4d.%1d%% %4d.%1d%% %9d", - taskFrequency, taskInfo.maxExecutionTimeUs, taskInfo.averageExecutionTimeUs, + taskFrequency, taskInfo.maxExecutionTimeUs, taskInfo.averageExecutionTime10thUs / 10, maxLoad/10, maxLoad%10, averageLoad/10, averageLoad%10, taskInfo.totalExecutionTimeUs / 1000); #endif diff --git a/src/main/io/dashboard.c b/src/main/io/dashboard.c index 03f1447264..7a06178cb0 100644 --- a/src/main/io/dashboard.c +++ b/src/main/io/dashboard.c @@ -555,9 +555,9 @@ static void showTasksPage(void) getTaskInfo(taskId, &taskInfo); if (taskInfo.isEnabled && taskId != TASK_SERIAL) {// don't waste a line of the display showing serial taskInfo const int taskFrequency = (int)(1000000.0f / ((float)taskInfo.latestDeltaTimeUs)); - const int maxLoad = (taskInfo.maxExecutionTimeUs * taskFrequency + 5000) / 10000; - const int averageLoad = (taskInfo.averageExecutionTimeUs * taskFrequency + 5000) / 10000; - tfp_sprintf(lineBuffer, format, taskId, taskInfo.maxExecutionTimeUs, taskInfo.averageExecutionTimeUs, maxLoad, averageLoad); + const int maxLoad = taskInfo.maxExecutionTimeUs == 0 ? 0 : (taskInfo.maxExecutionTimeUs * taskFrequency) / 1000; + const int averageLoad = taskInfo.averageExecutionTime10thUs == 0 ? 0 : (taskInfo.averageExecutionTime10thUs * taskFrequency) / 10000; + tfp_sprintf(lineBuffer, format, taskId, taskInfo.maxExecutionTimeUs, taskInfo.averageExecutionTime10thUs / 10, maxLoad, averageLoad); padLineBuffer(); i2c_OLED_set_line(dev, rowIndex++); i2c_OLED_send_string(dev, lineBuffer); diff --git a/src/main/scheduler/scheduler.c b/src/main/scheduler/scheduler.c index f43cbe19e2..d14b79200c 100644 --- a/src/main/scheduler/scheduler.c +++ b/src/main/scheduler/scheduler.c @@ -217,7 +217,7 @@ void getTaskInfo(taskId_e taskId, taskInfo_t * taskInfo) taskInfo->subTaskName = getTask(taskId)->attribute->subTaskName; taskInfo->maxExecutionTimeUs = getTask(taskId)->maxExecutionTimeUs; taskInfo->totalExecutionTimeUs = getTask(taskId)->totalExecutionTimeUs; - taskInfo->averageExecutionTimeUs = getTask(taskId)->anticipatedExecutionTime >> TASK_EXEC_TIME_SHIFT; + taskInfo->averageExecutionTime10thUs = getTask(taskId)->movingSumExecutionTime10thUs / TASK_STATS_MOVING_SUM_COUNT; taskInfo->averageDeltaTime10thUs = getTask(taskId)->movingSumDeltaTime10thUs / TASK_STATS_MOVING_SUM_COUNT; taskInfo->latestDeltaTimeUs = getTask(taskId)->taskLatestDeltaTimeUs; taskInfo->movingAverageCycleTimeUs = getTask(taskId)->movingAverageCycleTimeUs; @@ -389,6 +389,7 @@ FAST_CODE timeUs_t schedulerExecuteTask(task_t *selectedTask, timeUs_t currentTi selectedTask->attribute->taskFunc(currentTimeBeforeTaskCallUs); taskExecutionTimeUs = micros() - currentTimeBeforeTaskCallUs; taskTotalExecutionTime += taskExecutionTimeUs; + selectedTask->movingSumExecutionTime10thUs += (taskExecutionTimeUs * 10) - selectedTask->movingSumExecutionTime10thUs / TASK_STATS_MOVING_SUM_COUNT; if (!ignoreCurrentTaskExecRate) { // Record task execution rate and max execution time selectedTask->taskLatestDeltaTimeUs = cmpTimeUs(currentTimeUs, selectedTask->lastStatsAtUs); diff --git a/src/main/scheduler/scheduler.h b/src/main/scheduler/scheduler.h index be87aac36c..a33cfd72eb 100644 --- a/src/main/scheduler/scheduler.h +++ b/src/main/scheduler/scheduler.h @@ -85,7 +85,7 @@ typedef struct { timeDelta_t latestDeltaTimeUs; timeUs_t maxExecutionTimeUs; timeUs_t totalExecutionTimeUs; - timeUs_t averageExecutionTimeUs; + timeUs_t averageExecutionTime10thUs; timeUs_t averageDeltaTime10thUs; float movingAverageCycleTimeUs; #if defined(USE_LATE_TASK_STATISTICS) @@ -212,6 +212,7 @@ typedef struct { float movingAverageCycleTimeUs; timeUs_t anticipatedExecutionTime; // Fixed point expectation of next execution time timeUs_t movingSumDeltaTime10thUs; // moving sum over 64 samples + timeUs_t movingSumExecutionTime10thUs; timeUs_t maxExecutionTimeUs; timeUs_t totalExecutionTimeUs; // total time consumed by task since boot timeUs_t lastStatsAtUs; // time of last stats gathering for rate calculation