Skip to content
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

Multiple instances under multiple user setup cause ~20% CPU usage #651

Closed
githubyouser opened this issue Nov 20, 2024 · 24 comments
Closed

Comments

@githubyouser
Copy link

My computer seems to be running a lot "hotter" recently, with the fan running almost constantly. I checked Task Manager and realized that Monitorian just seems to be sitting there eating CPU cycles.

image

It jumps up and down, but Monitorian uses between 20-30% of CPU constantly. I've been watching it for several minutes now, and it hasn't slowed down. I finally killed the process, because it's kinda problematic. Interestingly, if I then restart Monitorian it settles down to 0% CPU usage after the initial spike for checking monitors. I suspect that sleeping/resuming is what causes the runaway CPU usage.

I've also been experiencing mouse delays/stutters at login and never made the connection, but after searching through the issues here for performance issues, I see that that's also something that's been reported, so Monitorian might be relevant to that issue as well.

If you need any additional info, I'll be happy to supply it, please just let me know. Thank you for making this software available for free! I use it all the time and 99% of the time I never even think about it, it just works. :)

Specs:
Windows 11
Monitorian 4.9.1.0
ASUS TUF laptop
CPU: AMD Ryzen 5 3550H with Radeon Vega Mobile Gfx
Acer SA242Y external monitor (HDMI)

@emoacht
Copy link
Owner

emoacht commented Nov 20, 2024

Thank you for reporting.
I think I have never experienced such high CPU usage.
I have no idea but operation.log may help. How to produce the log is explained in Reporting section of readme.

@MagicAndre1981
Copy link

Use ETW to capture a trace with wpr.exe from an elevated command prompt (wpr -start CPU ENTER wait until usage dropped and run wpr -stop %USERPROFILE%\MonitorianPlusCPUUsage.etl -compress ENTER) and analyze it with Windows Performance Analyzer (WPA.exe).

@githubyouser
Copy link
Author

Thank you for reporting. I think I have never experienced such high CPU usage. I have no idea but operation.log may help. How to produce the log is explained in Reporting section of readme.

Thanks, I've enabled Reporting, but I haven't seen the issue again yet. I've seen it at least twice in the past week or so, so hopefully I'll be able to catch it next time it happens.

@githubyouser
Copy link
Author

So I left my laptop running and stepped away to eat supper (probably about an hour). When I returned, I could hear the CPU fans running as soon as I stepped into the room. The laptop and HDMI monitor were both sleeping and awoke as soon as I moved the mouse. I checked Task Manager, and sure enough Monitorian is using the CPU constantly again. Here's a copy of the operation.log

@githubyouser
Copy link
Author

Use ETW to capture a trace with wpr.exe from an elevated command prompt (wpr -start CPU ENTER wait until usage dropped and run wpr -stop %USERPROFILE%\MonitorianPlusCPUUsage.etl -compress ENTER) and analyze it with Windows Performance Analyzer (WPA.exe).

Thanks, @MagicAndre1981 I tried running this for a while and then stopping it. It says "the trace was successfully saved" but no .etl file can be found in the directory. :( Not sure what to do about that.

@emoacht
Copy link
Owner

emoacht commented Nov 27, 2024

Thank you for the log.
I found the OS constantly fired display settings changed event.
So this issue happens when your PC suspends?

@MagicAndre1981
Copy link

look in your user folder C:\Users<USERNAME> , but it looks like emoacht already found the cause.

@githubyouser
Copy link
Author

Thank you for the log. I found the OS constantly fired display settings changed event. So this issue happens when your PC suspends?

Thanks for looking into this for me! The display was asleep, but the computer itself was still awake, because the CPU was running hard.

@MagicAndre1981
Copy link

if you found the ETL file does it show anything usefull in callstack of monitorian?

@githubyouser
Copy link
Author

if you found the ETL file does it show anything usefull in callstack of monitorian?

No ETL file is created. I tried twice. Not sure what else to try.

@MagicAndre1981
Copy link

hm, wired. You can replace %USERPROFILE% with a fixed path like C:\ETLTraces\ for example.

@emoacht
Copy link
Owner

emoacht commented Nov 28, 2024

@githubyouser So does it happen when the display is turned off but the system has not suspended yet?

@githubyouser
Copy link
Author

@githubyouser So does it happen when the display is turned off but the system has not suspended yet?

Yes, that's correct. It just happened yesterday again, but I didn't have a chance to do anything about it because I was busy with other things.

@emoacht
Copy link
Owner

emoacht commented Dec 9, 2024

@githubyouser Thank you for the confirmation.
Ant additional information?

@githubyouser
Copy link
Author

Hi @emoacht I haven't noticed it again till today. Then when I logged in to my other user account on the PC, I noticed almost right away that the fans were running hard and sure enough, Monitorian is chewing up ~30% of the CPU again. I tried running the trace again and saving to a different location as @MagicAndre1981 suggested, and this time I got an ETL file! It's 750MB. I took a look at it, but I don't really know what to look for. Any ideas?
image

@emoacht
Copy link
Owner

emoacht commented Dec 10, 2024

I am not an expert of that tool.
If you can identify names of methods that were called during the period, it might be helpful to understand what is happening.

@MagicAndre1981
Copy link

load the debug symbols (PDBs) and expand the full stack of minitorian to see what is called. On the point where the % Weight splitts you have the causing function call.

@githubyouser
Copy link
Author

I just realized that I've been chasing a red herring. The cause of Monitorian's CPU usage is not sleeping, but switching between user accounts in Windows! I have 2 non admin user accounts on my PC and I regularly switch between them. (They both run Monitorian on login). If I don't log out but just switch to the other account, then the CPU usage immediately starts from Monitorian. It was camouflaged before, because logging in usually causes a bunch of CPU usage as various startup programs launch. So I wouldn't notice it till the PC was idle, and then realize that the CPU fans were still going.

I can reliably trigger the bug now by switching between user accounts without logging out of the first one.

@emoacht
Copy link
Owner

emoacht commented Dec 12, 2024

Thank you for update.
Could you run and upload operation.log as is?
I have not seen the clue of user session change in previously uploaded.

@githubyouser
Copy link
Author

operation.log
Sure, here's a copy of the latest operation.log. I had killed the Monitorian process, so I had to start it again, and as soon as I started it, it went back to using ~30% of the CPU.

@emoacht
Copy link
Owner

emoacht commented Dec 13, 2024

Thank you for the log.
Could you disable "restore brightness on reconnection" and see if anything changes?

@githubyouser
Copy link
Author

Could you disable "restore brightness on reconnection" and see if anything changes?

I disabled it in both user profiles but the issue still shows up. When I logged out from one profile, Monitorian's CPU usage immediately went back down to normal. So it only happens when both profiles are logged in and running Monitorian at the same time.

@emoacht
Copy link
Owner

emoacht commented Dec 25, 2024

I found that a preceding instance of this app prevents a succeeding instance from starting named pipe server and causes unauthorized access exception. Consequently, repetitive attemps to start named pipe server caused relatively high CPU usage. It only happens under multiple user setup.

I changed to stop the attempt if that exception is thown. See 3b154cc
A succeeding instance will run without CPU usage but it will no longer accept command-line option to get/set brightness/constrast.

@emoacht emoacht changed the title Monitorian is using ~20% CPU constantly Multiple instances under multiple user setup cause ~20% CPU usage Dec 25, 2024
@githubyouser
Copy link
Author

Awesome, thanks so much for being responsive and helping me track down the bug and then fixing it!

@emoacht emoacht closed this as completed Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants