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

Get Windows Processes Name Take Too Much Time #1053

Closed
1 task
huxt1993 opened this issue Mar 24, 2021 · 3 comments
Closed
1 task

Get Windows Processes Name Take Too Much Time #1053

huxt1993 opened this issue Mar 24, 2021 · 3 comments

Comments

@huxt1993
Copy link

huxt1993 commented Mar 24, 2021

Describe the bug
It takes too much time to get the windows process name. In general, my windows has 260 processes, and When I get the names of these processes, it usually takes 8-9 seconds. It seems execute func getFromSnapProcess(pid int32) (int32, int32, string, error) 260*260 times, not 260 times.

To Reproduce

processInfos, _ := process.Processes()
for _, processInfo := range processInfos {
      name, _ := processInfo.Name()
}

Expected behavior
It should execute func getFromSnapProcess(pid int32) (int32, int32, string, error) 260 times and takse less than 1s

Environment (please complete the following information):

  • Windows: Microsoft Windows [version 10.0.18363.1440]

Additional context
command: go build

C:\WINDOWS\system32>go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\xiaotao.hu\AppData\Local\go-build
set GOENV=C:\Users\xiaotao.hu\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\xiaotao.hu\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\xiaotao.hu\go
set GOPRIVATE=
set GOPROXY=https://goproxy.io
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=x86_64-w64-mingw32-gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\xiaotao.hu\AppData\Local\Temp\go-build909459346=/tmp/go-build -gno-record-gcc-switches

@Lomanic
Copy link
Collaborator

Lomanic commented Mar 24, 2021

Which version of gopsutil are you using (which git tag or commit sha)?

I can't see how you can say that getFromSnapProcess is called 260*260 times in your example, it should be only called once per process here, so 260 times.

@huxt1993
Copy link
Author

I'm very sorry for the number of calls getFromSnapProcess, it should be called 260times. And my psutils version is V3.20.10

@Lomanic
Copy link
Collaborator

Lomanic commented Apr 3, 2021

Try running gopsutil/process benchmarks on the host with that many running processes, but I'm not sure we can do much here.

See also #468 (comment) or #609 with another benchmark using CreateToolhelp32Snapshot internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants