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+
6994void OutputFormatterImpl::addResult (absl::string_view name,
7095 const std::vector<StatisticPtr>& statistics,
7196 const std::map<std::string, uint64_t >& counters) {
0 commit comments