Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to increase the sample rate when profiling go programs?

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...

like image 249
Benjamin K. Avatar asked Nov 28 '13 20:11

Benjamin K.


People also ask

What is profiling in Go?

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.

How can you view the Profiler output in CPU Pprof in the browser?

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.

Which of the following package can be used to find memory usage for Go program?

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.

What is CPU profiling?

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.


1 Answers

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.

like image 79
peterSO Avatar answered Sep 23 '22 11:09

peterSO