Skip to content

Commit

Permalink
use go-humanize to print data transferred sizes (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
bengadbois authored Jul 21, 2018
1 parent 8c7895d commit 80e68d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@
[[constraint]]
branch = "master"
name = "golang.org/x/net"

[[constraint]]
branch = "master"
name = "github.com/dustin/go-humanize"
3 changes: 2 additions & 1 deletion cmd/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"

pewpew "github.com/bengadbois/pewpew/lib"
humanize "github.com/dustin/go-humanize"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -176,7 +177,7 @@ var stressCmd = &cobra.Command{
req.StartTime.String(),
fmt.Sprintf("%d", req.Duration),
fmt.Sprintf("%d", req.StatusCode),
fmt.Sprintf("%d bytes", req.DataTransferred),
fmt.Sprintf("%s", humanize.Bytes(uint64(req.DataTransferred))),
}
err := writer.Write(line)
if err != nil {
Expand Down
23 changes: 12 additions & 11 deletions lib/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sort"
"sync"

humanize "github.com/dustin/go-humanize"
color "github.com/fatih/color"
)

Expand All @@ -24,17 +25,17 @@ func CreateTextStressSummary(reqStatSummary RequestStatSummary) string {
summary := "\n"

summary += "Timing\n"
summary += "Mean query speed: " + fmt.Sprintf("%d", reqStatSummary.avgDuration/1000000) + " ms\n"
summary += "Fastest query speed: " + fmt.Sprintf("%d", reqStatSummary.minDuration/1000000) + " ms\n"
summary += "Slowest query speed: " + fmt.Sprintf("%d", reqStatSummary.maxDuration/1000000) + " ms\n"
summary += "Mean RPS: " + fmt.Sprintf("%.2f", reqStatSummary.avgRPS*1000000000) + " req/sec\n"
summary += "Total time: " + fmt.Sprintf("%d", reqStatSummary.endTime.Sub(reqStatSummary.startTime).Nanoseconds()/1000000) + " ms\n"
summary += fmt.Sprintf("Mean query speed: %d ms\n", reqStatSummary.avgDuration/1000000)
summary += fmt.Sprintf("Fastest query speed: %d ms\n", reqStatSummary.minDuration/1000000)
summary += fmt.Sprintf("Slowest query speed: %d ms\n", reqStatSummary.maxDuration/1000000)
summary += fmt.Sprintf("Mean RPS: %.2f req/sec\n", reqStatSummary.avgRPS*1000000000)
summary += fmt.Sprintf("Total time: %d ms\n", reqStatSummary.endTime.Sub(reqStatSummary.startTime).Nanoseconds()/1000000)

summary += "\nData Transferred\n"
summary += "Mean query: " + fmt.Sprintf("%d", reqStatSummary.avgDataTransferred) + " bytes\n"
summary += "Largest query: " + fmt.Sprintf("%d", reqStatSummary.maxDataTransferred) + " bytes\n"
summary += "Smallest query: " + fmt.Sprintf("%d", reqStatSummary.minDataTransferred) + " bytes\n"
summary += "Total: " + fmt.Sprintf("%d", reqStatSummary.totalDataTransferred) + " bytes\n"
summary += fmt.Sprintf("Mean query: %s\n", humanize.Bytes(uint64(reqStatSummary.avgDataTransferred)))
summary += fmt.Sprintf("Largest query: %s\n", humanize.Bytes(uint64(reqStatSummary.maxDataTransferred)))
summary += fmt.Sprintf("Smallest query: %s\n", humanize.Bytes(uint64(reqStatSummary.minDataTransferred)))
summary += fmt.Sprintf("Total: %s\n", humanize.Bytes(uint64(reqStatSummary.totalDataTransferred)))

summary = summary + "\nResponse Codes\n"
//sort the status codes
Expand Down Expand Up @@ -85,10 +86,10 @@ func (p *printer) printStat(stat RequestStat) {
} else {
color.Set(color.FgRed)
}
fmt.Fprintf(p.output, "%s %d\t%d bytes\t%d ms\t-> %s %s\n",
fmt.Fprintf(p.output, "%s %d\t%s \t%d ms\t-> %s %s\n",
stat.Proto,
stat.StatusCode,
stat.DataTransferred,
humanize.Bytes(uint64(stat.DataTransferred)),
stat.Duration.Nanoseconds()/1000000,
stat.Method,
stat.URL)
Expand Down

0 comments on commit 80e68d2

Please sign in to comment.