Skip to content

Commit

Permalink
Fix output
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodauria committed Feb 6, 2024
1 parent afa2e43 commit 85e5db2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type Throughput1Client struct {

// Result contains the aggregate metrics collected during the test.
type Result struct {
// Subtest is the subtest this Result refers to.
Subtest spec.SubtestKind
// Goodput is the average number of application-level bits per second that
// have been transferred so far across all the streams.
Goodput float64
Expand Down Expand Up @@ -353,7 +355,7 @@ func (c *Throughput1Client) runStream(ctx context.Context, streamID int, mURL *u
m.Network.BytesReceived, m.Network.BytesSent))
c.storeMeasurement(streamID, m)
if c.started.Load() {
res := c.computeResult()
res := c.computeResult(subtest)
c.config.Emitter.OnResult(res)
c.lastResultForSubtestMutex.Lock()
c.lastResultForSubtest[subtest] = res
Expand Down Expand Up @@ -393,11 +395,12 @@ func (c *Throughput1Client) applicationBytes() int64 {
}

// computeResult returns a Result struct with the current state of the measurement.
func (c *Throughput1Client) computeResult() Result {
func (c *Throughput1Client) computeResult(subtest spec.SubtestKind) Result {
applicationBytes := c.applicationBytes()
elapsed := time.Since(c.sharedStartTime)
goodput := float64(applicationBytes) / float64(elapsed.Seconds()) * 8 // bps
return Result{
Subtest: subtest,
Elapsed: elapsed,
Goodput: goodput,
Throughput: 0, // TODO,
Expand Down
8 changes: 5 additions & 3 deletions pkg/client/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type HumanReadable struct {

// OnResult prints the aggregate result.
func (HumanReadable) OnResult(r Result) {
fmt.Printf("Download rate: %f Mb/s, rtt: %.2f, minrtt: %.2f\n",
r.Goodput/1e6, float32(r.RTT)/1000, float32(r.MinRTT)/1000)
fmt.Printf("%s rate: %f Mb/s, rtt: %.2f, minrtt: %.2f\n",
r.Subtest, r.Goodput/1e6, float32(r.RTT)/1000, float32(r.MinRTT)/1000)
}

// OnStart is called when the stream starts and prints the subtest and server hostname.
Expand Down Expand Up @@ -71,8 +71,10 @@ func (HumanReadable) OnSummary(results map[spec.SubtestKind]Result) {
fmt.Println()
fmt.Printf("Test results:\n")
for kind, result := range results {
fmt.Printf(" %s rate: %.2f Mb/s, rtt: %.2f ms, minrtt: %.2f ms\n",
fmt.Printf(" %s rate: %.2f Mb/s, rtt: %.2fms, minrtt: %.2fms\n",
kind, result.Goodput/1e6, float32(result.RTT)/1000, float32(result.MinRTT)/1000)
fmt.Printf(" streams: %d, duration: %.2fs, cc algo: %s, byte limit: %d bytes\n",
result.Streams, result.Length.Seconds(), result.CongestionControl, result.ByteLimit)
}
}

Expand Down

0 comments on commit 85e5db2

Please sign in to comment.