your program never completes, pprof.StopCPUProfile() has no chance of
being called.

On Tue, Feb 7, 2017 at 2:55 PM, Jason E. Aten <[email protected]> wrote:
> How does one reliably obtain a cpu profile written to file?  I tried
> following the instructions in runtime/pprof.go, but the profile file is most
> always empty... only on some magical moments can I discover a profile file
> being written to disk.
>
> I also tried calling f.Sync() on the file hanlde f, from main (below) every
> minute, but that didn't help.
>
> Supposedly the profiler is sampling at 100Hz, but I can't seem to get any
> samples.
>
> repro code:
> $ cat addack.go
> package main
>
> import (
>     "fmt"
>     "log"
>     //"net/http"
>     _ "net/http/pprof"
>     "os"
>     "runtime/pprof"
> )
>
> const ProgramName = "profileme"
>
> func main() {
>
>     f, err := os.Create(fmt.Sprintf("./addack-cpu-profile.%v", os.Getpid()))
>     if err != nil {
>         log.Fatal(err)
>     }
>     pprof.StartCPUProfile(f)
>     defer pprof.StopCPUProfile()
>
>     massiveAddack()
> }
>
> func massiveAddack() {
>     m := 0
>     for {
>         m = addSub(m)
>         fmt.Printf("m=%v\n", m)
>     }
> }
>
> func addSub(n int) int {
>     for i := 0; i < 1000000000; i++ {
>         n += i * i
>     }
>     return n
> }
>
>  $ go run addack.go
> m=3338615082255021824
> m=6677230164510043648
> m=-8430898826944486144
> m=-5092283744689464320
> m=-1753668662434442496
> m=1584946419820579328
> ^Csignal: interrupt
> $
> $ ls -al|grep addack-cpu-profile.31523
> -rw-rw-r--    1 jason  staff           0 Feb  7 15:50
> addack-cpu-profile.31523  ## hmm.... profile file is always empty
>  $
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to