diff --git a/call/call_perf_tests.cc b/call/call_perf_tests.cc index 88ac2e8d3f..90eaa5a4d5 100644 --- a/call/call_perf_tests.cc +++ b/call/call_perf_tests.cc @@ -130,8 +130,7 @@ class VideoRtcpAndSyncObserver : public test::RtpRtcpObserver, void PrintResults() { test::PrintResultList("stream_offset", "", "synchronization", - test::ValuesToString(sync_offset_ms_list_), "ms", - false); + sync_offset_ms_list_, "ms", false); } private: @@ -140,7 +139,7 @@ class VideoRtcpAndSyncObserver : public test::RtpRtcpObserver, int64_t first_time_in_sync_; rtc::CriticalSection crit_; VideoReceiveStream* receive_stream_ RTC_GUARDED_BY(crit_); - std::vector sync_offset_ms_list_; + std::vector sync_offset_ms_list_; }; void CallPerfTest::TestAudioVideoSync(FecMode fec, @@ -458,8 +457,7 @@ void CallPerfTest::TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config, "estimated capture NTP time to be " "within bounds."; test::PrintResultList("capture_ntp_time", "", "real - estimated", - test::ValuesToString(time_offset_ms_list_), "ms", - true); + time_offset_ms_list_, "ms", true); } rtc::CriticalSection crit_; @@ -474,7 +472,7 @@ void CallPerfTest::TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config, uint32_t rtp_start_timestamp_; typedef std::map FrameCaptureTimeList; FrameCaptureTimeList capture_time_list_ RTC_GUARDED_BY(&crit_); - std::vector time_offset_ms_list_; + std::vector time_offset_ms_list_; } test(net_config, threshold_ms, start_time_ms, run_time_ms); RunBaseTest(&test); @@ -651,8 +649,7 @@ void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) { "bitrate_stats_", (pad_to_min_bitrate_ ? "min_transmit_bitrate" : "without_min_transmit_bitrate"), - "bitrate_kbps", test::ValuesToString(bitrate_kbps_list_), "kbps", - false); + "bitrate_kbps", bitrate_kbps_list_, "kbps", false); } VideoSendStream* send_stream_; @@ -661,7 +658,7 @@ void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) { const int min_acceptable_bitrate_; const int max_acceptable_bitrate_; int num_bitrate_observations_in_range_; - std::vector bitrate_kbps_list_; + std::vector bitrate_kbps_list_; } test(pad_to_min_bitrate); fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps); diff --git a/modules/audio_processing/audio_processing_performance_unittest.cc b/modules/audio_processing/audio_processing_performance_unittest.cc index 51d4a9163a..ea01f24af0 100644 --- a/modules/audio_processing/audio_processing_performance_unittest.cc +++ b/modules/audio_processing/audio_processing_performance_unittest.cc @@ -269,12 +269,9 @@ class TimedThreadApiProcessor { "us", false); if (kPrintAllDurations) { - std::string value_string = ""; - for (int64_t duration : api_call_durations_) { - value_string += std::to_string(duration) + ","; - } webrtc::test::PrintResultList("apm_call_durations", sample_rate_name, - processor_name, value_string, "us", false); + processor_name, api_call_durations_, "us", + false); } } @@ -432,7 +429,7 @@ class TimedThreadApiProcessor { AudioFrameData frame_data_; webrtc::Clock* clock_; const size_t num_durations_to_store_; - std::vector api_call_durations_; + std::vector api_call_durations_; const float input_level_; bool first_process_call_ = true; const ProcessorType processor_type_; diff --git a/test/testsupport/perf_test.cc b/test/testsupport/perf_test.cc index bb4491af91..b7578d101e 100644 --- a/test/testsupport/perf_test.cc +++ b/test/testsupport/perf_test.cc @@ -16,43 +16,24 @@ #include #include +#include namespace { -std::string ResultsToString(const std::string& measurement, - const std::string& modifier, - const std::string& trace, - const std::string& values, - const std::string& prefix, - const std::string& suffix, - const std::string& units, - bool important) { +void PrintResultsImpl(const std::string& graph_name, + const std::string& trace, + const std::string& values, + const std::string& units, + bool important) { // <*>RESULT : = // <*>RESULT : = {, } // <*>RESULT : = [,value,value,...,] - // TODO(ajm): Use of a stream here may violate the style guide (depending on - // one's definition of "logging"). Consider adding StringPrintf-like - // functionality as in the original Chromium implementation. - std::ostringstream stream; if (important) { - stream << "*"; + printf("*"); } - stream << "RESULT " << measurement << modifier << ": " << trace << "= " - << prefix << values << suffix << " " << units << std::endl; - return stream.str(); -} - -void PrintResultsImpl(const std::string& measurement, - const std::string& modifier, - const std::string& trace, - const std::string& values, - const std::string& prefix, - const std::string& suffix, - const std::string& units, - bool important) { - printf("%s", ResultsToString(measurement, modifier, trace, values, - prefix, suffix, units, important).c_str()); + printf("RESULT %s: %s= %s %s\n", graph_name.c_str(), trace.c_str(), + values.c_str(), units.c_str()); } } // namespace @@ -68,8 +49,8 @@ void PrintResult(const std::string& measurement, bool important) { std::ostringstream value_stream; value_stream << value; - PrintResultsImpl(measurement, modifier, trace, value_stream.str(), "", "", - units, important); + PrintResultsImpl(measurement + modifier, trace, value_stream.str(), units, + important); } void PrintResultMeanAndError(const std::string& measurement, @@ -81,18 +62,30 @@ void PrintResultMeanAndError(const std::string& measurement, bool important) { std::ostringstream value_stream; value_stream << '{' << mean << ',' << error << '}'; - PrintResultsImpl(measurement, modifier, trace, value_stream.str(), "", "", - units, important); + PrintResultsImpl(measurement + modifier, trace, value_stream.str(), units, + important); } void PrintResultList(const std::string& measurement, const std::string& modifier, const std::string& trace, - const std::string& values, + const std::vector& values, const std::string& units, bool important) { - PrintResultsImpl(measurement, modifier, trace, values, - "[", "]", units, important); + std::ostringstream value_stream; + value_stream << '['; + if (!values.empty()) { + auto it = values.begin(); + while (true) { + value_stream << *it; + if (++it == values.end()) + break; + value_stream << ','; + } + } + value_stream << ']'; + PrintResultsImpl(measurement + modifier, trace, value_stream.str(), units, + important); } } // namespace test diff --git a/test/testsupport/perf_test.h b/test/testsupport/perf_test.h index 02dd1f3713..31b7b1345c 100644 --- a/test/testsupport/perf_test.h +++ b/test/testsupport/perf_test.h @@ -17,6 +17,7 @@ #include #include +#include namespace webrtc { namespace test { @@ -52,6 +53,7 @@ void PrintResultMeanAndError(const std::string& measurement, const std::string& units, bool important); + // Like PrintResult(), but prints an entire list of results. The |values| // will generally be a list of comma-separated numbers. A typical // post-processing step might produce plots of their mean and standard @@ -59,27 +61,10 @@ void PrintResultMeanAndError(const std::string& measurement, void PrintResultList(const std::string& measurement, const std::string& modifier, const std::string& trace, - const std::string& values, + const std::vector& values, const std::string& units, bool important); -// Converts list of values into comma-separated string for PrintResultList. -template -std::string ValuesToString(const Container& container) { - if (container.empty()) - return ""; - - std::stringstream ss; - auto it = container.begin(); - while (true) { - ss << *it; - if (++it == container.end()) - break; - ss << ','; - } - return ss.str(); -} - } // namespace test } // namespace webrtc diff --git a/test/testsupport/perf_test_unittest.cc b/test/testsupport/perf_test_unittest.cc index b88f7e1d46..466e2b3e69 100644 --- a/test/testsupport/perf_test_unittest.cc +++ b/test/testsupport/perf_test_unittest.cc @@ -23,7 +23,13 @@ TEST(PerfTest, AppendResult) { PrintResult("measurement", "modifier", "trace", 42, "units", false); expected += "*RESULT foobar: baz= 7 widgets\n"; - PrintResult( "foo", "bar", "baz", 7, "widgets", true); + PrintResult("foo", "bar", "baz", 7, "widgets", true); + + expected += "RESULT foobar: baz= {1,2} lemurs\n"; + PrintResultMeanAndError("foo", "bar", "baz", 1, 2, "lemurs", false); + + expected += "RESULT foobar: baz= [1,2,3] units\n"; + PrintResultList("foo", "bar", "baz", {1, 2, 3}, "units", false); std::string output = testing::internal::GetCapturedStdout(); EXPECT_EQ(expected, output);