With CPU Profiling
This one we have the same programer as 01_Initial-No-Profiler
, but with an added file generated for profiling.
This file is done using the following:
...
// Create a Profiling File
fl, err := os.Create("p.out")
if err != nil {
panic(err)
}
defer fl.Close()
// Begin CPU Profiling
pprof.StartCPUProfile(fl)
defer pprof.StopCPUProfile()
...
These lines would create a file p.out
containing the Profile info.
Using golang
internal tool called pprof
we can visualize whats going On.
Profiling Command
go tool pprof -http :6000 p.out
This command would instantly open your Web-browser.
It would show the timing and profile graph of the execution.
Note: The option -http
opens up the pprof
server User interface.
In case one is interested in doing detail analysis in command line - you can
also get a (pprof)
prompt by removing it.
Conclusion
Though the details displayed are stunning but one can hardly image the actual bottle necks.
To some extent one can observe the more time taking function.
But the integrated effect of goroutines
+ Workloads can't be visualized.