stress example with cpuprofile flag
Vladimir Bauer
3 years ago
| 0 | 0 | package main |
| 1 | 1 | |
| 2 | 2 | import ( |
| 3 | "flag" | |
| 3 | 4 | "fmt" |
| 5 | "log" | |
| 4 | 6 | "math/rand" |
| 7 | "os" | |
| 8 | "runtime/pprof" | |
| 5 | 9 | "sync" |
| 6 | 10 | "time" |
| 7 | 11 | |
| 13 | 17 | totalBars = 32 |
| 14 | 18 | ) |
| 15 | 19 | |
| 20 | var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") | |
| 21 | ||
| 16 | 22 | 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 | } | |
| 17 | 32 | var wg sync.WaitGroup |
| 18 | 33 | // passed wg will be accounted at p.Wait() call |
| 19 | 34 | p := mpb.New(mpb.WithWaitGroup(&wg)) |