shirou / gopsutil

psutil for golang
Other
10.36k stars 1.57k forks source link

: Optimization Request: Reducing the Number of windows.OpenProcess Calls When Gathering Name, CreateTime, and PPID #1608

Open vela-security opened 5 months ago

vela-security commented 5 months ago

Hello,

I'm currently facing a performance bottleneck in my application due to the need to repeatedly call windows.OpenProcess to obtain information such as the process name, creation time, and parent process ID (PPID) for the same process. This repeated operation significantly impacts the overall performance and efficiency of the process information gathering routine in my application.

I'm looking for a way to optimize this aspect, specifically by minimizing the number of times windows.OpenProcess needs to be invoked for the same process. The goal is to improve the performance of my application by reducing the overhead associated with these repetitive system calls.

Is there a recommended approach or best practice for consolidating these operations or somehow reusing the handle obtained from windows.OpenProcess to get all the required information (name, creation time, PPID) in a more efficient manner? Any suggestions or guidance on how to achieve this optimization would be greatly appreciated.

Thank you for your attention to this issue.

shirou commented 4 months ago

One idea is to do cache. gopsutil has a function called EnableBoottimeCache that allows the startup time to be cached. This is mainly for Linux.

Also, psutil can use cache. I believe the number of calls can be reduced by introducing this feature. But no plans at the moment, PR is always welcome!