Closed Still34 closed 5 months ago
Great job! I have to admit I'm not very familar with windows-specific side of things, and I just grabbed the first thing that worked! π
Feel free to submit a PR, I'll try it out!
Maybe I'll incorporate the fix myself over the weekend as well π
Summary
Earlier this month, I was troubleshooting the enormous WMI host CPU usage on my system (consistently around ~5% CPU usage). Through WMIMon, I found that the culprit was the Profile Autoswitcher app. The current implementation appears to query a WMI call to the system every 0.25 second if I'm reading this correctly.
https://github.com/dekuNukem/duckyPad-profile-autoswitcher/blob/b9f690a459630a018ec1bd46407e958b3668b0f4/src/duckypad_autoprofile.py#L640
https://github.com/dekuNukem/duckyPad-profile-autoswitcher/blob/b9f690a459630a018ec1bd46407e958b3668b0f4/src/get_window.py#L109
This constant loop of creating WMI queries causes a heavy strain on the WMI host process.
Suggested Fix
Fortunately, there are other methods of querying for process name with PID. One of the methods is to use native Win32 API instead of having to have a roundtrip to the WMI. Using
NtQuerySystemInformation
with theSystemProcessIdInformation
struct, we can get the PID and the process name without any of the surplus.The following is a PoC that demonstrates how this might be done in Python via ctwin32, a tiny Win32 abstraction library for Python (though this can be done with just the native Python
ctypes
I believe).The profiling shows a huge improvement in overall execution time and there's no stress being done to the WMI process.
Please let me know what you think and if you would like a PR to be created to address this issue.