0

Edit: worked when i added the the executable to the pprof call

I'm trying to profile a simple program with the profiler from https://github.com/pkg/profile: and go tool pprof.

package main

import "github.com/pkg/profile"

func main() {
    defer profile.Start().Stop()
    t1()
    t2()
}

func t1() {
    for i := 0; i < 9000000000; i++ {
        x := i * 2
        x += x
    }
}

func t2() {
    for i := 0; i < 1000000000; i++ {
        x := i * 2
        x += x
    }
}

The examples shows a nice table with all the functions that have been called and how long time was spent in each one of them, but i'm only seeing 100% usage for a few seconds with no more information

what can i do to make it output the functions? does it have anything to do with the "cpu profiling disabled" line that is outputted when the code is done?

this is what I used to generate the output:

./test 
2016/12/16 11:04:39 profile: cpu profiling enabled, /tmp/profile176930291/cpu.pprof
2016/12/16 11:04:44 profile: cpu profiling disabled, /tmp/profile176930291/cpu.pprof
martin@martin-laptop:~/work/bin$ go tool pprof -text /tmp/profile176930291/cpu.pprof 
4.90s of 4.90s total (  100%)                                                                                                                                                                                                                       
      flat  flat%   sum%        cum   cum%
     4.90s   100%   100%      4.90s   100%  
Pownyan
  • 475
  • 1
  • 6
  • 23

1 Answers1

0

Are you getting an error like:

Local symbolization failed for tmp: open /tmp/go-build594370835/command-line-arguments/_obj/exe/tmp: no such file or directory

If so; in the directory of the source, try:

go build tmp.go

Re-running go tool pprof -text ... then results in:

go tool pprof -text /tmp/profile668503934/cpu.pprof
5040ms of 5040ms total (  100%)
      flat  flat%   sum%        cum   cum%
    4560ms 90.48% 90.48%     4560ms 90.48%  main.t1
     480ms  9.52%   100%      480ms  9.52%  main.t2
         0     0%   100%     5040ms   100%  main.main
         0     0%   100%     5040ms   100%  runtime.goexit
         0     0%   100%     5040ms   100%  runtime.main

It's now using the symbols contained in the ./tmp binary.

I'm using go version go1.7.3 linux/amd64

Martin Gallagher
  • 4,444
  • 2
  • 28
  • 26