Author Topic: RaspberryPi Debugging CPU Usage  (Read 3105 times)

seth350

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
RaspberryPi Debugging CPU Usage
« on: June 20, 2018, 10:08:32 AM »
Good morning,

I have been battling high cpu usage for some time now. It seems the app starts out small and grows over time until it locks up. The app is running in Mono.

In the RaspberryPi, you can open a new terminal window and enter the command type in:
Code: [Select]
top
This displays the processes currently running and the system resources. A little trick while in this command is to press Shift + H, this will display all of the threads currently running and their resources.

I wanted to share some screenshots of what my app is doing to try to figure out if its something in MY code, Mono, or if it is something in AdvancedHMI causing this.

Archie,
Are the "Threadpool work" threads apart of AHMI?

Mono Version: 5.2.0.215
AdvancedHMI Version: 3.99x


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: RaspberryPi Debugging CPU Usage
« Reply #1 on: June 20, 2018, 02:57:27 PM »
Most of the threads used by AdvancedHMI are named, such as CLXSubscription, CIPSendQueProcessor, EIPSendQueProcessor

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #2 on: June 20, 2018, 04:54:35 PM »
seth350, have you checked this application, called cpulimit, which might help with high cpu usage in linux:

https://www.maketecheasier.com/limit-cpu-usage-of-any-process-in-linux/

seth350

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #3 on: June 21, 2018, 11:01:41 PM »
I thought so Archie.

Godra,
I had not seen that program, thanks for sharing. Still, even if I limit the cpu usage, wouldn’t the application still suffer? The app runs for about a week or two then stops responding or gets really slow. Wouldn’t setting the cpu limit lower just make the app lock up sooner?

I am by means doing any fancy threading in the app. I am using a sound player that plays a small wav file. Depending on how you call it, it will play the file in a separate thread. I am calling it so that it does just that.

The wav file plays when a user has completed scanning all of their parts. A different sound plays if the wrong part is scanned, and another different sound plays on each successful scan.

The sound player is not an AdvancedHMI component, and I can’t remember exactly which one I used.

I would assume that it would handle its threads appropriately though? I wouldn’t need to dispose of the player once it’s finished?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #4 on: June 22, 2018, 12:24:14 AM »
You are the one troubleshooting this issue so whatever you try might just provide more info for you.

It could be your player that chokes everything or it could be something else.

The issue is so odd that could have you troubleshoot it for weeks or months.

Mikefly95

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #5 on: June 22, 2018, 06:36:39 AM »
Are you cooling it? Pi's and other SBC an get super hot and then shut down.

seth350

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #6 on: June 22, 2018, 10:52:47 AM »
Are you cooling it? Pi's and other SBC an get super hot and then shut down.

No cooling. Temp goes up to 84C and sits. I think it does some throttling based on temp.
I know many people are using RPi with Mono to run AHMI and I can't imagine them all having the same issue as I am. Otherwise there would be more hits on the net.

I wish I could get more debug info about what is actually occurring inside each "Threadpool work" thread.

Mikefly95

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #7 on: June 22, 2018, 12:03:24 PM »
84 degrees C?? 183 F??

seth350

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #8 on: June 22, 2018, 11:38:54 PM »
84 degrees C?? 183 F??

Correct.

The next set of RPis I will order will have heatsinks and a fan.

If I didn’t have this usage problem, the temp sits at 50C.

EvenChu

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #9 on: July 20, 2018, 12:03:43 PM »
Hi...i am a new user here. As per my knowledge the other way of debugging is to look through your code. Often explaining it to someone else will help you see where a problem lies, they don't even need to understand what you are saying as it the act of explaining that helps clarifies things in your mind.Break the code up into small sections and step through it in your head, think about how the data will start out and finish for that section, and in what conditions it might fail, then move onto the next section.

prototype pcb assembly china
« Last Edit: August 21, 2018, 11:40:49 AM by EvenChu »

seth350

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: RaspberryPi Debugging CPU Usage
« Reply #10 on: July 21, 2018, 11:45:35 PM »
Thanks EvenChu

I have started looking through the code as I get time. The one thing that I have found is this:

I have a status panel that displays messages and images on the main form.
I set the messages and images by using an event arguments class “StatusEventArgs”.

So if an event is fired that needs to set the status panel message and image, I call a SetStatus method like so:
SetStatus(New StatusArgs(“New Message”, imgNewImage, Color.Green, Color.White)

The colors are setting background color and text color.

I set new messages to this status panel many times. Each time making a call just like above.

Not sure if this would cause my symptoms but it’s one thing that has stood out.