adding final print for stats
@@ -70,7 +70,7 @@ func (p *Progress) Init(hostCount int64, rulesCount int, requestCount int64) {
p.stats.AddCounter("total", uint64(requestCount))
if p.active {
- if err := p.stats.Start(makePrintCallback(), p.tickDuration); err != nil {
+ if err := p.stats.Start(printCallback, p.tickDuration); err != nil {
gologger.Warning().Msgf("Couldn't start statistics: %s", err)
}
}
@@ -93,7 +93,7 @@ func (p *Progress) IncrementMatched() {
// IncrementErrorsBy increments the error counter by count.
func (p *Progress) IncrementErrorsBy(count int64) {
- p.stats.IncrementCounter("errors", 1)
+ p.stats.IncrementCounter("errors", int(count))
}
// IncrementFailedRequestsBy increments the number of requests counter by count along with errors.
@@ -103,13 +103,8 @@ func (p *Progress) IncrementFailedRequestsBy(count int64) {
p.stats.IncrementCounter("errors", int(count))
}
-const bufferSize = 128
-
-func makePrintCallback() func(stats clistats.StatisticsClient) {
+func printCallback(stats clistats.StatisticsClient) {
builder := &strings.Builder{}
- builder.Grow(bufferSize)
-
- return func(stats clistats.StatisticsClient) {
builder.WriteRune('[')
startedAt, _ := stats.GetStatic("startedAt")
duration := time.Since(startedAt.(time.Time))
@@ -151,8 +146,6 @@ func makePrintCallback() func(stats clistats.StatisticsClient) {
builder.WriteRune('\n')
gologger.Print().Msgf("%s", builder.String())
- builder.Reset()
- }
}
// getMetrics returns a map of important metrics for client
@@ -199,6 +192,8 @@ func fmtDuration(d time.Duration) string {
// Stop stops the progress bar execution
func (p *Progress) Stop() {
if p.active {
+ // Print one final summary
+ printCallback(p.stats)
if err := p.stats.Stop(); err != nil {
gologger.Warning().Msgf("Couldn't stop statistics: %s", err)
}
