golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.09k stars 17.68k forks source link

proposal: net/http/pprof: add parameter for sampling frequency for CPU profiles #57488

Open florianl opened 1 year ago

florianl commented 1 year ago

This proposal is based on https://github.com/golang/go/issues/42502 and adds the ability to configure the sampling rate for CPU profiles.

At the moment it is possible to dynamically collect CPU profiles using the net/http/pprof package via go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30. In this example a 30 second CPU profile is collected. Internally this call utilizes pprof.StartCPUProfile() which uses a hard coded sampling frequency of 100hz.

With https://github.com/golang/go/issues/42502 being accepted it would be great if dynamically collected CPU profiles would also get the option to set the sampling frequency. This could be possible by adding an additional parameter besides seconds like hertz. hertz is just used as an example and input on better naming is always welcomed. This new parameter should be optional and if not set the CPU profile should use the default sampling rate of 100hz.

In the following example a CPU profile of 30 seconds with a sampling rate of 257hz is collected: go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30&hertz=257

mastertheknife commented 1 year ago

I would also like to see this. 100 samples/second are not enough for some applications.

EbenezerJesuraj commented 1 year ago

In my organization we are running multiple-micro services in a golang-based scaffold,I can clearly see such a feature be very important in debugging and in analyzing the efficiency of such services in specific architecture.. Looking forward to see how this proposal will develop in the forth-coming stages..