gpt4 book ai didi

go - 如何取消设置 $GODEBUG

转载 作者:IT王子 更新时间:2023-10-29 02:06:57 24 4
gpt4 key购买 nike

我一直在使用 Dave Cheney's gcvis tool以解决内存泄漏问题。一切顺利,问题解决。

但是,我不知道该怎么做,但我这辈子都无法阻止垃圾收集器输出淹没我的日志,这让开发变得非常困难。

根据 the runtime-package manual :

Setting gctrace to any value > 0 also causes the garbage collector to emit a summary when memory is released back to the system.

然而,这没有任何效果。

如何删除输出?


我尝试了以下方法:

导出为空值

$ export GODEBUG=
$ go run main.go

取消设置

$ unset GODEBUG
$ go run main.go

设置为零 (也尝试过不带引号,只是为了完成)

$ export GODEBUG="gctrace=0"
$ go run main.go

无论如何,我每次都会得到这个输出(包名称已编辑):

# my-package-0
gc 1 @0.006s 10%: 0.025+3.4+0.11 ms clock, 0.20+1.7/5.9/1.7+0.94 ms cpu, 4->4->3 MB, 5 MB goal, 8 P
gc 2 @0.019s 7%: 0.005+1.0+0.086 ms clock, 0.047+0.67/1.8/2.8+0.69 ms cpu, 5->5->4 MB, 6 MB goal, 8 P
gc 3 @0.030s 6%: 0.006+2.8+0.091 ms clock, 0.053+0.10/4.8/4.2+0.73 ms cpu, 7->8->6 MB, 8 MB goal, 8 P
gc 4 @0.050s 6%: 0.030+4.2+0.096 ms clock, 0.24+1.0/7.3/3.7+0.76 ms cpu, 13->14->8 MB, 14 MB goal, 8 P
# my-package-1
gc 1 @0.007s 5%: 0.010+2.6+0.15 ms clock, 0.086+0.19/3.4/2.6+1.2 ms cpu, 4->4->2 MB, 5 MB goal, 8 P
gc 2 @0.015s 6%: 0.007+2.5+0.11 ms clock, 0.060+0.63/3.4/2.4+0.91 ms cpu, 5->5->4 MB, 6 MB goal, 8 P
gc 3 @0.028s 6%: 0.010+3.0+0.53 ms clock, 0.084+0.23/2.7/2.4+4.2 ms cpu, 8->9->5 MB, 9 MB goal, 8 P
# my-package-3
gc 1 @0.009s 15%: 0.012+4.5+1.7 ms clock, 0.10+0.62/4.5/0.77+13 ms cpu, 4->4->2 MB, 5 MB goal, 8 P
gc 2 @0.030s 9%: 0.006+2.8+0.10 ms clock, 0.050+0.63/3.7/2.9+0.85 ms cpu, 5->5->4 MB, 6 MB goal, 8 P
gc 3 @0.043s 11%: 0.53+3.9+0.084 ms clock, 4.3+7.0/7.8/5.2+0.67 ms cpu, 9->10->7 MB, 10 MB goal, 8 P
gc 4 @0.062s 10%: 0.027+3.6+0.12 ms clock, 0.21+5.2/6.3/5.0+1.0 ms cpu, 12->13->8 MB, 14 MB goal, 8 P
# my-package-4
[...]

根据评论中的要求,这是 $ go env 的输出:

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/dimholt/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/dimholt/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/fx/p9gpbcnd5_jdgqyp6z1w9tqr0000gn/T/go-build333219542=/tmp/go-build -gno-record-gcc-switches -fno-common"

还有我的main.go:

package main

import (
"fmt"
"log"
"net/http"

"github.com/redacted/config"
"github.com/redacted/db"
)

func main() {
conf := config.GetConfig()

// Connect database.
db.Connect()
defer db.Close()

// Register all HTTP routes.
registerRoutes()

port := fmt.Sprintf(":%v", conf.Port)
log.Printf("documents: listening on port %v", port[1:])
log.Fatal(http.ListenAndServe(port, nil))
}

最佳答案

万一其他人遇到这个问题,这对我有用。

go clean -cache

关于go - 如何取消设置 $GODEBUG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55955610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com