FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [December 2011 Threads] Measuring CPU usage?Posted by keith soldavin on December 6, 2011 I have an application I am currently developing that requires me to report the CPU usage of the system periodically. I have my code compiled (FreeRTOS 7.0.1, ARM7, IAR 6.2) with the configGENERATE_RUN_TIME_STATS flag set and I can display the stats off all tasks on my debug screen. What I am looking for is not the stats of each individual task but of the overall system. My thought was that if I can get the stats for the Idle task I can subtract the number from 100 and get the total CPU usage. My problem is that I do not know how, or if it is even possible, to get the usage stats of an individual task. One option would be to get the stats for all the tasks and parse out the idle task information but that would be a waste of resources which I don't have.
The one thing I tried, that didn't seem to work well, is to set up idle and tick hook functions that incremented a uint32 variable every time they are entered. I used these values to try to calculate the percentage of time in idle. Unfortunately the values I calculated did not correspond to the RTOS task stats.
Does anyone have any suggestions? Thanks Keith
RE: Measuring CPU usage?Posted by Dave on December 6, 2011 You can use the traceTASK_SWICHED_IN macro.
In the macro, if pxCurrentTCB equals the handle of the idle task, then you know the idle task has just been switched in and you can start a high frequency timer (or note the time of a free running high frequency timer). If the idle task was running, and pxCurrentTCB is no longer the idle task, you know the idle task has just been switched out and you can stop the high frequency timer and note the elapsed time (or again note the time of a free running high frequency timer).
If you use FreeRTOS 7.0.2 and define INCLUDE_xTaskGetIdleTaskHandle to 1 in FreeRTOSConfig.h, then you can use xTaskGetIdleTaskHandle() after the scheduler is started to get the idle task handle.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|