无法使用Go Profile解析代码

I am trying to get a hang of Go Pro filer by following the example in go blog . I am not sure what I am doing wrong. But my profiled generated output shows 0 samples. Its weird.

rahul@g3ck0:~/programs/go$ go tool pprof parallel cpuprofile 
Welcome to pprof!  For help, type 'help'.
(pprof) top5  
Total: 0 samples

The following is my code :

package main

import (
    "fmt"
    "os/exec"
    "sync"
    "strings"
    "runtime/pprof"
    "os"
)

func exe_cmd(cmd string, wg *sync.WaitGroup) {

    out, err := exec.Command(cmd).Output()
    if err != nil {
        fmt.Println("error occured")
        fmt.Printf("%s", err)
    }
    fmt.Printf("%s", out)

    wg.Done()
}

func main() {
     f, _ := os.Create("cpuprofile")
     pprof.StartCPUProfile(f)
        defer pprof.StopCPUProfile()
    cmd := "echo newline >> blah.txt"
    parts := strings.Fields(cmd)
    head := parts[0]
    parts = parts[1:len(parts)]
    out, err := exec.Command(head,parts...).Output()
    if err != nil {
         fmt.Println("error occured")
         fmt.Printf("%s", err)
        }
        fmt.Printf("%s", out)

}

Your profiled program runs not long enough for the profiler to pick up any profiling sample. Basically the profiler looks periodically at the state of your program (which code is executed, what function is that, ...). If the program terminates faster than the routine that looks for a status then no status is sampled and, thus, there are no samples to look at in the end.

This is what happens for you.

One solution is set the sample rate of the profiler to a higher value, the other way is to have your program actually do something that takes longer. For example:

 f, _ := os.Create("cpuprofile")

 pprof.StartCPUProfile(f)
 defer pprof.StopCPUProfile()

 for i := 0; i < 10; i++ {
      time.Sleep(1 * time.Second)
 }

Alternatively, when trying to figure out what is wrong with a isolated portion of your code, you can write a benchmark and profile that benchmark.