[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.h b/libartbase/base/metrics.h
index d5a4873..0c0227a 100644
--- a/libartbase/base/metrics.h
+++ b/libartbase/base/metrics.h
@@ -202,6 +202,25 @@
   static_assert(std::atomic<value_t>::is_always_lock_free);
 };
 
+// A backend that writes metrics in a human-readable format to an std::ostream.
+class StreamBackend : public MetricsBackend {
+ public:
+  explicit StreamBackend(std::ostream& os);
+
+  void BeginSession(const SessionData& session_data) override;
+  void EndSession() override;
+
+  void ReportCounter(DatumId counter_type, uint64_t value) override;
+
+  void ReportHistogram(DatumId histogram_type,
+                       int64_t low_value,
+                       int64_t high_value,
+                       const std::vector<uint32_t>& buckets) override;
+
+ private:
+  std::ostream& os_;
+};
+
 /**
  * AutoTimer simplifies time-based metrics collection.
  *
@@ -279,6 +298,7 @@
   ArtMetrics();
 
   void ReportAllMetrics(MetricsBackend* backend) const;
+  void DumpForSigQuit(std::ostream& os) const;
 
 #define ART_COUNTER(name)                                       \
   MetricsCounter<DatumId::k##name>* name() { return &name##_; } \