gopsutil
gopsutil copied to clipboard
When I call process.Percent,memory increase slowly
Describe the bug When I call process.Percent,memory increases slowly
To Reproduce
package main
import (
"fmt"
"os"
"strconv"
"time"
"github.com/shirou/gopsutil/v3/process"
)
func main() {
if len(os.Args) < 1 {
fmt.Println("exec pid")
return
}
pid, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Println("pid should int")
return
}
p, err := process.NewProcess(int32(pid))
if err != nil {
fmt.Println(err)
return
}
for {
cpu, _ = p.Percent(1 * time.Second)
fmt.Printf("cpu:%.2f\n", cpu)
}
}
Environment (please complete the following information):
- [ ] Windows: [paste the result of
ver] - [ ] Linux: [paste contents of
/etc/os-releaseand the result ofuname -a] - [x] Mac OS: [paste the result of
sw_versanduname -a - [ ] FreeBSD: [paste the result of
freebsd-version -k -r -uanduname -a] - [ ] OpenBSD: [paste the result of
uname -a]
sw_vers
ProductName: macOS
ProductVersion: 12.7
BuildVersion: 21G816
Additional context
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mf/Library/Caches/go-build"
GOENV="/Users/mf/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mf/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mf/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.10"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bh/sk4mvy391bn6rndd7q83wxkm0000gp/T/go-build1363534723=/tmp/go-build -gno-record-gcc-switches -fno-common"
yes, facing the same issue
When I run your code for 10 minutes, it does not increase memory.
- Linux 5.4.0-174-generic
- go version go1.21.4 linux/amd64
Could you get a memory profile? Thank you.