| 5497 | #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) |
| 5498 | |
| 5499 | void vTaskGetRunTimeStats( char * pcWriteBuffer ) |
| 5500 | { |
| 5501 | TaskStatus_t * pxTaskStatusArray; |
| 5502 | UBaseType_t uxArraySize, x; |
| 5503 | uint32_t ulTotalTime, ulStatsAsPercentage; |
| 5504 | |
| 5505 | #if ( configUSE_TRACE_FACILITY != 1 ) |
| 5506 | { |
| 5507 | #error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats(). |
| 5508 | } |
| 5509 | #endif |
| 5510 | |
| 5511 | /* |
| 5512 | * PLEASE NOTE: |
| 5513 | * |
| 5514 | * This function is provided for convenience only, and is used by many |
| 5515 | * of the demo applications. Do not consider it to be part of the |
| 5516 | * scheduler. |
| 5517 | * |
| 5518 | * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part |
| 5519 | * of the uxTaskGetSystemState() output into a human readable table that |
| 5520 | * displays the amount of time each task has spent in the Running state |
| 5521 | * in both absolute and percentage terms. |
| 5522 | * |
| 5523 | * vTaskGetRunTimeStats() has a dependency on the sprintf() C library |
| 5524 | * function that might bloat the code size, use a lot of stack, and |
| 5525 | * provide different results on different platforms. An alternative, |
| 5526 | * tiny, third party, and limited functionality implementation of |
| 5527 | * sprintf() is provided in many of the FreeRTOS/Demo sub-directories in |
| 5528 | * a file called printf-stdarg.c (note printf-stdarg.c does not provide |
| 5529 | * a full snprintf() implementation!). |
| 5530 | * |
| 5531 | * It is recommended that production systems call uxTaskGetSystemState() |
| 5532 | * directly to get access to raw stats data, rather than indirectly |
| 5533 | * through a call to vTaskGetRunTimeStats(). |
| 5534 | */ |
| 5535 | |
| 5536 | /* Make sure the write buffer does not contain a string. */ |
| 5537 | *pcWriteBuffer = ( char ) 0x00; |
| 5538 | |
| 5539 | /* Take a snapshot of the number of tasks in case it changes while this |
| 5540 | * function is executing. */ |
| 5541 | uxArraySize = uxCurrentNumberOfTasks; |
| 5542 | |
| 5543 | /* Allocate an array index for each task. NOTE! If |
| 5544 | * configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will |
| 5545 | * equate to NULL. */ |
| 5546 | pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); /*lint !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack and this allocation allocates a struct that has the alignment requirements of a pointer. */ |
| 5547 | |
| 5548 | if( pxTaskStatusArray != NULL ) |
| 5549 | { |
| 5550 | /* Generate the (binary) data. */ |
| 5551 | uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime ); |
| 5552 | |
| 5553 | /* For percentage calculations. */ |
| 5554 | ulTotalTime /= 100UL; |
| 5555 | |
| 5556 | /* Avoid divide by zero errors. */ |
no test coverage detected