diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-04-02 14:26:12 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-04-02 14:26:12 +0000 |
commit | 65c0297240442a512be937c7a831fb07abb8ef6e (patch) | |
tree | 9542a6f612a6eec9e443e479d0517feefdfc99f3 /fbench | |
parent | 63eac4550cb4ebc15816f79fa052e6416821e68b (diff) |
Factor out to make it less verbose.
Diffstat (limited to 'fbench')
-rw-r--r-- | fbench/src/fbench/fbench.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
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); |