Currently, runtime.parsedebugvars is called from schedinit which is part of binary bootstrap. This means it's not possible to dynamically enable GODEBUG features once a binary has started.
Typically, we don't want gc traces to flood our logs, but when debugging specific memory issues, it would be helpful if we could enable features (such as gctrace=1 and scavenge=1) dynamically.
While it doesn't have to be via os.Setenv, it;d be useful to have some way to dynamically enable GODEBUG features.
What version of Go are you using (go version)?
$ go version
go version go1.11.2 linux/amd64
Does this issue reproduce with the latest release?
Yes, I'm using the latest release.
What operating system and processor architecture are you using (go env)?
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/prashant/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/prashant/go"
GOPROXY=""
GORACE=""
GOROOT="/home/prashant/bin/go1.11.2"
GOTMPDIR=""
GOTOOLDIR="/home/prashant/bin/go1.11.2/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build849457703=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Set GODEBUG to gctrace=1,scavenge=1 dynamically using os.Setenv.
What did you expect to see?
Expected to see GC traces once the variable was set.
What did you see instead?
No GC traces.
Currently,
runtime.parsedebugvarsis called fromschedinitwhich is part of binary bootstrap. This means it's not possible to dynamically enable GODEBUG features once a binary has started.Typically, we don't want gc traces to flood our logs, but when debugging specific memory issues, it would be helpful if we could enable features (such as gctrace=1 and scavenge=1) dynamically.
While it doesn't have to be via
os.Setenv, it;d be useful to have some way to dynamically enableGODEBUGfeatures.What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
Yes, I'm using the latest release.
What operating system and processor architecture are you using (
go env)?What did you do?
Set
GODEBUGtogctrace=1,scavenge=1dynamically usingos.Setenv.What did you expect to see?
Expected to see GC traces once the variable was set.
What did you see instead?
No GC traces.