vTaskGetCpuLoadStats

Hi,

There is cpu load API “vTaskGetCpuLoadStats” in kernel v9.0.0. But I can’t find it in kernel v10.3.1.

Has it been deleted now?

void vTaskGetCpuLoadStats( char *pcWriteBuffer )
	{
	TaskStatus_t *pxTaskStatusArray;
	volatile UBaseType_t uxArraySize, x;
	uint64_t ulTotalTime;

		#if( configUSE_TRACE_FACILITY != 1 )
		{
			#error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats().
		}
		#endif

		/*
		 * PLEASE NOTE:
		 *
		 * This function is provided for convenience only, and is used by many
		 * of the demo applications.  Do not consider it to be part of the
		 * scheduler.
		 *
		 * vTaskGetCpuLoadStats() calls uxTaskGetSystemState(), then formats part
		 * of the uxTaskGetSystemState() output into a human readable table that
		 * displays the amount of time(0.1s/1s/10s) each task has spent in the 
		 * Running state in percentage term.
		 *
		 * vTaskGetCpuLoadStats() has a dependency on the sprintf() C library
		 * function that might bloat the code size, use a lot of stack, and
		 * provide different results on different platforms.  An alternative,
		 * tiny, third party, and limited functionality implementation of
		 * sprintf() is provided in many of the FreeRTOS/Demo sub-directories in
		 * a file called printf-stdarg.c (note printf-stdarg.c does not provide
		 * a full snprintf() implementation!).
		 *
		 * It is recommended that production systems call uxTaskGetSystemState()
		 * directly to get access to raw stats data, rather than indirectly
		 * through a call to vTaskGetRunTimeStats().
		 */

		/* Make sure the write buffer does not contain a string. */
		*pcWriteBuffer = 0x00;

		/* Take a snapshot of the number of tasks in case it changes while this
		function is executing. */
		uxArraySize = uxCurrentNumberOfTasks;

		/* Allocate an array index for each task.  NOTE!  If
		configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will
		equate to NULL. */
		pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );

		if( pxTaskStatusArray != NULL )
		{
			/* Generate the (binary) data. */
			uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime );

				/* Create a human readable table from the binary data. */
				for( x = 0; x < uxArraySize; x++ )
			{
				/* Write the task name to the string, padding with
				spaces so it can be printed in tabular form more
				easily. */
				pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );

				#ifdef portLU_PRINTF_SPECIFIER_REQUIRED
				{
					sprintf( pcWriteBuffer, "\t%lu%%\t%lu%%\t%lu%%\r\n", 
									pxTaskStatusArray[ x ].xCpuLoad.ulAveragePoint1s,
									((pxTaskStatusArray[ x ].xCpuLoad.ulAverage1s + 5) / 10),
									(( pxTaskStatusArray[ x ].xCpuLoad.ulAverage10s +50) /100));
				}
				#else
				{
					/* sizeof( int ) == sizeof( long ) so a smaller
					printf() library can be used. */
					sprintf( pcWriteBuffer, "\t%2u%%\t%2u%%\t%2u%%\r\n", 
								(unsigned int) pxTaskStatusArray[ x ].xCpuLoad.ulAveragePoint1s,
								(unsigned int) ((pxTaskStatusArray[ x ].xCpuLoad.ulAverage1s + 5) / 10),
								(unsigned int) ((pxTaskStatusArray[ x ].xCpuLoad.ulAverage10s +50) /100));
				}
				#endif

				pcWriteBuffer += strlen( pcWriteBuffer );
			}

			/* Free the array again.  NOTE!  If configSUPPORT_DYNAMIC_ALLOCATION
			is 0 then vPortFree() will be #defined to nothing. */
			vPortFree( pxTaskStatusArray );
		}
		else
		{
			mtCOVERAGE_TES**strong text**T_MARKER();
		}
	}

#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */

I guess it has been replaced by vTaskGetRunTimeStats.

no.
vTaskGetRunTimeStats always exists.

The official code never had a function called vTaskGetCpuLoadStats().
Here is version 9 of tasks.C: FreeRTOS-Kernel/tasks.c at V9.0.0 · FreeRTOS/FreeRTOS-Kernel · GitHub (if it were an official function “Cpu” would be in upper case).