title: How to profile benchmarks using the pprof tool?
body: <p>I want to <strong>profile</strong> my benchmarks generated by <code>go test -c</code>, but the <code>go tool pprof</code> needs a profile file usually generated inside the main function like <a href="http://blog.golang.org/profiling-go-programs">this</a>:</p>
  
  <pre><code>func main() {
      flag.Parse()
      if *cpuprofile != "" {
          f, err := os.Create(*cpuprofile)
          if err != nil {
              log.Fatal(err)
          }
          pprof.StartCPUProfile(f)
          defer pprof.StopCPUProfile()
      }
  </code></pre>
  
  <p>How can I create a profile file within my benchmarks ?</p>