diff options
| author | Will Hawkins <[email protected]> | 2024-01-03 19:11:10 -0500 |
|---|---|---|
| committer | Will Hawkins <[email protected]> | 2024-01-04 19:17:06 -0500 |
| commit | 218f2e6d235c4e947a04a39e4e09acde7675de6a (patch) | |
| tree | 4642b7deed792e8345ccef86d549c8748a9e0ce8 | |
| parent | f3990f950277c2f61e0e1811b4b8a81fc0219da4 (diff) | |
[Feature] Reformat test result output.
| -rw-r--r-- | extendedstats/unix.go | 10 | ||||
| -rw-r--r-- | networkQuality.go | 73 | ||||
| -rw-r--r-- | utilities/utilities.go | 15 | ||||
| -rw-r--r-- | utilities/utilities_test.go | 20 |
4 files changed, 79 insertions, 39 deletions
diff --git a/extendedstats/unix.go b/extendedstats/unix.go index 1454f1c..fd537ee 100644 --- a/extendedstats/unix.go +++ b/extendedstats/unix.go @@ -60,12 +60,12 @@ func (es *AggregateExtendedStats) IncorporateConnectionStats(basicConn net.Conn) func (es *AggregateExtendedStats) Repr() string { return fmt.Sprintf(`Extended Statistics: - Maximum Path MTU: %v - Maximum Send MSS: %v - Maximum Recv MSS: %v + Maximum Path MTU: %v + Maximum Send MSS: %v + Maximum Recv MSS: %v Total Retransmissions: %v - Total Reorderings: %v - Average RTT: %v + Total Reorderings: %v + Average RTT: %v `, es.MaxPathMtu, es.MaxSendMss, es.MaxRecvMss, es.TotalRetransmissions, es.TotalReorderings, es.AverageRtt) } diff --git a/networkQuality.go b/networkQuality.go index 2e13893..f0b981c 100644 --- a/networkQuality.go +++ b/networkQuality.go @@ -1025,39 +1025,48 @@ func main() { (*direction.ThroughputActivityCtxCancel)() } - direction.FormattedResults += fmt.Sprintf( - "%v: %7.3f Mbps (%7.3f MBps), using %d parallel connections.\n", - direction.DirectionLabel, + // Add a header to the results + direction.FormattedResults += fmt.Sprintf("%v:\n", direction.DirectionLabel) + + if !testRanToStability { + direction.FormattedResults += utilities.IndentOutput( + "Note: Test did not run to stability, these results are estimates.\n", 1, "\t") + } + direction.FormattedResults += utilities.IndentOutput(fmt.Sprintf( + "Throughput: %.3f Mbps (%.3f MBps), using %d parallel connections.\n", utilities.ToMbps(lastThroughputRate), utilities.ToMBps(lastThroughputRate), lastThroughputOpenConnectionCount, - ) + ), 1, "\t") if *calculateExtendedStats { - direction.FormattedResults += fmt.Sprintf("%v\n", extendedStats.Repr()) + direction.FormattedResults += utilities.IndentOutput( + fmt.Sprintf("%v", extendedStats.Repr()), 1, "\t") } directionResult := rpm.CalculateRpm(direction.SelfRtts, direction.ForeignRtts, specParameters.TrimmedMeanPct, specParameters.Percentile) if *debugCliFlag { - direction.FormattedResults += fmt.Sprintf("(%s RPM Calculation stats): %v\n", - direction.DirectionLabel, directionResult.ToString()) + direction.FormattedResults += utilities.IndentOutput( + "RPM Calculation Statistics:\n", 1, "\t") + direction.FormattedResults += utilities.IndentOutput(directionResult.ToString(), 2, "\t") } if *printQualityAttenuation { - direction.FormattedResults += "Quality Attenuation Statistics:\n" - direction.FormattedResults += fmt.Sprintf( - ` Number of losses: %d - Number of samples: %d - Min: %.6f s - Max: %.6f s - Mean: %.6f s - Variance: %.6f s - Standard Deviation: %.6f s - PDV(90): %.6f s - PDV(99): %.6f s - P(90): %.6f s - P(99): %.6f s - RPM: %.0f - Gaming QoO: %.0f + direction.FormattedResults += utilities.IndentOutput( + "Quality Attenuation Statistics:\n", 1, "\t") + direction.FormattedResults += utilities.IndentOutput(fmt.Sprintf( + ` Number of losses: %d + Number of samples: %d + Min: %.6fs + Max: %.6fs + Mean: %.6fs + Variance: %.6fs + Standard Deviation: %.6fs + PDV(90): %.6fs + PDV(99): %.6fs + P(90): %.6fs + P(99): %.6fs + RPM: %.0f + Gaming QoO: %.0f `, selfRttsQualityAttenuation.GetNumberOfLosses(), selfRttsQualityAttenuation.GetNumberOfSamples(), selfRttsQualityAttenuation.GetMinimum(), @@ -1070,18 +1079,14 @@ func main() { selfRttsQualityAttenuation.GetPercentile(90), selfRttsQualityAttenuation.GetPercentile(99), selfRttsQualityAttenuation.GetRPM(), - selfRttsQualityAttenuation.GetGamingQoO()) - } - - if !testRanToStability { - direction.FormattedResults += "Test did not run to stability, these results are estimates:\n" + selfRttsQualityAttenuation.GetGamingQoO()), 1, "\t") } - direction.FormattedResults += fmt.Sprintf("%s RPM: %5.0f (P%d)\n", direction.DirectionLabel, - directionResult.PNRpm, specParameters.Percentile) - direction.FormattedResults += fmt.Sprintf( - "%s RPM: %5.0f (Single-Sided %v%% Trimmed Mean)\n", direction.DirectionLabel, - directionResult.MeanRpm, specParameters.TrimmedMeanPct) + direction.FormattedResults += utilities.IndentOutput(fmt.Sprintf( + "RPM: %.0f (P%d)\n", directionResult.PNRpm, specParameters.Percentile), 1, "\t") + direction.FormattedResults += utilities.IndentOutput(fmt.Sprintf( + "RPM: %.0f (Single-Sided %v%% Trimmed Mean)\n", directionResult.MeanRpm, + specParameters.TrimmedMeanPct), 1, "\t") if len(*prometheusStatsFilename) > 0 { var testStable int @@ -1183,8 +1188,8 @@ func main() { fmt.Printf("(Final RPM Calculation stats): %v\n", result.ToString()) } - fmt.Printf("Final RPM: %5.0f (P%d)\n", result.PNRpm, specParameters.Percentile) - fmt.Printf("Final RPM: %5.0f (Single-Sided %v%% Trimmed Mean)\n", + fmt.Printf("Final RPM: %.0f (P%d)\n", result.PNRpm, specParameters.Percentile) + fmt.Printf("Final RPM: %.0f (Single-Sided %v%% Trimmed Mean)\n", result.MeanRpm, specParameters.TrimmedMeanPct) if *calculateRelativeRpm { diff --git a/utilities/utilities.go b/utilities/utilities.go index b976f77..a1ec805 100644 --- a/utilities/utilities.go +++ b/utilities/utilities.go @@ -220,3 +220,18 @@ type Pair[T1, T2 any] struct { func PerSecondToInterval(rate int64) time.Duration { return time.Duration(time.Second.Nanoseconds() / rate) } + +func IndentOutput(output string, depth uint, character string) string { + finalNewline := false + if strings.LastIndex(output, "\n") == len(output)-1 { + finalNewline = true + output = strings.TrimSuffix(output, "\n") + } + indentedOutput := strings.Join(Fmap[string](strings.SplitAfter(output, "\n"), func(line string) string { + return strings.Repeat(character, int(depth)) + line + }), "") + if finalNewline { + indentedOutput += "\n" + } + return indentedOutput +} diff --git a/utilities/utilities_test.go b/utilities/utilities_test.go index 7f3d83a..8f43c6d 100644 --- a/utilities/utilities_test.go +++ b/utilities/utilities_test.go @@ -188,3 +188,23 @@ func TestTrimmedMean(t *testing.T) { t.Fatalf("The trimmed mean result %v does not match the expected value %v", result, expected) } } + +func TestIndentStringOneNewline(t *testing.T) { + output := "This is my output\n" + + indendentedOutput := IndentOutput(output, 3, "--") + + if indendentedOutput != "------This is my output\n" { + t.Fatalf("I expected the indented output to be ####%v#### but got ####%v####!", output, indendentedOutput) + } +} + +func TestIndentStringMultipleNewlines(t *testing.T) { + output := "This is my output\n\n" + + indendentedOutput := IndentOutput(output, 3, "--") + + if indendentedOutput != "------This is my output\n------\n" { + t.Fatalf("I expected the indented output to be ####%v#### but got ####%v####!", output, indendentedOutput) + } +} |
