From 65c0297240442a512be937c7a831fb07abb8ef6e Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 2 Apr 2020 14:26:12 +0000 Subject: Factor out to make it less verbose. --- fbench/src/fbench/fbench.cpp | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'fbench') diff --git a/fbench/src/fbench/fbench.cpp b/fbench/src/fbench/fbench.cpp index 365ae66eabd..395381966fd 100644 --- a/fbench/src/fbench/fbench.cpp +++ b/fbench/src/fbench/fbench.cpp @@ -200,6 +200,28 @@ FBench::StopClients() printf("\nClients Joined.\n"); } +namespace { + +const char * +approx(double latency, const ClientStatus & status) { + return (latency > (status._timetable.size() / status._timetableResolution - 1)) + ? "ms (approx)" + : "ms"; +} + +std::string +fmtPercentile(double percentile) { + char buf[32]; + if (percentile <= 99.0) { + snprintf(buf, sizeof(buf), "%2d", int(percentile)); + } else { + snprintf(buf, sizeof(buf), "%2.1f", percentile); + } + return buf; +} + +} + void FBench::PrintSummary() { @@ -245,20 +267,9 @@ FBench::PrintSummary() printf("average response time: %8.2f ms\n", status.GetAverage()); for (double percentile : {25.0, 50.0, 75.0, 90.0, 98.0, 99.0, 99.5, 99.6, 99.7, 99.8, 99.9}) { - if (percentile <= 99.0) { - //Backwards compatible printing - if (percentile > (status._timetable.size() / status._timetableResolution - 1)) { - printf("%2d percentile: %8.2f ms (approx)\n", int(percentile), status.GetPercentile(percentile)); - } else { - printf("%2d percentile: %8.2f ms\n", int(percentile), status.GetPercentile(percentile)); - } - } else { - if (percentile > (status._timetable.size() / status._timetableResolution - 1)) { - printf("%2.1f percentile: %8.2f ms (approx)\n", percentile, status.GetPercentile(percentile)); - } else { - printf("%2.1f percentile: %8.2f ms\n", percentile, status.GetPercentile(percentile)); - } - } + double latency = status.GetPercentile(percentile); + printf("%s percentile: %8.2f %s\n", + fmtPercentile(percentile).c_str(), latency, approx(latency, status)); } printf("actual query rate: %8.2f Q/s\n", actualRate); -- cgit v1.2.3