Debugging
约 1 分钟阅读
Go Debug
- go-delve/delveGitHubgo-delve/delve
- MIT, Go
go install github.com/go-delve/delve/cmd/dlv@latest
# 仓库内运行 go.mod
dlv debug --headless --listen=:2345 --api-version=2 --accept-multiclient
# 编译后远程运行
go build -gcflags "all=-N -l" github.com/app/demo
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./demoPackagesgithub.com/go-delve/delve/cmd/dlvGo Packagegithub.com/go-delve/delve/cmd/dlvGo
pprof
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
}go build main.go
./main -cpuprofile=out.prof
go tool pprof main out.profbenchstat
go install golang.org/x/perf/cmd/benchstat@latest
# 测试然后输出统计
go test ./contextx/ -bench=BenchmarkCopy -benchmem -run=^$ -count=10 > out.txt
benchstat out.txt
# 对比
# delta 为 ~ 表示两次没有差异
benchstat old.txt new.txtPackagesgolang.org/x/perf/cmd/benchstatGo Packagegolang.org/x/perf/cmd/benchstatGo
关联信息
反向链接、本文链接的其他页面和外部资料。
References
GitHub1 条
- go-delve/delvegithub.com/go-delve/delve
Packages1 条
- golang.org/x/perf/cmd/benchstatpkg.go.dev/golang.org/x/perf/cmd/benchstat