[metrics] Enable periodic reporting for system server

This enables reporting from system server once an hour.

The reason is that system server is long-running, so startup metrics,
which are all that are enabled by default otherwise, are not as
meaningful. Note that the reporting period can still be overridden by
a command line argument.

Testing instructions:

    adb shell setprop dalvik.vm.extra-opts -Xwrite-metrics-to-log
    adb logcat -e "ART internal metrics"

    Observe periodic system server reports.

Bug: 170149255
Test: manual (see above)
Test: ./test.py --run-test --host -t 911
Change-Id: I71775e454c6fd07c4312e3df9ae8082fa497ea93
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 3c187d3..7010c17 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1070,6 +1070,14 @@
   heap_->ResetGcPerformanceInfo();
 
   if (metrics_reporter_ != nullptr) {
+    if (IsSystemServer() && !metrics_reporter_->IsPeriodicReportingEnabled()) {
+      // For system server, we don't get startup metrics, so make sure we have periodic reporting
+      // enabled.
+      //
+      // Note that this does not override the command line argument if one is given.
+      metrics_reporter_->SetReportingPeriod(kOneHourInSeconds);
+    }
+
     metrics::SessionData session_data{metrics::SessionData::CreateDefault()};
     session_data.session_id = GetRandomNumber<int64_t>(0, std::numeric_limits<int64_t>::max());
     // TODO: set session_data.compilation_reason and session_data.compiler_filter
@@ -1846,9 +1854,7 @@
 
 void Runtime::InitMetrics(const RuntimeArgumentMap& runtime_options) {
   auto metrics_config = metrics::ReportingConfig::FromRuntimeArguments(runtime_options);
-  if (metrics_config.ReportingEnabled()) {
-    metrics_reporter_ = metrics::MetricsReporter::Create(metrics_config, this);
-  }
+  metrics_reporter_ = metrics::MetricsReporter::Create(metrics_config, this);
 }
 
 bool Runtime::EnsurePluginLoaded(const char* plugin_name, std::string* error_msg) {