-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Windows Process.Name() getFromSnapProcess() performance #1368
Comments
Changing the flag used in
In fact, psutil doesn't use |
We align ourself with psutil https://github.com/giampaolo/psutil/blob/8e4099d9f063ceb4ee3da5845562c5b934f83544/psutil/_pswindows.py#L749-L759 Benchmmarks show vast improvements go test -run=BenchmarkProcessName -bench=BenchmarkProcessName ./process goos: windows goarch: amd64 pkg: github.com/shirou/gopsutil/v3/process cpu: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz BenchmarkProcessName-4 180 6564033 ns/op BenchmarkProcessNameViaExe-4 22111 51153 ns/op PASS ok github.com/shirou/gopsutil/v3/process 3.914s Fixes shirou#1368
We align ourself with psutil https://github.com/giampaolo/psutil/blob/8e4099d9f063ceb4ee3da5845562c5b934f83544/psutil/_pswindows.py#L749-L759 Benchmarks show vast improvements go test -run=BenchmarkProcessName -bench=BenchmarkProcessName ./process goos: windows goarch: amd64 pkg: github.com/shirou/gopsutil/v3/process cpu: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz BenchmarkProcessName-4 180 6564033 ns/op BenchmarkProcessNameViaExe-4 22111 51153 ns/op PASS ok github.com/shirou/gopsutil/v3/process 3.914s Fixes shirou#1368
@Lomanic BTW, |
Ppid can be obtained as the last field in the ProcessBasicInformation struct. But that obviously uses
This is functional and way faster this way, but a lot more thought needs to occur for this patch. For the
but I'm not convinced it will be faster as it's a more granular snapshot. |
Currently
Process.Name()
on Windows calls theCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, pid)
syscall to get it's ppid and name:gopsutil/process/process_windows.go
Lines 321 to 322 in 400a453
gopsutil/process/process_windows.go
Lines 830 to 831 in 400a453
It seems
CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, pid)
will return all processes in the system despite passing the ProcessID parameter.Although returning a snapshot of all processes is quite fast most of the time (<10ms), it can sometimes be slow (>100ms, sometimes even >1000ms).
Can we change the flags like below according to the documentation:
(not so sure about the exact flags, especially
TH32CS_SNAPMODULE32
)or switch to
NtQuerySystemInformation
?refs
https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot:
see also
The text was updated successfully, but these errors were encountered: