runtime/pprof: collecting a CPU profile takes ~200ms of wall time #63043
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, Go 1.21 is the latest release series.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
I hoped to see very little wall-time overhead as a result of enabling the CPU profile.
What did you see instead?
Starting and stopping the CPU profile adds around 200ms of wall-clock time. That's a significant slowdown when the process under test is something like "a benchmark" or "a command, such as the compiler". (It's not as noticeable when the process under test is a long-running server program.)
Furthermore, the DurationNanos field in the resulting protobuf-encoded profile includes that idle time. As a result,
go tool pprof
reporting that the process was less busy than it really was during the time the profile was active: the CPU profile samples represent the work the app does from the start of the call topprof.StopCPUProfile
, but the duration covers until the end of that call.I think this relates to the 100ms sleep in
runtime/pprof.profileWriter
's loop at https://github.com/golang/go/blob/go1.21.1/src/runtime/pprof/pprof.go#L809The text was updated successfully, but these errors were encountered: