CPU Usage monitor. Works great

I thought i’d share this excellent snippet from Inquisitor over on the Netduino forums. I have been using this for a couple of months now to track my CPU load and it works perfectly.


Clever way to use ticks… Thanks

Unfortunately, does not work correctly with CDC (https://www.ghielectronics.com/community/codeshare/entry/517), you will always get 100% CPU load even if nothing else is running.
This line ruins all the fun:

Not sure how the project works you have linked to.
But if it has a loop without any sleep or wait for external event, then of course, the CPU load is 100% then.

It is in a separate thread, but that line does not return until you send some data.

I have tried that CPUUsage class along with CDC class and my GUI class which is CPU power hungry. GUI works perfectly well, without any lag, I wouldn’t expect that when CPU is 100% loaded. So I have removed GUI class and tried it again it was still showing 100% CPU load.

Does the …

PowerState.WaitForIdleCPU(1, int.MaxValue);

…line return?

It seems that not.

I have noticed that while this monitor works it does seem to prevent the MCU dropping into its propped low power idle state so it will have an impact on current draw.

I usually activate it only for Debugging/profiling sessions.
Then I remove it again

1 Like