Go 1.5发行说明说:



这真的很令人兴奋,我想了解更多。但是它在https://golang.org/cmd/trace/上的官方文件确实很干。

找到Rob Pike complained about it,要求“在1.5版本发布后不久,应该有关于该功能的博客文章”。

如果有人发布/发现了这样的博客,请在此处添加链接。或者,如果您想直接在这里回答,也欢迎您。

谢谢

最佳答案

有两种方法可以生成跟踪文件。

方法1

  • 在程序的开头添加以下行
    f, err := os.Create(time.Now().Format("2006-01-02T150405.pprof"))
    if err != nil {
        panic(err)
    }
    defer f.Close()
    
    if err := trace.Start(f); err != nil {
        panic(err)
    }
    defer trace.Stop()
    
  • 构建程序

  • 运行程序(例如./myprogram)
  • 运行去跟踪。


  • 方法2
  • 使用测试包编写测试功能。
  • 使用跟踪标志运行测试

  • 使用生成的.test和.out文件运行跟踪工具


  • 在这两种情况下,您的浏览器都将打开类似于的内容

    graph - go 1.5 trace命令-LMLPHP
    graph - go 1.5 trace命令-LMLPHP
    graph - go 1.5 trace命令-LMLPHP

    关于graph - go 1.5 trace命令,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32131339/

    10-12 17:58