I am trying to enable Go's "block" profiler by adding the following code to my main function:
f, err := os.Create(profFile)
if err != nil {
// Error handling
}
runtime.SetBlockProfileRate(1)
p := pprof.Lookup("block")
defer func() {
err := p.WriteTo(f, 0)
if err != nil {
Logger.Error("Error writing block profile: %v", err)
}
}()
I do see the profile file created after my application is run and I am trying to interpret the results by running the command:
$ go tool pprof --text <PROFILE_FILE>
29.95mins of 29.95mins total ( 100%)
flat flat% sum% cum cum%
29.95mins 100% 100% 29.95mins 100%
I don't see any data on the block times. Is the code to generate block profile data correct? Or perhaps I need to use different options to "go tool"? Any help is appreciated.
Thanks, Raghu