From 04492f2982458f16174c017298d3b3d17e6fe3d1 Mon Sep 17 00:00:00 2001 From: Wesley Merkel Date: Tue, 5 Nov 2024 12:37:17 -0700 Subject: [PATCH] feat(benchmark): use humanize to print stats --- go.mod | 1 + go.sum | 2 ++ internal/impl/pure/processor_benchmark.go | 9 +++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index ef10ca60e..0c7c5edaa 100644 --- a/go.mod +++ b/go.mod @@ -52,6 +52,7 @@ require ( github.com/cockroachdb/apd/v3 v3.2.1 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect diff --git a/go.sum b/go.sum index 0fe6cfb33..4ecf74b02 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/emicklei/proto v1.10.0 h1:pDGyFRVV5RvV+nkBK9iy3q67FBy9Xa7vwrOTE+g5aGw= github.com/emicklei/proto v1.10.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= diff --git a/internal/impl/pure/processor_benchmark.go b/internal/impl/pure/processor_benchmark.go index ca80d0656..fb68adf62 100644 --- a/internal/impl/pure/processor_benchmark.go +++ b/internal/impl/pure/processor_benchmark.go @@ -19,6 +19,7 @@ import ( "sync" "time" + "github.com/dustin/go-humanize" "github.com/redpanda-data/benthos/v4/public/service" ) @@ -133,13 +134,13 @@ func (b *benchmarkProc) sampleRolling() benchmarkStats { return s } -func (b *benchmarkProc) printStats(window string, s benchmarkStats, interval time.Duration) { +func (b *benchmarkProc) printStats(window string, stats benchmarkStats, interval time.Duration) { secs := interval.Seconds() b.logger.Infof( - "%s stats: %.2f msgs/sec, %.2f bytes/sec", + "%s stats: %s msg/sec, %s/sec", window, - s.msgCount/secs, - s.msgBytesCount/secs, + humanize.Ftoa(stats.msgCount/secs), + humanize.Bytes(uint64(stats.msgBytesCount/secs)), ) }