Codebase list golang-github-vbauerster-mpb / 7c60ac9
stress example use pkg/profile Vladimir Bauer 3 years ago
2 changed file(s) with 11 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
11
22 go 1.17
33
4 require github.com/vbauerster/mpb/v8 v8.1.2
4 require (
5 github.com/pkg/profile v1.6.0
6 github.com/vbauerster/mpb/v8 v8.1.2
7 )
58
69 require (
710 github.com/VividCortex/ewma v1.2.0 // indirect
22 import (
33 "flag"
44 "fmt"
5 "log"
65 "math/rand"
76 "os"
8 "runtime/pprof"
97 "sync"
108 "time"
119
10 "github.com/pkg/profile"
1211 "github.com/vbauerster/mpb/v8"
1312 "github.com/vbauerster/mpb/v8/decor"
1413 )
1716 totalBars = 32
1817 )
1918
20 var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
19 var proftype = flag.String("prof", "", "profile type (cpu, mem)")
2120
2221 func main() {
2322 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()
23 switch *proftype {
24 case "cpu":
25 defer profile.Start(profile.CPUProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
26 case "mem":
27 defer profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
3128 }
3229 var wg sync.WaitGroup
3330 // passed wg will be accounted at p.Wait() call