go常用命令

go help

  • test
  • testflag

    build选项

  • -gcflags “-N -l” 是为了关闭编译器优化和函数内联,防止后面在设置断点的时候找不到相对应的代码位置
  • –gcflags=-m 内存逃逸分析

GODEBUG环境变量

GODEBUG=gctrace=1 go run cmd/agent_bin.go
- 设置 `schedtrace=X` 参数可以使运行时在每 X 毫秒发出一行调度器的摘要信息到标准 err 输出中
- `scheddetail=1` 可以使运行时在每 X 毫秒发出一次详细的多行信息,信息内容主要包括调度程序、处理器、OS 线程 和 Goroutine 的状态。

go tool

pprof

  • display

    • 命令行方式 go tool pprof xx.out
    • web方式 go tool pprof -http=:8080 heap.out
  • 生成文件

    • 代码生成

      // cpu
      pprof.StartCPUProfile(w)
      defer pprof.StopCPUProfile()
      // mem
      pprof.WriteHeapProfile(w)
      
    • curl从http获取 localhost:6061/debug/pprof/profile?...

    • 性能测试 go test -bench=. -cpuprofile=./cpu.prifile

  • 分析

    • go tool pprof x.prof
      • top
      • list func
      • web
    • go-torch x.prof | go-torch -u http=localhost:6061 -t30

trace

  • 获取trace文件
    • 写代码
        trace.Start(w)
        defer trace.Stop()
    • http请求 /debug/pprof/trace
  • 分析
    • go tool trace /tmp/trace.output

objdump反汇编

  • go tool objdump -S -s “main.example” ./example1

test

性能测试

  • GOGC=off go test -cpu 1 -run none -bench . -benchtime 3s
  • GOGC=off go test -cpu 8 -run none -bench . -benchtime 3s

压力测试

  • go-wrk
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!