[metrics] Report metrics at app startup completion

We are particularly interested in metrics collected during app
launch. This causes ART to report metrics when NotifyStartupCompleted
is called.

Note that startup reports are automatically enabled if any metrics
backend is configured.

This CL also fixing a small bug where attaching the thread could fail
if this happens while the runtime is shutting down, leading to a fatal
error when the background thread attempted to detach itself.

Bug: 170149255
Test: adb shell setprop dalvik.vm.extra-opts -Xwrite-metrics-to-log && \
      adb shell stop && adb shell start

      Then launch apps and observe metrics in logcat.

Change-Id: I2f3fc0c61c58db94aa3e2165ed794e1a5652a060
3 files changed