an introduction to go tool trace and describing how you can use it to debug concurrent Go programs. Go makes it easy to use concurrency with goroutines, which means we do more concurrency, which means we have more concurrency problems.
copy and paste the following code into your main function
func main(){
//go tool trace
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 prgram source code goes here
}
go run main.go
go tool trace trace.out
GODEBUG=gctrace=1 go run .
GOMAXPROCS=3 go run .