diff --git a/_examples/stress/main.go b/_examples/stress/main.go index 830fca8..5cb4652 100644 --- a/_examples/stress/main.go +++ b/_examples/stress/main.go @@ -1,8 +1,12 @@ package main import ( + "flag" "fmt" + "log" "math/rand" + "os" + "runtime/pprof" "sync" "time" @@ -14,7 +18,18 @@ totalBars = 32 ) +var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") + func main() { + flag.Parse() + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + if err != nil { + log.Fatal(err) + } + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } var wg sync.WaitGroup // passed wg will be accounted at p.Wait() call p := mpb.New(mpb.WithWaitGroup(&wg))