Skip to content

Files

Latest commit

Dec 5, 2024
53acb9a · Dec 5, 2024

History

History

trace

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Dec 5, 2024
Nov 9, 2017
May 13, 2021

README.md

Tracing

The tracing can help identify not only what is happening but also what is not happening when your program is running. We will use a simple program to learn how to navigate and read some of the tracing information you can find in the trace tool.

Basic Skills

Review this post to gain basic skills.

[go tool trace](https://making.pusher.com/go-tool-trace/ - Will Sewell
Debugging Latency in Go 1.11 - JBD

Trace Command

You have two options with this code. First uncomment the CPU profile lines to generate a CPU profile.

pprof.StartCPUProfile(os.Stdout)
defer pprof.StopCPUProfile()

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

This will let you run a profile first. Leverage the lessons learned in the other sections.

$ ./trace > p.out
$ go tool pprof p.out

Then run a trace by uncommenting the other lines of code.

// pprof.StartCPUProfile(os.Stdout)
// defer pprof.StopCPUProfile()

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

Once you run the program.

$ ./trace > t.out
$ go tool trace t.out

Then explore the trace tooling by building the program with these different find functions.

n := find(topic, docs)
// n := findConcurrent(topic, docs)
// n := findConcurrentSem(topic, docs)
// n := findProcessors(topic, docs)
// n := findActor(topic, docs)

Using this function allows you to see how to add custom tasks and regions. This requires Go version 1.11.

// n := findProcessorsTasks(topic, docs)

Note that goroutines in "syscall" state consume an OS thread, other goroutines do not (except for goroutines that called runtime.LockOSThread, which is, unfortunately, not visible in the profile).

Note that goroutines in "IO wait" state do NOT consume an OS thread. They are parked on the non-blocking network poller.

Code Review

Profiling Test (Go Playground)


All material is licensed under the Apache License Version 2.0, January 2004.