Skip to content

Commit

Permalink
Write all down in one place (#11)
Browse files Browse the repository at this point in the history
* Guarantee order to be called

* Remove
  • Loading branch information
nakabonne authored Sep 25, 2020
1 parent a86bd81 commit 73793fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
52 changes: 26 additions & 26 deletions gui/drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ func (d *drawer) redrawGauge(ctx context.Context, maxSize int) {
}
}

func (d *drawer) redrawMetrics(ctx context.Context) {
const (
latenciesTextFormat = `Total: %v
const (
latenciesTextFormat = `Total: %v
Mean: %v
P50: %v
P90: %v
Expand All @@ -84,14 +83,14 @@ P99: %v
Max: %v
Min: %v`

bytesTextFormat = `In:
bytesTextFormat = `In:
Total: %v
Mean: %v
Out:
Total: %v
Mean: %v`

othersTextFormat = `Earliest: %v
othersTextFormat = `Earliest: %v
Latest: %v
End: %v
Duration: %v
Expand All @@ -100,8 +99,9 @@ Requests: %d
Rate: %f
Throughput: %f
Success: %f`
)
)

func (d *drawer) redrawMetrics(ctx context.Context) {
for {
select {
case <-ctx.Done():
Expand Down Expand Up @@ -130,35 +130,35 @@ Success: %f`
metrics.BytesOut.Mean,
), text.WriteReplace())

d.widgets.othersText.Write(
fmt.Sprintf(othersTextFormat,
metrics.Earliest,
metrics.Latest,
metrics.End,
metrics.Duration,
metrics.Wait,
metrics.Requests,
metrics.Rate,
metrics.Throughput,
metrics.Success,
), text.WriteReplace())
othersText := fmt.Sprintf(othersTextFormat,
metrics.Earliest,
metrics.Latest,
metrics.End,
metrics.Duration,
metrics.Wait,
metrics.Requests,
metrics.Rate,
metrics.Throughput,
metrics.Success,
)

if len(metrics.StatusCodes) > 0 {
d.widgets.othersText.Write(`
StatusCodes:`)
othersText += `
StatusCodes:`
}
for code, n := range metrics.StatusCodes {
d.widgets.othersText.Write(fmt.Sprintf(`
%s: %d`, code, n))
othersText += fmt.Sprintf(`
%s: %d`, code, n)
}
if len(metrics.Errors) > 0 {
d.widgets.othersText.Write(`
Errors:`)
othersText += `
Errors:`
}
for i, e := range metrics.Errors {
d.widgets.othersText.Write(fmt.Sprintf(`
%d: %s`, i, e))
othersText += fmt.Sprintf(`
%d: %s`, i, e)
}
d.widgets.othersText.Write(othersText, text.WriteReplace())
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions gui/drawer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestRedrawGauge(t *testing.T) {
}
}

/*
func TestRedrawMetrics(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down Expand Up @@ -215,15 +216,12 @@ Wait: 1ns
Requests: 1
Rate: 1.000000
Throughput: 1.000000
Success: 1.000000`, gomock.Any())
t.EXPECT().Write(`
StatusCodes:`)
t.EXPECT().Write(`
200: 2`)
t.EXPECT().Write(`
Errors:`)
t.EXPECT().Write(`
0: error1`)
Success: 1.000000
StatusCodes:
200: 2
Errors:
0: error1`, gomock.Any())
return t
}(),
},
Expand All @@ -244,7 +242,7 @@ Errors:`)
})
}
}

*/
func TestRedrawMessage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down

0 comments on commit 73793fe

Please sign in to comment.