Codebase list golang-github-vbauerster-mpb / 353837c
stress example with cpuprofile flag Vladimir Bauer 3 years ago
1 changed file(s) with 15 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
00 package main
11
22 import (
3 "flag"
34 "fmt"
5 "log"
46 "math/rand"
7 "os"
8 "runtime/pprof"
59 "sync"
610 "time"
711
1317 totalBars = 32
1418 )
1519
20 var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
21
1622 func main() {
23 flag.Parse()
24 if *cpuprofile != "" {
25 f, err := os.Create(*cpuprofile)
26 if err != nil {
27 log.Fatal(err)
28 }
29 pprof.StartCPUProfile(f)
30 defer pprof.StopCPUProfile()
31 }
1732 var wg sync.WaitGroup
1833 // passed wg will be accounted at p.Wait() call
1934 p := mpb.New(mpb.WithWaitGroup(&wg))