[metrics] Dump ArtMetrics on SIGQUIT
ART now writes a current snapshot of its internal metrics in response to
a SIGQUIT.
Example output:
```
*** ART internal metrics ***
ClassVerificationTotalTime: count = 863833
JitMethodCompileTime: range = 0...1000000, buckets: 244,5,1,0,1,0,0,0,0,1,0,0,0,0,0
*** Done dumping ART internal metrics ***
```
This includes a new StreamBackend, which is used to write ART metrics to
an output stream in a human readable format.
Bug: 170149255
Test: m test-art-host-gtest-art_libartbase_tests
Change-Id: Iaf8bcee5a4993e70ac4e36940591a734fe1a6697
diff --git a/libartbase/base/metrics_test.cc b/libartbase/base/metrics_test.cc
index 20ac92c..f568ea0 100644
--- a/libartbase/base/metrics_test.cc
+++ b/libartbase/base/metrics_test.cc
@@ -205,6 +205,27 @@
EXPECT_GT(GetBuckets(test_histogram)[0], 0u);
}
+// Makes sure all defined metrics are included when dumping through StreamBackend.
+TEST_F(MetricsTest, StreamBackendDumpAllMetrics) {
+ ArtMetrics metrics;
+ std::stringstream os;
+ StreamBackend backend(os);
+
+ metrics.ReportAllMetrics(&backend);
+
+ // Make sure the resulting string lists all the counters.
+#define COUNTER(name) \
+ EXPECT_NE(os.str().find(DatumName(DatumId::k##name)), std::string::npos)
+ ART_COUNTERS(COUNTER);
+#undef COUNTER
+
+ // Make sure the resulting string lists all the histograms.
+#define HISTOGRAM(name, num_buckets, minimum_value, maximum_value) \
+ EXPECT_NE(os.str().find(DatumName(DatumId::k##name)), std::string::npos)
+ ART_HISTOGRAMS(HISTOGRAM);
+#undef HISTOGRAM
+}
+
} // namespace metrics
} // namespace art