Given the following toy code, I would expect to be able to run
go tool pprof cpu.prof
and get useful information about waster1 and waster2, but when I run top in pprof, all I get is:
Showing nodes accounting for 0, 0% of 0 total
flat flat% sum% cum cum%
It is possible the problem is that I am using WSL to run Ubuntu on Windows 10.
Here is the code I am using:
package main
import (
"fmt"
"log"
"os"
"runtime/pprof"
)
func waster2() int {
j := 0;
for i := 0; i < 100; i++ {
j += waster1()
}
return j
}
func waster1() int {
j := 0;
for i := 0; i < 10000; i++ {
j++
}
return j
}
func main() {
f, err := os.Create("cpu.prof")
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
j := waster2()
fmt.Println(j)
}