dslfq06464 2017-11-10 19:36 采纳率: 0%
浏览 401
已采纳

尝试使用Go工具跟踪解析跟踪时出错

I was following tutorial from JustForFunc episode 22

Added those two lines at the start of main() in main.go:

trace.Start(os.Stdout)
defer trace.Stop()

build the binary using go build -o appName

Timed it with time ./appName > m.trace

And finally tried to open trace with go tool trace m.trace but got following error:

2017/11/10 19:15:38 Parsing trace...
failed to parse trace: unknown event type 50 at offset 0x16

Little more background on my code(golang 1.9, linux) : it is a server for GET requests built with gin-gonic. I added extra line of code time.AfterFunc(20*time.Seconds, func(){closeServer()}) to close my server after 20 seconds so I could make few request to it and then stop server exiting program.

  • 写回答

1条回答 默认 最新

  • dongzuo4666 2017-11-11 12:02
    关注

    I found a solution to my problem. I followed this tutorial https://making.pusher.com/go-tool-trace/. Added code to main :

    f, err := os.Create("trace.out")
    if err != nil {
        panic(err)
    }
    defer f.Close()
    
    err = trace.Start(f)
    if err != nil {
        panic(err)
    }
    defer trace.Stop()
    // Your program here
    

    And it seems to be working fine. I have no idea what could cause this problem :(

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

报告相同问题?