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 <titovartem@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Jeremy Leconte <jleconte@google.com> Cr-Commit-Position: refs/heads/main@{#38177}
This commit is contained in:
parent
b625101da8
commit
f5808fc4c5
@ -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",
|
||||
|
||||
@ -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<std::vector<std::string>> metrics_to_plot);
|
||||
|
||||
// Returns true if unittests should be run by the XCTest runnner.
|
||||
|
||||
@ -10,6 +10,11 @@
|
||||
|
||||
#import <UIKit/UIKit.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 "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<bool> g_is_xctest;
|
||||
static absl::optional<std::vector<std::string>> g_metrics_to_plot;
|
||||
|
||||
@ -87,23 +93,46 @@ static absl::optional<std::vector<std::string>> g_metrics_to_plot;
|
||||
- (int)runGoogleTests {
|
||||
rtc::test::ConfigureCoverageReportPath();
|
||||
|
||||
int exitStatus = g_test_suite();
|
||||
std::vector<std::unique_ptr<webrtc::test::MetricsExporter>> exporters;
|
||||
if (g_export_perf_results_new_api) {
|
||||
exporters.push_back(std::make_unique<webrtc::test::StdoutMetricsExporter>());
|
||||
if (g_write_perf_output) {
|
||||
// Stores data into a proto file under the app's document directory.
|
||||
NSString *fileName = @"perftest-output.pb";
|
||||
NSArray<NSString *> *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<NSString *> *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<webrtc::test::ChromePerfDashboardMetricsExporter>(
|
||||
[NSString stdStringForString:outputPath]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
exporters.push_back(std::make_unique<webrtc::test::PrintResultProxyMetricsExporter>());
|
||||
}
|
||||
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<NSString *> *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<std::vector<std::string>> 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);
|
||||
}
|
||||
|
||||
|
||||
@ -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<std::unique_ptr<test::MetricsExporter>> exporters;
|
||||
exporters.push_back(std::make_unique<test::StdoutMetricsExporter>());
|
||||
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<std::unique_ptr<test::MetricsExporter>> exporters;
|
||||
if (absl::GetFlag(FLAGS_export_perf_results_new_api)) {
|
||||
exporters.push_back(std::make_unique<test::StdoutMetricsExporter>());
|
||||
if (!absl::GetFlag(FLAGS_isolated_script_test_perf_output).empty()) {
|
||||
exporters.push_back(
|
||||
std::make_unique<test::ChromePerfDashboardMetricsExporter>(
|
||||
absl::GetFlag(FLAGS_isolated_script_test_perf_output)));
|
||||
}
|
||||
} else {
|
||||
exporters.push_back(
|
||||
std::make_unique<test::PrintResultProxyMetricsExporter>());
|
||||
}
|
||||
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 =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user