Codebase list golang-github-vbauerster-mpb / 69acf83
minor: stress example with ewma decorators Vladimir Bauer 1 year, 10 months ago
1 changed file(s) with 7 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
1313 )
1414
1515 const (
16 totalBars = 32
16 totalBars = 42
1717 )
1818
1919 var proftype = flag.String("prof", "", "profile type (cpu, mem)")
3737 bar := p.AddBar(int64(total),
3838 mpb.PrependDecorators(
3939 decor.Name(name, decor.WCSyncWidthR),
40 decor.Elapsed(decor.ET_STYLE_GO, decor.WCSyncWidth),
40 decor.OnComplete(decor.Percentage(decor.WCSyncWidth), "done"),
4141 ),
4242 mpb.AppendDecorators(
43 decor.OnComplete(decor.Percentage(decor.WCSyncWidth), "done"),
43 decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_GO, 30, decor.WCSyncWidth), ""),
44 decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 30, decor.WCSyncSpace),
4445 ),
4546 )
4647
4849 defer wg.Done()
4950 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
5051 max := 100 * time.Millisecond
51 for !bar.Completed() {
52 for bar.IsRunning() {
53 start := time.Now()
5254 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
53 bar.Increment()
55 bar.EwmaIncrement(time.Since(start))
5456 }
5557 }()
5658 }