From f5808fc4c5f480ee114d94400746735238b3412a Mon Sep 17 00:00:00 2001 From: Artem Titov Date: Fri, 23 Sep 2022 12:06:56 +0200 Subject: [PATCH] Enable support for both new and old perf metrics export APIs Make it possible to use both APIs inside same test and have consistent export results to the Chrome Perf Dashboard and stdout. Bug: b/246095034 Change-Id: I924088a2ddcb04981e56bbeb4544ac317833fb98 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276540 Commit-Queue: Artem Titov Reviewed-by: Mirko Bonadei Reviewed-by: Jeremy Leconte Cr-Commit-Position: refs/heads/main@{#38177} --- test/BUILD.gn | 7 +++++ test/ios/test_support.h | 1 + test/ios/test_support.mm | 57 +++++++++++++++++++++++++++++++--------- test/test_main_lib.cc | 46 +++++++++++++++++++------------- 4 files changed, 80 insertions(+), 31 deletions(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index 242a8b21fa..01539d5d0a 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -331,6 +331,11 @@ if (is_ios) { ] deps = [ ":perf_test", + "../api/test/metrics:chrome_perf_dashboard_metrics_exporter", + "../api/test/metrics:global_metrics_logger_and_exporter", + "../api/test/metrics:metrics_exporter", + "../api/test/metrics:print_result_proxy_metrics_exporter", + "../api/test/metrics:stdout_metrics_exporter", "../sdk:helpers_objc", ] absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] @@ -509,8 +514,10 @@ if (rtc_include_tests && !build_with_chromium) { ":resources_dir_flag", ":test_flags", ":test_support", + "../api/test/metrics:chrome_perf_dashboard_metrics_exporter", "../api/test/metrics:global_metrics_logger_and_exporter", "../api/test/metrics:metrics_exporter", + "../api/test/metrics:print_result_proxy_metrics_exporter", "../api/test/metrics:stdout_metrics_exporter", "../rtc_base", "../rtc_base:checks", diff --git a/test/ios/test_support.h b/test/ios/test_support.h index cd8d2a8103..2699923e09 100644 --- a/test/ios/test_support.h +++ b/test/ios/test_support.h @@ -26,6 +26,7 @@ void InitTestSuite(int (*test_suite)(void), int argc, char* argv[], bool save_chartjson_result, + bool export_perf_results_new_api, absl::optional> metrics_to_plot); // Returns true if unittests should be run by the XCTest runnner. diff --git a/test/ios/test_support.mm b/test/ios/test_support.mm index 24cbcc7939..d51e5a1ba5 100644 --- a/test/ios/test_support.mm +++ b/test/ios/test_support.mm @@ -10,6 +10,11 @@ #import +#include "api/test/metrics/chrome_perf_dashboard_metrics_exporter.h" +#include "api/test/metrics/global_metrics_logger_and_exporter.h" +#include "api/test/metrics/metrics_exporter.h" +#include "api/test/metrics/print_result_proxy_metrics_exporter.h" +#include "api/test/metrics/stdout_metrics_exporter.h" #include "test/ios/coverage_util_ios.h" #include "test/ios/google_test_runner_delegate.h" #include "test/ios/test_support.h" @@ -38,6 +43,7 @@ static int (*g_test_suite)(void) = NULL; static int g_argc; static char **g_argv; static bool g_write_perf_output; +static bool g_export_perf_results_new_api; static absl::optional g_is_xctest; static absl::optional> g_metrics_to_plot; @@ -87,23 +93,46 @@ static absl::optional> g_metrics_to_plot; - (int)runGoogleTests { rtc::test::ConfigureCoverageReportPath(); - int exitStatus = g_test_suite(); + std::vector> exporters; + if (g_export_perf_results_new_api) { + exporters.push_back(std::make_unique()); + if (g_write_perf_output) { + // Stores data into a proto file under the app's document directory. + NSString *fileName = @"perftest-output.pb"; + NSArray *outputDirectories = + NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + if ([outputDirectories count] != 0) { + NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName]; - if (g_write_perf_output) { - // Stores data into a proto file under the app's document directory. - NSString *fileName = @"perftest-output.pb"; - NSArray *outputDirectories = - NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - if ([outputDirectories count] != 0) { - NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName]; - - if (!webrtc::test::WritePerfResults([NSString stdStringForString:outputPath])) { - return 1; + exporters.push_back(std::make_unique( + [NSString stdStringForString:outputPath])); } } + } else { + exporters.push_back(std::make_unique()); } - if (g_metrics_to_plot) { - webrtc::test::PrintPlottableResults(*g_metrics_to_plot); + webrtc::test::SetupGlobalMetricsLoggerAndExporter(std::move(exporters)); + + int exitStatus = g_test_suite(); + + webrtc::test::ExportAndDestroyGlobalMetricsLoggerAndExporter(); + if (!g_export_perf_results_new_api) { + if (g_write_perf_output) { + // Stores data into a proto file under the app's document directory. + NSString *fileName = @"perftest-output.pb"; + NSArray *outputDirectories = + NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + if ([outputDirectories count] != 0) { + NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName]; + + if (!webrtc::test::WritePerfResults([NSString stdStringForString:outputPath])) { + return 1; + } + } + } + if (g_metrics_to_plot) { + webrtc::test::PrintPlottableResults(*g_metrics_to_plot); + } } return exitStatus; @@ -139,11 +168,13 @@ void InitTestSuite(int (*test_suite)(void), int argc, char *argv[], bool write_perf_output, + bool export_perf_results_new_api, absl::optional> metrics_to_plot) { g_test_suite = test_suite; g_argc = argc; g_argv = argv; g_write_perf_output = write_perf_output; + g_export_perf_results_new_api = export_perf_results_new_api; g_metrics_to_plot = std::move(metrics_to_plot); } diff --git a/test/test_main_lib.cc b/test/test_main_lib.cc index 183ff9df21..0c5a998898 100644 --- a/test/test_main_lib.cc +++ b/test/test_main_lib.cc @@ -19,8 +19,10 @@ #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/types/optional.h" +#include "api/test/metrics/chrome_perf_dashboard_metrics_exporter.h" #include "api/test/metrics/global_metrics_logger_and_exporter.h" #include "api/test/metrics/metrics_exporter.h" +#include "api/test/metrics/print_result_proxy_metrics_exporter.h" #include "api/test/metrics/stdout_metrics_exporter.h" #include "rtc_base/checks.h" #include "rtc_base/event_tracer.h" @@ -110,12 +112,6 @@ class TestMainImpl : public TestMain { rtc::LogMessage::SetLogToStderr(absl::GetFlag(FLAGS_logs) || absl::GetFlag(FLAGS_verbose)); - if (absl::GetFlag(FLAGS_export_perf_results_new_api)) { - std::vector> exporters; - exporters.push_back(std::make_unique()); - test::SetupGlobalMetricsLoggerAndExporter(std::move(exporters)); - } - // InitFieldTrialsFromString stores the char*, so the char array must // outlive the application. field_trials_ = absl::GetFlag(FLAGS_force_fieldtrials); @@ -156,25 +152,39 @@ class TestMainImpl : public TestMain { #if defined(WEBRTC_IOS) rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv, absl::GetFlag(FLAGS_write_perf_output_on_ios), + absl::GetFlag(FLAGS_export_perf_results_new_api), metrics_to_plot); rtc::test::RunTestsFromIOSApp(); int exit_code = 0; #else + std::vector> exporters; + if (absl::GetFlag(FLAGS_export_perf_results_new_api)) { + exporters.push_back(std::make_unique()); + if (!absl::GetFlag(FLAGS_isolated_script_test_perf_output).empty()) { + exporters.push_back( + std::make_unique( + absl::GetFlag(FLAGS_isolated_script_test_perf_output))); + } + } else { + exporters.push_back( + std::make_unique()); + } + test::SetupGlobalMetricsLoggerAndExporter(std::move(exporters)); + int exit_code = RUN_ALL_TESTS(); - std::string perf_output_file = - absl::GetFlag(FLAGS_isolated_script_test_perf_output); - if (!perf_output_file.empty()) { - if (!webrtc::test::WritePerfResults(perf_output_file)) { - return 1; + test::ExportAndDestroyGlobalMetricsLoggerAndExporter(); + if (!absl::GetFlag(FLAGS_export_perf_results_new_api)) { + std::string perf_output_file = + absl::GetFlag(FLAGS_isolated_script_test_perf_output); + if (!perf_output_file.empty()) { + if (!webrtc::test::WritePerfResults(perf_output_file)) { + return 1; + } + } + if (metrics_to_plot) { + webrtc::test::PrintPlottableResults(*metrics_to_plot); } - } - if (metrics_to_plot) { - webrtc::test::PrintPlottableResults(*metrics_to_plot); - } - - if (absl::GetFlag(FLAGS_export_perf_results_new_api)) { - test::ExportAndDestroyGlobalMetricsLoggerAndExporter(); } std::string result_filename =