I have a small program in go that executes most of its code in parallel using go routines. I start CPU profiling as described in the blog on profiling go programs, but when I look at the data I see only 3-5 samples (the actual runtime of the program is several seconds). Is there way to increase the sample rate? Tried googling but couldn't find a thing...
Profiling. Profiling is useful for identifying expensive or frequently called sections of code. The Go runtime provides profiling data in the format expected by the pprof visualization tool. The profiling data can be collected during testing via go test or endpoints made available from the net/http/pprof package.
Instead it's a trace and you can view it using go tool trace (not go tool pprof ). You can see the available profiles with http://localhost:6060/debug/pprof/ in your browser.
To check the CPU and memory usage and other profiles of a Go application at runtime, we can use `pprof` package. You can check for the following details at runtime based on the profile you chose: CPU. Memory/Heap.
CPU Profiler shows what functions consume what percent of CPU time This information can provide you a better understanding of how your application is executed, and how exactly resources are allocated.
Package runtime
func SetCPUProfileRate
func SetCPUProfileRate(hz int)
SetCPUProfileRate sets the CPU profiling rate to hz samples per second. If hz <= 0, SetCPUProfileRate turns off profiling. If the profiler is on, the rate cannot be changed without first turning it off.
Most clients should use the runtime/pprof package or the testing package's -test.cpuprofile flag instead of calling SetCPUProfileRate directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With