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

runtime: GODEBUG=allocfreetrace=1 not working as go1.19.2 in go1.23.0 #68885

Closed
bronze1man opened this issue Aug 15, 2024 · 4 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@bronze1man
Copy link
Contributor

bronze1man commented Aug 15, 2024

Go version

go version go1.23.0 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/a/Library/Caches/go-build'
GOENV='/Users/a/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/a/go/pkg/mod'
GONOPROXY='xxx.com'
GONOSUMDB='xxxx.com'
GOOS='darwin'
GOPATH='/Users/a/go'
GOPRIVATE='xxxx.com'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/a/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/xxx/go.mod'
GOWORK='/xxx/go.work'
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 -ffile-prefix-map=/var/folders/mw/884f6hx53r56gd7zxsm1h8bm0000gp/T/go-build2465272456=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

go build -o ./bin/tAlloc3 ./make/tAlloc3
GODEBUG=allocfreetrace=1 ./bin/tAlloc3 &> ./tmp/2.log

my code

package main
import "fmt"
func main(){
	fmt.Println("abc")
}

What did you see happen?

nothing, only "abc"

What did you expect to see?

a lot of stack of alloc place of my code like in ./tmp/2.log

tracealloc(0xc000024000, 0x40, *runtime.p)
goroutine 0 [idle]:
runtime.mallocgc(0x40, 0x1098460, 0x1)
	/usr/local/go/src/runtime/malloc.go:1121 +0x7aa fp=0x7ff7bfeff6d8 sp=0x7ff7bfeff660 pc=0x100b9ea
runtime.makeslice(0x59960e85937f?, 0x105cbc1?, 0x1006a3f?)
	/usr/local/go/src/runtime/slice.go:103 +0x52 fp=0x7ff7bfeff700 sp=0x7ff7bfeff6d8 pc=0x1045c72
runtime.procresize(0x8)
	/usr/local/go/src/runtime/proc.go:4822 +0x15c fp=0x7ff7bfeff7b8 sp=0x7ff7bfeff700 pc=0x103d53c
runtime.schedinit()
	/usr/local/go/src/runtime/proc.go:722 +0x1d3 fp=0x7ff7bfeff810 sp=0x7ff7bfeff7b8 pc=0x1034713
runtime.rt0_go()
	/usr/local/go/src/runtime/asm_amd64.s:345 +0x11e fp=0x7ff7bfeff818 sp=0x7ff7bfeff810 pc=0x105ab3e 
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 15, 2024
@bronze1man
Copy link
Contributor Author

bronze1man commented Aug 15, 2024

Then I tried the new api from "runtime.trace" and "golang.org/x/exp/trace". I can not get stacktrace of every alloc.

package main

import (
	"os"
	"runtime/trace"
	trace2 "golang.org/x/exp/trace"
	"fmt"
)

func main(){
	runTrace()
	f,err:=os.Open("./tmp/1.trace")
	if err!=nil{
		panic(err)
	}
	r,err:=trace2.NewReader(f)
	if err!=nil{
		panic(err)
	}
	for {
		event,err:=r.ReadEvent()
		if err!=nil{
			fmt.Println(err)
			return
		}
		if event.Kind()!=trace2.EventExperimental{
			continue
		}
		exp:=event.Experimental()
		if exp.Name=="HeapObjectAlloc"{
			fmt.Println(event.String())
			fmt.Println(event.Stack())
		}
	}
}

func runTrace(){
	os.Setenv("GODEBUG", "traceallocfree=1")
	f,err:=os.Create("./tmp/1.trace")
	if err!=nil{
		panic(err)
	}
	trace.Start(f)
	defer trace.Stop()
	toTrace()
}

func toTrace(){
	fmt.Println(`abc`)
}

I can not get stacktrace of every alloc:

abc
M=140704665246592 P=0 G=1 Experimental Time=98720547720960 Name=HeapObjectAlloc ArgNames=[id type] Args=[8288 10]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547721472 Name=HeapObjectAlloc ArgNames=[id type] Args=[61454 0]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547721856 Name=HeapObjectAlloc ArgNames=[id type] Args=[60426 11]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547722048 Name=HeapObjectAlloc ArgNames=[id type] Args=[61468 0]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547722624 Name=HeapObjectAlloc ArgNames=[id type] Args=[10334 12]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547723136 Name=HeapObjectAlloc ArgNames=[id type] Args=[3744 13]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547730816 Name=HeapObjectAlloc ArgNames=[id type] Args=[61482 0]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547731072 Name=HeapObjectAlloc ArgNames=[id type] Args=[8291 10]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547731264 Name=HeapObjectAlloc ArgNames=[id type] Args=[61496 0]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547731520 Name=HeapObjectAlloc ArgNames=[id type] Args=[60436 11]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547731840 Name=HeapObjectAlloc ArgNames=[id type] Args=[10336 14]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547732096 Name=HeapObjectAlloc ArgNames=[id type] Args=[3800 13]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547735616 Name=HeapObjectAlloc ArgNames=[id type] Args=[8294 15]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547735808 Name=HeapObjectAlloc ArgNames=[id type] Args=[3856 13]
{<nil> 0}
M=123145502023680 P=1 G=6 Experimental Time=98720547783744 Name=HeapObjectAlloc ArgNames=[id type] Args=[72704 16]
{<nil> 0}
M=123145502023680 P=1 G=6 Experimental Time=98720547790848 Name=HeapObjectAlloc ArgNames=[id type] Args=[73728 17]
{<nil> 0}
M=123145502023680 P=1 G=7 Experimental Time=98720547806720 Name=HeapObjectAlloc ArgNames=[id type] Args=[74752 16]
{<nil> 0}
M=123145502023680 P=1 G=7 Experimental Time=98720547807488 Name=HeapObjectAlloc ArgNames=[id type] Args=[73740 17]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547826816 Name=HeapObjectAlloc ArgNames=[id type] Args=[62608 18]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547827776 Name=HeapObjectAlloc ArgNames=[id type] Args=[60446 18]
{<nil> 0}
M=140704665246592 P=0 G=1 Experimental Time=98720547828800 Name=HeapObjectAlloc ArgNames=[id type] Args=[139284 18]
{<nil> 0}
EOF

@bronze1man bronze1man changed the title runtime: GODEBUG=traceallocfree=1 not working as go1.19.2 in go1.23.0 runtime: GODEBUG=allocfreetrace=1 not working as go1.19.2 in go1.23.0 Aug 15, 2024
@bronze1man
Copy link
Contributor Author

bronze1man commented Aug 15, 2024

GODEBUG=allocfreetrace=1 is very good tool to make my code faster with less heap alloc.
Now it is not working...

@MikeMitchellWebDev
Copy link
Contributor

runtime: remove allocfreetrace: https://go-review.googlesource.com/c/go/+/583376

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

5 participants