How to get CPU load approximate value on Micropython ?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
water
Posts: 29
Joined: Sun Sep 24, 2017 9:16 am

How to get CPU load approximate value on Micropython ?

Post by water » Mon Mar 18, 2019 3:08 pm

How to get CPU load approximate value on Micropython ?

fstengel
Posts: 30
Joined: Tue Apr 17, 2018 4:37 pm

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

Post by fstengel » Mon Mar 18, 2019 3:22 pm

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%...

ThomasChr
Posts: 120
Joined: Sat Nov 25, 2017 7:50 am

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

Post by ThomasChr » Mon Mar 18, 2019 4:52 pm

I tried a short explaination here: viewtopic.php?f=2&t=5922

oclyke
Posts: 11
Joined: Tue Mar 19, 2019 4:55 am

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

Post by oclyke » Wed Mar 20, 2019 4:39 pm

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.

Post Reply