Error when trying to parse trace using go tool trace

Viewed 1999

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 Answers

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 :(

Related