Skip to content

Commit

Permalink
Fixes golang#42502
Browse files Browse the repository at this point in the history
runtime/pprof: method StartCPUProfile adds a parameter to allow custom cpu rate.
  • Loading branch information
imxyb committed Nov 12, 2020
1 parent d7974c3 commit 08e24e2
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit 08e24e2

Please sign in to comment.