douang2297 2015-08-21 02:12
浏览 170
已采纳

go 1.5 trace命令

The Go 1.5 release note says,

The new "go tool trace" command enables the visualisation of program traces generated by new tracing infrastructure in the runtime.

This is really exciting, and I want to know more about it. But its official document at https://golang.org/cmd/trace/ is really dry.

Found that Rob Pike complained about it, requesting that "shortly after the 1.5 release, there should be a blog post about the feature."

If anyone has posted/spotted such a blog, please add a link here. Or, if you like to answer directly here, it is also welcome as well.

Thanks

  • 写回答

1条回答 默认 最新

  • donglao7947 2015-08-21 06:45
    关注

    There are two ways you can generate trace files.

    Method 1

    1. Add following line at the start of your program

      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()
      
    2. build the program

      go build

    3. Run your program (for example ./myprogram)
    4. Run go trace.

      go tool trace myprogram 2015-08-21T115354.pprof

    Method 2

    1. Write a testing function utilizing testing package.
    2. Run Test with trace flag

      go test -trace trace.out

    3. Run trace tool with generated .test and .out file

      go tool trace pkg.test trace.out

    In both cases your browser will open something like this

    enter image description here enter image description here enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献