Page 1 of 1

Approximate reasonably CPU load per core?

Posted: Thu Nov 21, 2019 11:08 am
by mharizanov
Folks,
Is there an "official" way to read the approximate CPU load e.g. how much time is spent in IDLE vs other tasks? I'd ideally need this per core, tips on how to achieve that would be appreciated.
Thanks

Re: Approximate reasonably CPU load per core?

Posted: Thu Nov 21, 2019 1:42 pm
by urbanze
mharizanov wrote:
Thu Nov 21, 2019 11:08 am
Folks,
Is there an "official" way to read the approximate CPU load e.g. how much time is spent in IDLE vs other tasks? I'd ideally need this per core, tips on how to achieve that would be appreciated.
Thanks
With RTOS stats, you can see task usage of all tasks of both cpus (including IDLEs)

https://www.freertos.org/rtos-run-time-stats.html

Re: Approximate reasonably CPU load per core?

Posted: Thu Nov 21, 2019 1:55 pm
by PeterR
Note: The above link gives you a total count. You may also wish to see load over 0.25 seconds. You would have to write that code yourself but its fairly easy to populate an array with task name and last run count from which to perform the delta.
I found that the returned task list would change the order of tasks so I am afraid you will have to hunt your entry if you want to see deltas.

Re: Approximate reasonably CPU load per core?

Posted: Thu Nov 21, 2019 2:22 pm
by mharizanov
Thanks for the pointers. Looks like with some fiddling, it will work. I'll update the thread.

Re: Approximate reasonably CPU load per core?

Posted: Thu Nov 21, 2019 6:02 pm
by mharizanov
Got it working. Had to enable "Component config > FreeRTOS > Enable FreeRTOS to collect run time stats " in menuconfig (IDF 3.3)

Gives me output like this:

Code: Select all

main					886790		<1%
IDLE1				146272698	90%
IDLE0				151160911	93%
buzzer_task			153997		<1%
tiT					439292		<1%
mqtt_task				2849535		1%
lvgl_task				14420182		8%
Tmr Svc				76			<1%
rfm69				73008		<1%
ipc0					2973947		1%
esp_timer				70375		<1%
wifi					2703508		1%
ipc1					251647		<1%
eventTask				11000		<1%
gpio_task				807			<1%


So CPU load per core is 100%-IDLE[0,1]

Thanks!

Re: Approximate reasonably CPU load per core?

Posted: Fri Nov 22, 2019 12:13 pm
by mharizanov
PeterR wrote:
Thu Nov 21, 2019 1:55 pm
Note: The above link gives you a total count. You may also wish to see load over 0.25 seconds. You would have to write that code yourself but its fairly easy to populate an array with task name and last run count from which to perform the delta.
I found that the returned task list would change the order of tasks so I am afraid you will have to hunt your entry if you want to see deltas.
Thanks for this, yes, it would make most sense to have "live" data, not accumulated totals since boot. Since my interest is in CPU load, I only care for the delta in IDLE[0,1] task. This makes the code simpler too.

Re: Approximate reasonably CPU load per core?

Posted: Fri Nov 22, 2019 12:57 pm
by PeterR
Cool.
Yes, it works, well sometimes the numbers do not add up to 100% but its good enough.

I have mine also showing load in last 0.25 seconds which helps with bursty activity. Just cannot share.
You will have to go a little native if you want to name std::thread
If you need wrap the constructor and use esp_pthread_set_cfg().