trace

command
v0.0.0-...-578e09f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

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.

Documentation

Overview

Sample program that performs a series of I/O related tasks to better understand tracing in Go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL