Skip to content

Commit 08e24e2

Browse files
committed
Fixes golang#42502
runtime/pprof: method StartCPUProfile adds a parameter to allow custom cpu rate.
1 parent d7974c3 commit 08e24e2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: src/runtime/pprof/pprof.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ var cpu struct {
758758
// not to the one used by Go. To make it work, call os/signal.Notify
759759
// for syscall.SIGPROF, but note that doing so may break any profiling
760760
// being done by the main program.
761-
func StartCPUProfile(w io.Writer) error {
761+
func StartCPUProfile(w io.Writer, specifiedRate ...int) error {
762762
// The runtime routines allow a variable profiling rate,
763763
// but in practice operating systems cannot trigger signals
764764
// at more than about 500 Hz, and our processing of the
@@ -780,7 +780,11 @@ func StartCPUProfile(w io.Writer) error {
780780
return fmt.Errorf("cpu profiling already in use")
781781
}
782782
cpu.profiling = true
783-
runtime.SetCPUProfileRate(hz)
783+
if len(specifiedRate) > 0 {
784+
runtime.SetCPUProfileRate(specifiedRate[0])
785+
} else {
786+
runtime.SetCPUProfileRate(hz)
787+
}
784788
go profileWriter(w)
785789
return nil
786790
}

0 commit comments

Comments
 (0)