能否实现一个监控任务,该任务在每个时间片开始时执行,并计算前一个时间片内的利用率。
如果利用率过高,则应发出警告。如果我们能利用空闲时间,就可以测量利用率。
为了设置此监控任务,需要一次性估算在一个时间片内可以执行多少空闲操作。
如果利用率高于90%,监控任务应在输出端打印警告。
我设计了一个方案,但用Segger SystemView工具检查时显示存在一些差异。有人做过类似的事情吗?
volatile float referencePoint = 1512.493;
volatile uint32_t tickhookcurrent = 0UL;
volatile float utilization_monitor = 0;
void vApplicationIdleHook( void )
{
/* This hook function does nothing but increment a counter. */
tickhookcurrent++;
}
void vApplicationTickHook(){
utilization_monitor = 100 - ((float) tickhookcurrent *100 / referencePoint);
tickhookcurrent = 0;
}
void monitor_task(void *argument){
char *s;
while(1){
sprintf(s, "Utilization %f", utilization_monitor);
print_function(s);
}
}
uint32_t lpt_profiler;
void task1_lowpriority(void *argument)
{
TickType_t timestamp;
while(1){
//lpt_profiler;
timestamp = xTaskGetTickCount() * portTICK_PERIOD_MS;
while((lpt_profiler = ( (xTaskGetTickCount() * portTICK_PERIOD_MS) - timestamp)) < 25*portTICK_PERIOD_MS);
SEGGER_SYSVIEW_PrintfHost("LPT task from task1");
}
vTaskDelete(NULL);
}
|
|