Skip to content

Commit 2ce4629

Browse files
oschaafhtuch
authored andcommitted
Improve human readable output. (#77)
Improves human-readable output on the CLI Fixes #69 Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
1 parent 658fbc3 commit 2ce4629

3 files changed

Lines changed: 41 additions & 8 deletions

File tree

source/client/output_formatter_impl.cc

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "client/output_formatter_impl.h"
22

3+
#include <google/protobuf/util/time_util.h>
4+
35
#include <chrono>
46
#include <sstream>
57

@@ -32,10 +34,12 @@ std::string ConsoleOutputFormatterImpl::toString() const {
3234
if (statistic.count() == 0) {
3335
continue;
3436
}
35-
ss << fmt::format("{}: {} samples, mean: {}, pstdev: {}", statistic.id(), statistic.count(),
36-
statistic.mean(), statistic.pstdev())
37-
<< std::endl;
38-
ss << fmt::format("{:<{}}{:<{}}{:<{}}", "Percentile", 12, "Count", 12, "Latency", 15)
37+
ss << fmt::format("{}", statIdtoFriendlyStatName(statistic.id())) << std::endl;
38+
ss << fmt::format(" samples: {}", statistic.count()) << std::endl;
39+
ss << fmt::format(" mean: {}", formatProtoDuration(statistic.mean())) << std::endl;
40+
ss << fmt::format(" pstdev: {}", formatProtoDuration(statistic.pstdev())) << std::endl;
41+
ss << std::endl;
42+
ss << fmt::format(" {:<{}}{:<{}}{:<{}}", "Percentile", 12, "Count", 12, "Latency", 15)
3943
<< std::endl;
4044

4145
// The proto percentiles are ordered ascending. We write the first match to the stream.
@@ -44,8 +48,9 @@ std::string ConsoleOutputFormatterImpl::toString() const {
4448
for (const auto& percentile : statistic.percentiles()) {
4549
if (percentile.percentile() >= p && last_percentile < percentile.percentile()) {
4650
last_percentile = percentile.percentile();
47-
ss << fmt::format("{:<{}}{:<{}}{:<{}}", percentile.percentile(), 12,
48-
percentile.count(), 12, percentile.duration(), 15)
51+
ss << fmt::format(" {:<{}}{:<{}}{:<{}}", percentile.percentile(), 12,
52+
percentile.count(), 12, formatProtoDuration(percentile.duration()),
53+
15)
4954
<< std::endl;
5055
break;
5156
}
@@ -66,6 +71,26 @@ std::string ConsoleOutputFormatterImpl::toString() const {
6671
return ss.str();
6772
}
6873

74+
std::string
75+
ConsoleOutputFormatterImpl::formatProtoDuration(const Envoy::Protobuf::Duration& duration) const {
76+
auto c = Envoy::ProtobufUtil::TimeUtil::DurationToMicroseconds(duration);
77+
return fmt::format("{}s {:03}ms {:03}us", (c % 1'000'000'000) / 1'000'000,
78+
(c % 1'000'000) / 1'000, c % 1'000);
79+
}
80+
81+
std::string ConsoleOutputFormatterImpl::statIdtoFriendlyStatName(absl::string_view stat_id) const {
82+
if (stat_id == "benchmark_http_client.queue_to_connect") {
83+
return "Queueing and connection setup latency";
84+
} else if (stat_id == "benchmark_http_client.request_to_response") {
85+
return "Request start to response end";
86+
} else if (stat_id == "sequencer.callback") {
87+
return "Initiation to completion";
88+
} else if (stat_id == "sequencer.blocking") {
89+
return "Blocking. Results are skewed when significant numbers are reported here.";
90+
}
91+
return std::string(stat_id);
92+
}
93+
6994
void OutputFormatterImpl::addResult(absl::string_view name,
7095
const std::vector<StatisticPtr>& statistics,
7196
const std::map<std::string, uint64_t>& counters) {

source/client/output_formatter_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class ConsoleOutputFormatterImpl : public OutputFormatterImpl {
3232
public:
3333
ConsoleOutputFormatterImpl(Envoy::TimeSource& time_source, const Options& options);
3434
std::string toString() const override;
35+
36+
private:
37+
std::string statIdtoFriendlyStatName(absl::string_view stat_id) const;
38+
std::string formatProtoDuration(const Envoy::Protobuf::Duration& duration) const;
3539
};
3640

3741
class JsonOutputFormatterImpl : public OutputFormatterImpl {

test/test_data/output_formatter.txt.gold

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
Nighthawk - A layer 7 protocol benchmarking tool.
22

3-
stat_id: 3 samples, mean: 0.002s, pstdev: 0.000816497s
4-
Percentile Count Latency
3+
stat_id
4+
samples: 3
5+
mean: 0s 002ms 000us
6+
pstdev: 0s 000ms 816us
7+
8+
Percentile Count Latency
59

610
Counter Value Per second
711
bar 2 2.00

0 commit comments

Comments
 (0)