Skip to content

Commit 06b1341

Browse files
committed
Add ulTaskGetRunTimeCounter and ulTaskGetRunTimePercent
Allow ulTaskGetIdleRunTimeCounter and ulTaskGetIdleRunTimePercent to be used whenever configGENERATE_RUN_TIME_STATS is enabled, as this is the only requirement for these functions to work.
1 parent bb6071e commit 06b1341

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

.github/lexicon.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,8 @@ ulstoppedtimercompensation
23212321
ultablebase
23222322
ultaskgetidleruntimecounter
23232323
ultaskgetidleruntimepercent
2324+
ultaskgetruntimecounter
2325+
ultaskgetruntimepercent
23242326
ultaskhasfpucontext
23252327
ultasknotifystateclear
23262328
ultasknotifytake

include/task.h

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,20 +1934,55 @@ void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unquali
19341934
*/
19351935
void vTaskGetRunTimeStats( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
19361936

1937+
/**
1938+
* task. h
1939+
* @code{c}
1940+
* configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimeCounter( const TaskHandle_t xTask );
1941+
* configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimePercent( const TaskHandle_t xTask );
1942+
* @endcode
1943+
*
1944+
* configGENERATE_RUN_TIME_STATS must be defined as 1 for these functions to be
1945+
* available. The application must also then provide definitions for
1946+
* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
1947+
* portGET_RUN_TIME_COUNTER_VALUE() to configure a peripheral timer/counter and
1948+
* return the timers current count value respectively. The counter should be
1949+
* at least 10 times the frequency of the tick count.
1950+
*
1951+
* Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1952+
* accumulated execution time being stored for each task. The resolution
1953+
* of the accumulated time value depends on the frequency of the timer
1954+
* configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1955+
* While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
1956+
* execution time of each task into a buffer, ulTaskGetRunTimeCounter()
1957+
* returns the total execution time of just one task and
1958+
* ulTaskGetRunTimePercent() returns the percentage of the CPU time used by
1959+
* just one task.
1960+
*
1961+
* @return The total run time of the given task or the percentage of the total
1962+
* run time consumed by the given task. This is the amount of time the task
1963+
* has actually been executing. The unit of time is dependent on the frequency
1964+
* configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
1965+
* portGET_RUN_TIME_COUNTER_VALUE() macros.
1966+
*
1967+
* \defgroup ulTaskGetRunTimeCounter ulTaskGetRunTimeCounter
1968+
* \ingroup TaskUtils
1969+
*/
1970+
configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimeCounter( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1971+
configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimePercent( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1972+
19371973
/**
19381974
* task. h
19391975
* @code{c}
19401976
* configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void );
19411977
* configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void );
19421978
* @endcode
19431979
*
1944-
* configGENERATE_RUN_TIME_STATS, configUSE_STATS_FORMATTING_FUNCTIONS and
1945-
* INCLUDE_xTaskGetIdleTaskHandle must all be defined as 1 for these functions
1946-
* to be available. The application must also then provide definitions for
1947-
* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1948-
* to configure a peripheral timer/counter and return the timers current count
1949-
* value respectively. The counter should be at least 10 times the frequency of
1950-
* the tick count.
1980+
* configGENERATE_RUN_TIME_STATS must be defined as 1 for these functions to be
1981+
* available. The application must also then provide definitions for
1982+
* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
1983+
* portGET_RUN_TIME_COUNTER_VALUE() to configure a peripheral timer/counter and
1984+
* return the timers current count value respectively. The counter should be
1985+
* at least 10 times the frequency of the tick count.
19511986
*
19521987
* Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
19531988
* accumulated execution time being stored for each task. The resolution

tasks.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5251,19 +5251,19 @@ TickType_t uxTaskResetEventItemValue( void )
52515251
#endif /* configUSE_TASK_NOTIFICATIONS */
52525252
/*-----------------------------------------------------------*/
52535253

5254-
#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
5254+
#if ( configGENERATE_RUN_TIME_STATS == 1 )
52555255

5256-
configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void )
5256+
configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimeCounter( const TaskHandle_t xTask )
52575257
{
5258-
return xIdleTaskHandle->ulRunTimeCounter;
5258+
return xTask->ulRunTimeCounter;
52595259
}
52605260

52615261
#endif
52625262
/*-----------------------------------------------------------*/
52635263

5264-
#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
5264+
#if ( configGENERATE_RUN_TIME_STATS == 1 )
52655265

5266-
configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void )
5266+
configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimePercent( const TaskHandle_t xTask )
52675267
{
52685268
configRUN_TIME_COUNTER_TYPE ulTotalTime, ulReturn;
52695269

@@ -5275,7 +5275,7 @@ TickType_t uxTaskResetEventItemValue( void )
52755275
/* Avoid divide by zero errors. */
52765276
if( ulTotalTime > ( configRUN_TIME_COUNTER_TYPE ) 0 )
52775277
{
5278-
ulReturn = xIdleTaskHandle->ulRunTimeCounter / ulTotalTime;
5278+
ulReturn = xTask->ulRunTimeCounter / ulTotalTime;
52795279
}
52805280
else
52815281
{
@@ -5285,7 +5285,27 @@ TickType_t uxTaskResetEventItemValue( void )
52855285
return ulReturn;
52865286
}
52875287

5288-
#endif /* if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) ) */
5288+
#endif /* if ( configGENERATE_RUN_TIME_STATS == 1 ) */
5289+
/*-----------------------------------------------------------*/
5290+
5291+
#if ( configGENERATE_RUN_TIME_STATS == 1 )
5292+
5293+
configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void )
5294+
{
5295+
return ulTaskGetRunTimeCounter( xIdleTaskHandle );
5296+
}
5297+
5298+
#endif
5299+
/*-----------------------------------------------------------*/
5300+
5301+
#if ( configGENERATE_RUN_TIME_STATS == 1 )
5302+
5303+
configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void )
5304+
{
5305+
return ulTaskGetRunTimePercent( xIdleTaskHandle );
5306+
}
5307+
5308+
#endif
52895309
/*-----------------------------------------------------------*/
52905310

52915311
static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,

0 commit comments

Comments
 (0)