Skip to content

Combine Process .Ppid(), .Name(), NumThreads() for Windows #818

Description

@AtakanColak

Is your feature request related to a problem? Please describe.

While trying to all of the information of all my processes in my Windows 10 PC using gopsutil.process, I observed about %40 CPU usage and ~38s runtime. After introducing go's concurrency and removing Cmdline() and IOCounters() calls which used most of the runtime, I was able to reduce it to about ~1.5s. However %40 CPU usage stayed. I did CPU profiling with pprof and found getFromSnapProcess was using the most resources. Right now it discards 2 of the 3 values (ppid, name and num threads) returned by a windows.ProcessEntry32 object in each call, which is found by iterating through all of the processess in the PC. This causes a O(3 * N * N) complexity while it is possible to iterate for once and keep the data for further calls with just a O(N) complexity with only a slight increase in memory usage.

Describe the solution you'd like

I wrote an external replacement function for getFromSnapProcess which keeps its data as a map with referencing:

https://golang.hotexamples.com/examples/syscall/-/Process32First/golang-process32first-function-examples.html

I observed a drop in CPU from %40 to %2 while increasing total memory usage by about 20MB. Runtime also dropped from 1.4s to about 0.3s. However I don't have the time to prepare this for gopsutil at the moment. Therefore I wanted to add this as a feature request.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions