I managed to make this work with the following steps:
[*]run
git log in arduino-esp32 to find the latest tagged IDF (3.1 in my case)
[*]checkout that tag in
esp-idf
[*]copy
sdkconfig from arduino-esp32/tools/sdk/sdkconfig to esp-idf/examples/get-started/blink/sdkconfig
[*]run
make menuconfig in esp-idf/examples/get-started/blink, turn on the options mentioned above
[*]make
[*]copy
build/freertos/libfreertos.a to
Arduino/hardware/expressif/esp32/tools/sdk/lib/
[*]copy
build/esp32/libesp32.a to
Arduino/hardware/expressif/esp32/tools/sdk/lib/
After doing these steps, I was able to compile this example:
https://www.freertos.org/uxTaskGetSystemState.html
with the following changes
[*]use
uxTaskGetNumberOfTasks() instead of
uxCurrentNumberOfTasks()
[*]hack the task status data out of memory. I've still messed something up because sizeof(TaskStatus_t) evaluates to 36, but the actual struct size in memory was 40. I offset the pointers manually. Please do pardon my language.
Code: Untitled.cpp Select all
void print_shit(void)
{
char *str = (char *)malloc(sizeof(char) * 2000);
memset(str, 0, 2000);
char *pcWriteBuffer = str;
TaskStatus_t *pxTaskStatusArray;
volatile UBaseType_t uxArraySize, x;
unsigned long ulStatsAsPercentage;
uint32_t ulTotalRunTime;
/* 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 = uxTaskGetNumberOfTasks();
/* Allocate a TaskStatus_t structure for each task. An array could be
allocated statically at compile time. */
Serial.printf("sizeof TaskStatus_t: %d\n", sizeof(TaskStatus_t));
pxTaskStatusArray = (TaskStatus_t*)pvPortMalloc( uxArraySize * sizeof(TaskStatus_t));
memset(pxTaskStatusArray, 0, uxArraySize * sizeof(TaskStatus_t));
if( pxTaskStatusArray != NULL )
{
/* Generate raw status information about each task. */
Serial.printf("Array size before: %d\n", uxArraySize);
uxArraySize = uxTaskGetSystemState( pxTaskStatusArray,
uxArraySize,
&ulTotalRunTime );
Serial.printf("Array size after: %d\n", uxArraySize);
Serial.printf("Total runtime: %d\n", ulTotalRunTime);
/* For percentage calculations. */
ulTotalRunTime /= 100UL;
/* Avoid divide by zero errors. */
if( ulTotalRunTime > 0 )
{
/* For each populated position in the pxTaskStatusArray array,
format the raw data as human readable ASCII data. */
Serial.printf(" name runtime pct core prio\n");
for( int x = 0; x < uxArraySize; x++ )
{
TaskStatus_t *fuckit;
void *tmp = &pxTaskStatusArray[x];
void *hmm = tmp + (4 * x);
fuckit = (TaskStatus_t*)hmm;
// Serial.printf("Name: %.5s, ulRunTimeCounter: %d\n", fuckit->pcTaskName , fuckit->ulRunTimeCounter);
/* What percentage of the total run time has the task used?
This will always be rounded down to the nearest integer.
ulTotalRunTimeDiv100 has already been divided by 100. */
ulStatsAsPercentage =
fuckit->ulRunTimeCounter / ulTotalRunTime;
if( ulStatsAsPercentage > 0UL )
{
sprintf( pcWriteBuffer, "%30s %10lu %10lu%% %5d %5d\n",
fuckit->pcTaskName,
fuckit->ulRunTimeCounter,
ulStatsAsPercentage,
*((int *)(&fuckit->usStackHighWaterMark)+1),
fuckit->uxBasePriority);
}
else
{
/* If the percentage is zero here then the task has
consumed less than 1% of the total run time. */
sprintf( pcWriteBuffer, "%30s %10lu %10s %5d %5d\n",
fuckit->pcTaskName,
fuckit->ulRunTimeCounter,
"<1%",
*((uint32_t *)(&fuckit->usStackHighWaterMark)+1),
fuckit->uxBasePriority);
}
pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
// Serial.printf("len: %d, idx: %d\n", pcWriteBuffer - str, x);
}
Serial.print(str);
}
/* The array is no longer needed, free the memory it consumes. */
// vPortFree( pxTaskStatusArray );
// free(str);
}
}
Code: Untitled.txt Select all
Name runtime pct core prio
loopTask 8361337 89% 1 1
IDLE0 9270465 99% 0 0
IDLE1 14782 <1% 1 0
CAN_RX_25 218240 2% 1 24
100Hz_CAN_send_ 144393 1% 1 3
tiT 11428 <1% 0 18
10Hz_CAN_send_t 19815 <1% 1 1
LED blinker 2382 <1% 0 0
CAN_WD_BI 4471 <1% 1 10
1Hz_CAN_send_ta 75161 <1% 1 1
CAN_RX_24 195768 2% 1 24
Tmr Svc 36 <1% 0 1
ipc0 3502 <1% 0 24
network_event 18 <1% 1 19
eventTask 23 <1% 0 20
CAN_RX 27 <1% 2147483647 15
CAN_LORX 20 <1% 1 19
mdns 141 <1% 0 1
esptimer 4469 <1% 0 22
ACAN2517Handler 60268 <1% 2147483647 24
ACAN2517Handler 215147 2% 2147483647 24
ipc1 22592 <1% 1 24
This forum is fine, but BBcode is an awful impediment. Good Night.