Page 1 of 1

How to get CPU load approximate value on Micropython ?

Posted: Mon Mar 18, 2019 3:08 pm
by water
How to get CPU load approximate value on Micropython ?

Re: How to get CPU load approximate value on Micropython ?

Posted: Mon Mar 18, 2019 3:22 pm
by fstengel
Excluding the UNIX port, I am not quite sure that one can get such a figure. In many cases micropython is running on bare metal without any os, so the "load" would be 100%...

Re: How to get CPU load approximate value on Micropython ?

Posted: Mon Mar 18, 2019 4:52 pm
by ThomasChr
I tried a short explaination here: viewtopic.php?f=2&t=5922

Re: How to get CPU load approximate value on Micropython ?

Posted: Wed Mar 20, 2019 4:39 pm
by oclyke
ThomasChr and fstengel are correct in saying that on the vanilla microcontroller ports the load is 100% because MicroPython is always running something. For example it might be waiting for input at the REPL prompt or (after receiving input) taking the necessary steps to lex, compile, and then run the bytecode for the requested actions.

However hypothetically if you had an appropriate system (such as running MicroPython on top of a scheduler like FreeRTOS) and you called appropriate "blocking" code (e.g. maybe you would make it so that utime.sleep() delays using vTaskDelay()) then other 'tasks' might be able to execute when MicroPython is busy. In that case you could use any of a number of methods to determine the duty cycle that MicroPython is using.