0
0
FreeRTOSprogramming~20 mins

vTaskGetRunTimeStats() for CPU usage in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FreeRTOS CPU Usage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of vTaskGetRunTimeStats() after two tasks run?

Consider two FreeRTOS tasks running with different CPU times. The vTaskGetRunTimeStats() function fills a buffer with CPU usage stats. What will the output string contain?

FreeRTOS
char buffer[100];
vTaskGetRunTimeStats(buffer);
printf("%s", buffer);
ATask1 100%\r\nTask2 0%\r\n
BTask1 30%\r\nTask2 70%\r\n
CTask1 70%\r\nTask2 30%\r\n
DTask1 50%\r\nTask2 50%\r\n
Attempts:
2 left
💡 Hint

Remember CPU usage is proportional to the run time of each task relative to total run time.

🧠 Conceptual
intermediate
1:30remaining
What does vTaskGetRunTimeStats() measure?

Which of the following best describes what vTaskGetRunTimeStats() reports?

AThe total time each task has spent running since system start, as a percentage of total CPU time.
BThe current stack usage of each task in bytes.
CThe number of times each task has been switched in and out by the scheduler.
DThe priority level of each task.
Attempts:
2 left
💡 Hint

Think about what CPU usage means in a multitasking system.

🔧 Debug
advanced
2:00remaining
Why does vTaskGetRunTimeStats() show zero CPU usage for all tasks?

You call vTaskGetRunTimeStats() but the output shows zero CPU usage for every task. What is the most likely cause?

AThe buffer passed to <code>vTaskGetRunTimeStats()</code> is too small.
BThe configGENERATE_RUN_TIME_STATS macro is not enabled or the timer for run time stats is not configured.
CThe tasks have not been created yet.
DThe scheduler is not running.
Attempts:
2 left
💡 Hint

Check your FreeRTOS configuration related to run time stats.

📝 Syntax
advanced
1:30remaining
Which code snippet correctly uses vTaskGetRunTimeStats()?

Choose the code snippet that correctly calls vTaskGetRunTimeStats() and prints the CPU usage stats.

Achar stats[200];\nvTaskGetRunTimeStats(&stats);\nprintf("CPU Usage:\n%s", stats);
Bchar stats[200];\nvTaskGetRunTimeStats();\nprintf("CPU Usage:\n%s", stats);
Cchar *stats;\nvTaskGetRunTimeStats(stats);\nprintf("CPU Usage:\n%s", stats);
Dchar stats[200];\nvTaskGetRunTimeStats(stats);\nprintf("CPU Usage:\n%s", stats);
Attempts:
2 left
💡 Hint

Check the function parameter type and how the buffer is passed.

🚀 Application
expert
3:00remaining
How to use vTaskGetRunTimeStats() to monitor CPU usage in a running system?

You want to monitor CPU usage of tasks periodically in a FreeRTOS system. Which approach correctly uses vTaskGetRunTimeStats() to achieve this?

ACreate a high priority monitoring task that calls <code>vTaskGetRunTimeStats()</code> every second, stores the output, and prints it via UART.
BCall <code>vTaskGetRunTimeStats()</code> once at system start and store the output for later use.
CModify each task to call <code>vTaskGetRunTimeStats()</code> inside their loop to get their own CPU usage.
DUse <code>vTaskGetRunTimeStats()</code> inside an interrupt service routine to get real-time CPU usage.
Attempts:
2 left
💡 Hint

Think about how to safely and periodically collect stats without blocking or causing errors.