On Wednesday, 19 August 2015 23:32:16 UTC+3, Shan Valleru wrote:
Here's the code I used to create a 10s trace from a server. You should be able to modify it to your own needs.
import "runtime/trace"
func trace10(w http.ResponseWriter, r *http.Request) {
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()
// All the important stuff is happening in other goroutines so we just wait here
time.Sleep(10 * time.Second)
}
Once you have integrated that into your own code whatever way you need:
// on Linux you can create/analyze it as:
go build .
./program
go tool trace program 2015-08-20T133508.pprof
// on Windows
go build .
program.exe
go tool trace program.exe 2015-08-20T133508.pprof