How to Use go tool trace for Execution Tracing

Use go tool trace to visualize execution traces generated by runtime/trace or GODEBUG settings.

Use the go tool trace command to visualize execution traces generated by runtime/trace.

  1. Generate a trace file by running your program with the GODEBUG environment variable set to enable tracing, or by importing runtime/trace and calling trace.Start(os.Stdout).
  2. Convert the trace output to a visual format by piping it to go tool trace.
GODEBUG=trace=1 ./your-program > trace.out
go tool trace trace.out

The command opens an interactive web interface in your default browser to analyze goroutine scheduling, GC pauses, and system calls.