-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Measuring CPU load #81
Comments
Hi. |
Hi, as the scope of my program on the ESP32 grows I would like to know how much headroom I still have. A system monitor task is currently able to periodically report free RAM and heap fragmentation, but I currently have no idea how fast I can clock other tasks and what difference a more frequent execution of those tasks will have on the CPU load. Since the loop() function is always being called, using the system CPU load reporting will be of little use as TaskScheduler is not using the system idle thread, as far as I know (for the ESP32). |
Just as a disclaimer. I do not use this scheduler, but am using something I wrote myself. (as I didn't know about this one...) What I do in my implementation is checking if there is something to be done and if not, I do log the current time stamp. (also keep track if that timestamp is 0 before setting it) But if you have some priority tasks possible, then you could also schedule a lowest priority task with its only purpose to keep track of how long it was running. (and maybe calling |
I simple method will cost you one output pin. The idle loop sets the pin
low as the first thing it does then high on exit. Then you look at the
pulse width (or average voltage) of the pin with a logic analyzer or even
an AC voltmeter and you can see CPU usage in real-time.
This is very helpful when you are deciding on changes to the software and
want to know if you have enough "spare" CPU time to support your proposed
new feature. But it does cost a pin and adds a few instructions to the
idle loop.
It is a good way to answer a question like "can I double the frequency of
this control loop?" Just look and see if you are only using 10% of the
CPU then "Yes" but if you are already at 60% then certainly not.
…On Sun, Jan 5, 2020 at 12:00 PM Anatoli Arkhipenko ***@***.***> wrote:
Hi.
Currently, there is no such method as I have never needed one, nor been
asked to implement one.
Also, since this needs to happen inside the scheduling loop I am trying to
avoid putting *any* non-essential processing inside there.
Could you please elaborate on the use case? Why is it necessary?
Cheers,
Anatoli
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#81?email_source=notifications&email_token=ABQKNRQGTR3ZIWUQEFLHDRDQ4I34LA5CNFSM4KC3SEWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEID6HGA#issuecomment-570942360>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQKNRQFTZUOZLYDFOGGQSDQ4I34LANCNFSM4KC3SEWA>
.
--
Chris Albertson
Redondo Beach, California
|
All good comments, guys, thank you. However, since we are talking about ESP32, the situation is a little complicated: Additionally on ESP32 loop() and therefore TS tasks run on CORE 1 (Application) inside the FreeRTOS idle task. Since tasks from CORE1 could potentially call system routines from CORE0 and then receive callbacks (especially in the WiFi methods), there is a way to create race condition on the callbacks leading to unpredictable results and crashes. I have (successfully) experimented combining FreeRTOS and TS in one program (multiple TSs actially, since you can have a separate scheduler per RTOS task), but this proved to be not trivial and caused a lot of tripping of RTOS watchdog timers. I have some ideas how we can measure what you are trying to measure - let me noodle on those. Meanwhile, there is something you can already do: You can use these two methods to assess whether you still have CPU capacity: If you start getting consistent and growing negative values on getOverrun, your CPU is not handling the load. |
OK. I pushed version 3.1.0 into the testing branch. Below is example 24 output for ESP32:
I think 'CPU Callback processing' is a bit of a misnomer. It should be "CPU callback processing and other stuff the ESP OS does outlside of loop() like running WiFi stack, etc.) |
@moritz89 : would be helpful if you could test and comment. |
First off, the added functionality is exactly what I am looking for! I agree that the "CPU Callback processing" would rather be "Time not spent in TaskScheduler" which effectively translates to "Doing effictive work". While testing the changes I noticed two issues:
My results while running the example code showed:
|
Could you please send me the files? I did test example 24 on ESP32 and it did not have any issues
Well... Idle sleep supposed to put the chip to sleep, which ESPs just does not do... just delays, so no power savings actually take place. Thanks for testing! |
Also: |
@arkhipenko I reordered my includes and how the defines are set and it works now. Thanks again for the quick turn-around for the CPU load functionality! |
Enjoy! And thank you for the suggestion. I think this is useful and I could have used it in my projects before for sure... |
Hi, I wanted to know if there is a method to measure the CPU load? i.e., time spent in the IDLE mode
The text was updated successfully, but these errors were encountered: