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

When I call process.Percent,memory increase slowly #1541

Open
1 of 5 tasks
frogh1 opened this issue Oct 12, 2023 · 2 comments
Open
1 of 5 tasks

When I call process.Percent,memory increase slowly #1541

frogh1 opened this issue Oct 12, 2023 · 2 comments

Comments

@frogh1
Copy link

frogh1 commented Oct 12, 2023

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-release and the result of uname -a]
  • Mac OS: [paste the result of sw_vers and uname -a
  • FreeBSD: [paste the result of freebsd-version -k -r -u and uname -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"
@vbanu-theja
Copy link

yes, facing the same issue

@shirou
Copy link
Owner

shirou commented Apr 25, 2024

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.

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

4 participants