Skip to content

Commit

Permalink
Use gause instead of donut
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Sep 15, 2020
1 parent 2b87b7c commit 6d7aae4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
14 changes: 7 additions & 7 deletions gui/drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type drawer struct {
widgets *widgets
chartCh chan *attacker.Result
donutCh chan bool
gaugeCh chan bool
reportCh chan string

// aims to avoid to perform multiple `redrawChart`.
Expand All @@ -34,10 +34,10 @@ L:
break L
case res := <-d.chartCh:
if res.End {
d.donutCh <- true
d.gaugeCh <- true
break L
}
d.donutCh <- false
d.gaugeCh <- false
values = append(values, float64(res.Latency/time.Millisecond))
d.widgets.latencyChart.Series("latency", values,
linechart.SeriesCellOpts(cell.FgColor(cell.ColorNumber(87))),
Expand All @@ -50,20 +50,20 @@ L:
d.chartDrawing = false
}

func (d *drawer) redrawDonut(ctx context.Context, maxSize int) {
func (d *drawer) redrawGauge(ctx context.Context, maxSize int) {
var count float64
size := float64(maxSize)
d.widgets.progressDonut.Percent(0)
d.widgets.progressGauge.Percent(0)
for {
select {
case <-ctx.Done():
return
case end := <-d.donutCh:
case end := <-d.gaugeCh:
if end {
return
}
count++
d.widgets.progressDonut.Percent(int(count / size * 100))
d.widgets.progressGauge.Percent(int(count / size * 100))
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Run() error {
d := &drawer{
widgets: w,
chartCh: make(chan *attacker.Result),
donutCh: make(chan bool),
gaugeCh: make(chan bool),
reportCh: make(chan string),
}
go d.redrawReport(ctx)
Expand All @@ -66,18 +66,18 @@ func gridLayout(w *widgets) ([]container.Option, error) {
grid.ColWidthPerc(99, grid.Widget(w.latencyChart, container.Border(linestyle.Light), container.BorderTitle("Latency (ms)"))),
)
raw2 := grid.RowHeightPerc(36,
grid.ColWidthPerc(30,
grid.RowHeightPerc(33, grid.Widget(w.urlInput, container.Border(linestyle.None))),
grid.RowHeightPerc(33,
grid.ColWidthPerc(64,
grid.RowHeightPerc(31, grid.Widget(w.urlInput, container.Border(linestyle.None))),
grid.RowHeightPerc(31,
grid.ColWidthPerc(50, grid.Widget(w.rateLimitInput, container.Border(linestyle.None))),
grid.ColWidthPerc(49, grid.Widget(w.durationInput, container.Border(linestyle.None))),
),
grid.RowHeightPerc(32,
grid.RowHeightPerc(31,
grid.ColWidthPerc(50, grid.Widget(w.methodInput, container.Border(linestyle.None))),
grid.ColWidthPerc(49, grid.Widget(w.bodyInput, container.Border(linestyle.None))),
),
grid.RowHeightPerc(6, grid.Widget(w.progressGauge, container.Border(linestyle.None))),
),
grid.ColWidthPerc(34, grid.Widget(w.progressDonut, container.Border(linestyle.Light), container.BorderTitle("Progress"))),
grid.ColWidthPerc(35, grid.Widget(w.reportText, container.Border(linestyle.Light), container.BorderTitle("Report"))),
)
raw3 := grid.RowHeightFixed(1,
Expand Down Expand Up @@ -151,7 +151,7 @@ func attack(ctx context.Context, dr *drawer) {

// To pre-allocate, run redrawChart on a per-attack basis.
go dr.redrawChart(ctx, requestNum)
go dr.redrawDonut(ctx, requestNum)
go dr.redrawGauge(ctx, requestNum)
go func(ctx context.Context, d *drawer, t string, r int, du time.Duration) {
metrics := attacker.Attack(ctx, t, d.chartCh, attacker.Options{Rate: r, Duration: du, Method: method, Body: []byte(body)})
d.reportCh <- metrics.String()
Expand Down
17 changes: 10 additions & 7 deletions gui/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"time"

"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/widgets/donut"
"github.com/mum4k/termdash/linestyle"
"github.com/mum4k/termdash/widgets/gauge"
"github.com/mum4k/termdash/widgets/linechart"
"github.com/mum4k/termdash/widgets/text"
"github.com/mum4k/termdash/widgets/textinput"
Expand All @@ -23,7 +24,7 @@ type widgets struct {
bodyInput *textinput.TextInput
latencyChart *linechart.LineChart
reportText *text.Text
progressDonut *donut.Donut
progressGauge *gauge.Gauge
navi *text.Text
}

Expand Down Expand Up @@ -60,7 +61,7 @@ func newWidgets() (*widgets, error) {
if err != nil {
return nil, err
}
progressDonut, err := newDonut()
progressDonut, err := newGauge()
if err != nil {
return nil, err
}
Expand All @@ -72,7 +73,7 @@ func newWidgets() (*widgets, error) {
bodyInput: bodyInput,
latencyChart: latencyChart,
reportText: reportText,
progressDonut: progressDonut,
progressGauge: progressDonut,
navi: navi,
}, nil
}
Expand Down Expand Up @@ -104,8 +105,10 @@ func newTextInput(label, placeHolder string, cells int) (*textinput.TextInput, e
)
}

func newDonut() (*donut.Donut, error) {
return donut.New(
donut.CellOpts(cell.FgColor(cell.ColorGreen)),
func newGauge() (*gauge.Gauge, error) {
return gauge.New(
gauge.Height(1),
gauge.Border(linestyle.Light),
gauge.BorderTitle("Progress"),
)
}

0 comments on commit 6d7aae4

Please sign in to comment.