Skip to content

runtime/pprof: method StartCPUProfile adds a parameter to allow custom cpu rate. #42538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/runtime/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ var cpu struct {
// not to the one used by Go. To make it work, call os/signal.Notify
// for syscall.SIGPROF, but note that doing so may break any profiling
// being done by the main program.
func StartCPUProfile(w io.Writer) error {
func StartCPUProfile(w io.Writer, specifiedRate ...int) error {
// The runtime routines allow a variable profiling rate,
// but in practice operating systems cannot trigger signals
// at more than about 500 Hz, and our processing of the
Expand All @@ -780,7 +780,11 @@ func StartCPUProfile(w io.Writer) error {
return fmt.Errorf("cpu profiling already in use")
}
cpu.profiling = true
runtime.SetCPUProfileRate(hz)
if len(specifiedRate) > 0 {
runtime.SetCPUProfileRate(specifiedRate[0])
} else {
runtime.SetCPUProfileRate(hz)
}
go profileWriter(w)
return nil
}
Expand Down