The go 1.5 trace command

若如初见. 提交于 2019-12-04 03:33: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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!