diff options
Diffstat (limited to 'runtime/metrics/metrics.cc')
-rw-r--r-- | runtime/metrics/metrics.cc | 72 |
1 files changed, 8 insertions, 64 deletions
diff --git a/runtime/metrics/metrics.cc b/runtime/metrics/metrics.cc index 0f8bacf679..81ae2b4dab 100644 --- a/runtime/metrics/metrics.cc +++ b/runtime/metrics/metrics.cc @@ -18,8 +18,6 @@ #include "android-base/logging.h" #include "base/macros.h" -#include "runtime.h" -#include "thread-current-inl.h" #pragma clang diagnostic push #pragma clang diagnostic error "-Wconversion" @@ -113,73 +111,19 @@ void StreamBackend::ReportHistogram(DatumId histogram_type, } } -std::unique_ptr<MetricsReporter> MetricsReporter::Create(ReportingConfig config, Runtime* runtime) { +std::unique_ptr<MetricsReporter> MetricsReporter::Create(ReportingConfig config, + const ArtMetrics* metrics) { std::unique_ptr<MetricsBackend> backend; // We can't use std::make_unique here because the MetricsReporter constructor is private. - return std::unique_ptr<MetricsReporter>{new MetricsReporter{config, runtime}}; + return std::unique_ptr<MetricsReporter>{new MetricsReporter{config, metrics}}; } -MetricsReporter::MetricsReporter(ReportingConfig config, Runtime* runtime) - : config_{config}, runtime_{runtime} {} +MetricsReporter::MetricsReporter(ReportingConfig config, const ArtMetrics* metrics) + : config_{config}, metrics_{metrics} {} -MetricsReporter::~MetricsReporter() { StopBackgroundThreadIfRunning(); } - -void MetricsReporter::StartBackgroundThreadIfNeeded() { - if (config_.BackgroundReportingEnabled()) { - CHECK(!thread_.has_value()); - - thread_.emplace(&MetricsReporter::BackgroundThreadRun, this); - } -} - -void MetricsReporter::StopBackgroundThreadIfRunning() { - if (thread_.has_value()) { - messages_.SendMessage(ShutdownRequestedMessage{}); - thread_->join(); - } - // Do one final metrics report, if enabled. - if (config_.report_metrics_on_shutdown) { - ReportMetrics(); - } -} - -void MetricsReporter::BackgroundThreadRun() { - runtime_->AttachCurrentThread("Metrics Background Reporting Thread", - /*as_daemon=*/true, - runtime_->GetSystemThreadGroup(), - /*create_peer=*/true); - LOG_STREAM(DEBUG) << "Metrics reporting thread started"; - bool running = true; - - ResetTimeoutIfNeeded(); - - while (running) { - messages_.SwitchReceive( - [&]([[maybe_unused]] ShutdownRequestedMessage message) { - LOG_STREAM(DEBUG) << "Shutdown request received"; - running = false; - }, - [&]([[maybe_unused]] TimeoutExpiredMessage message) { - LOG_STREAM(DEBUG) << "Timer expired, reporting metrics"; - - ReportMetrics(); - - ResetTimeoutIfNeeded(); - }); - } - - runtime_->DetachCurrentThread(); - LOG_STREAM(DEBUG) << "Metrics reporting thread terminating"; -} - -void MetricsReporter::ResetTimeoutIfNeeded() { - if (config_.periodic_report_seconds.has_value()) { - messages_.SetTimeout(SecondsToMs(config_.periodic_report_seconds.value())); - } -} - -void MetricsReporter::ReportMetrics() const { +MetricsReporter::~MetricsReporter() { + // If we are configured to report metrics, do one final report at the end. if (config_.dump_to_logcat) { LOG_STREAM(INFO) << "\n*** ART internal metrics ***\n\n"; // LOG_STREAM(INFO) destroys the stream at the end of the statement, which makes it tricky pass @@ -188,7 +132,7 @@ void MetricsReporter::ReportMetrics() const { // dump the metrics. [this](std::ostream& os) { StreamBackend backend{os}; - runtime_->GetMetrics()->ReportAllMetrics(&backend); + metrics_->ReportAllMetrics(&backend); }(LOG_STREAM(INFO)); LOG_STREAM(INFO) << "\n*** Done dumping ART internal metrics ***\n"; } |