From 51a9283984b05511bd98f9bcbd1f2f18900239cc Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Mon, 7 Dec 2020 15:07:00 -0800 Subject: [metrics] Add file output support Adds a new command line option, -Xwrite-metrics-to-file=_, which specifies a file for writing metrics to. This can be used in conjunction with -Xwrite-metrics-to-log, which will cause the output to go to both logcat and the file. Writing metrics to a file can be helpful for testing or benchmarking environments. Access to the file is protected using advisory locking, so it is safe to have multiple processes write metrics to the same file. Test: test/run-test --host test/2234-write-metrics-to-file Bug: 175025360, 170149255 Change-Id: I83a4f959cbb96847dc71188035c050a73b915064 --- runtime/metrics/metrics.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'runtime/metrics/metrics.h') diff --git a/runtime/metrics/metrics.h b/runtime/metrics/metrics.h index 7156d576e0..a6e395559a 100644 --- a/runtime/metrics/metrics.h +++ b/runtime/metrics/metrics.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -58,6 +59,10 @@ // per metric. namespace art { + +class Runtime; +struct RuntimeArgumentMap; + namespace metrics { /** @@ -340,9 +345,16 @@ class ArtMetrics { std::string DatumName(DatumId datum); struct ReportingConfig { - bool dump_to_logcat; - // TODO(eholk): this will grow to support other configurations, such as logging to a file, or - // statsd. There will also be options for reporting after a period of time, or at certain events. + static ReportingConfig FromRuntimeArguments(const RuntimeArgumentMap& args); + + // Causes metrics to be written to the log, which makes them show up in logcat. + bool dump_to_logcat{false}; + + // If set, provides a file name to enable metrics logging to a file. + std::optional dump_to_file; + + // Returns whether any options are set that enables metrics reporting. + constexpr bool ReportingEnabled() const { return dump_to_logcat || dump_to_file.has_value(); } }; // MetricsReporter handles periodically reporting ART metrics. -- cgit v1.2.3-59-g8ed1b