Anyone make sense of vTaskGetRunTimeStats?

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Anyone make sense of vTaskGetRunTimeStats?

Postby fly135 » Fri Oct 05, 2018 7:47 pm

When I initially boot up and read vTaskGetRunTimeStats it seems to produce reasonable numbers for % cpu utilization. For example the two idles tasks each read about 50%, which one would guess is 100% per core. Looking at the code that computes the percentages leads me to believe that it should be printing 100% instead of 50% as the calculation don't appear to take into account the two cores.

But assuming that the percent utilization is supposed to be based on the total of two cores, the values returned after running for a while don't add up. For example....

Code: Select all

------------- TASKS --------------
Uptime = 6019 sec / 6019742 msec
soundTask       2844795936              82
main            16049702                <1
IDLE            1387194975              40
IDLE            3136531981              90
pirTask         13701570                <1
mgrRuleTask     37943962                1
super           1253519         <1
sensor_task     6231089         <1
wd_app          15279           <1
wd_pro          16978           <1
pubnub_task     91240172                2
tiT             20367385                <1
Tmr Svc         36              <1
ipc0            887             <1
eventTask       804             <1
pthread         819             <1
ipc1            158207          <1
esp_timer       5313957         <1
wifi            163263046               4
mic_task        20398940                <1
led_task        8707            <1
nvs_task        6118            <1
Then slightly later...

Code: Select all

------------- TASKS --------------
Uptime = 6727 sec / 6727991 msec
main            17995053                <1
IDLE            3503867369              72
IDLE            2052790476              42
super           1410208         <1
tiT             23092209                <1
mgrRuleTask     43809452                <1
soundTask       3181231775              65
sensor_task     6986521         <1
wd_app          17316           <1
wd_pro          19081           <1
pubnub_task     101745144               2
pirTask         15318772                <1
Tmr Svc         36              <1
eventTask       804             <1
pthread         819             <1
led_task        8707            <1
ipc1            159545          <1
esp_timer       5950142         <1
wifi            183782656               3
mic_task        22800893                <1
nvs_task        6118            <1
ipc0            887             <1
Looking at soundTask... in the first dump 2805/6019 = 47% but prints 82%. in the second dump (about 700 sec later) 3181/6727 = 47% but prints 65%. soundTask is pinned to the APP core so IDLE = 40% + soundTask = 82% = 122%. Then later in the second dump the order of the idle tasks appear to have switched, which I think would be fixed in a single run.

The actual times don't even seem to add up to about the total up time for each core. The pirTask, micTask and soundTask are on the same core (APP_CORE) and make up the bulk of that core + the idle task = 5271 or 6727 sec in the 2nd dump. In the first they add up to 4266 out of 6019.

I pin most tasks to one core or the other. The wifi task is the only task with a lot of usage, but it's my understanding that it's on the PRO core. If it floats then that might explain some variation, but not enough to make the numbers add up.

Has anyone been able to get definitive and consistent info from this data?

John A

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: Anyone make sense of vTaskGetRunTimeStats?

Postby ESP_Dazz » Tue Oct 09, 2018 8:23 am

vTaskGetRunTimeStats() should take into account the total run time of both cores in the following line:

Code: Select all

ulStatsAsPercentage = (pxTaskStatusArray[ x ].ulRunTimeCounter/portNUM_PROCESSORS)/ ulTotalTime;
I think the issue you're seeing is due to the total run time overflowing. When ulTotalTime overflows, the output percentage will be inaccurate.

Could you check menu config to see which clock is used as a the reference clock for run time stats?

Who is online

Users browsing this forum: username and 98 guests