summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libartbase/base/flags.h3
-rw-r--r--runtime/runtime.cc17
-rw-r--r--runtime/runtime.h2
-rw-r--r--runtime/runtime_test.cc28
-rw-r--r--test/2232-write-metrics-to-log/run.py5
-rw-r--r--test/2233-metrics-background-thread/run.py7
6 files changed, 54 insertions, 8 deletions
diff --git a/libartbase/base/flags.h b/libartbase/base/flags.h
index 4734a60568..cec6c584ff 100644
--- a/libartbase/base/flags.h
+++ b/libartbase/base/flags.h
@@ -311,6 +311,9 @@ struct Flags {
// to logcat will be in human-readable text format.
// Supported values are "text" and "xml".
Flag<std::string> MetricsFormat{"metrics.format", "text", FlagType::kCmdlineOnly};
+
+ // Whether or not to force the metrics initialization.
+ Flag<bool> MetricsForceEnable{"metrics.force-enable", false, FlagType::kCmdlineOnly};
};
// This is the actual instance of all the flags.
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 989763022f..53c1cb152f 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1278,7 +1278,7 @@ void Runtime::InitNonZygoteOrPostFork(
heap_->ResetGcPerformanceInfo();
GetMetrics()->Reset();
- if (metrics_reporter_ != nullptr) {
+ if (AreMetricsInitialized()) {
// Now that we know if we are an app or system server, reload the metrics reporter config
// in case there are any difference.
metrics::ReportingConfig metrics_config =
@@ -2112,7 +2112,12 @@ bool Runtime::Init(RuntimeArgumentMap&& runtime_options_in) {
// Class-roots are setup, we can now finish initializing the JniIdManager.
GetJniIdManager()->Init(self);
- InitMetrics();
+ // Initialize metrics only for the Zygote process or
+ // if explicitly enabled via command line argument.
+ if (IsZygote() || gFlags.MetricsForceEnable.GetValue()) {
+ LOG(INFO) << "Initializing ART runtime metrics";
+ InitMetrics();
+ }
// Runtime initialization is largely done now.
// We load plugins first since that can modify the runtime state slightly.
@@ -2213,7 +2218,7 @@ void Runtime::InitMetrics() {
}
void Runtime::RequestMetricsReport(bool synchronous) {
- if (metrics_reporter_) {
+ if (AreMetricsInitialized()) {
metrics_reporter_->RequestMetricsReport(synchronous);
}
}
@@ -2871,7 +2876,7 @@ void Runtime::RegisterAppInfo(const std::string& package_name,
ref_profile_filename,
AppInfo::FromVMRuntimeConstants(code_type));
- if (metrics_reporter_ != nullptr) {
+ if (AreMetricsInitialized()) {
metrics_reporter_->NotifyAppInfoUpdated(&app_info_);
}
@@ -3308,14 +3313,14 @@ bool Runtime::NotifyStartupCompleted() {
ProfileSaver::NotifyStartupCompleted();
- if (metrics_reporter_ != nullptr) {
+ if (AreMetricsInitialized()) {
metrics_reporter_->NotifyStartupCompleted();
}
return true;
}
void Runtime::NotifyDexFileLoaded() {
- if (metrics_reporter_ != nullptr) {
+ if (AreMetricsInitialized()) {
metrics_reporter_->NotifyAppInfoUpdated(&app_info_);
}
}
diff --git a/runtime/runtime.h b/runtime/runtime.h
index afb8ebd3c0..64d85b6464 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -1132,6 +1132,8 @@ class Runtime {
}
}
+ bool AreMetricsInitialized() const { return metrics_reporter_ != nullptr; }
+
private:
static void InitPlatformSignalHandlers();
diff --git a/runtime/runtime_test.cc b/runtime/runtime_test.cc
index cd0c862d82..1faecf36a8 100644
--- a/runtime/runtime_test.cc
+++ b/runtime/runtime_test.cc
@@ -109,4 +109,32 @@ TEST_F(RuntimeTest, ElfAlignmentMismatch) {
EXPECT_EQ(kElfSegmentAlignment, elf_file->GetElfSegmentAlignmentFromFile());
}
+class RuntimeInitMetricsDefaultTest : public CommonRuntimeTest {};
+
+TEST_F(RuntimeInitMetricsDefaultTest, MetricsAreNotInitialized) {
+ ASSERT_FALSE(runtime_->AreMetricsInitialized());
+}
+
+class RuntimeInitMetricsZygoteTest : public CommonRuntimeTest {
+ void SetUpRuntimeOptions(RuntimeOptions* options) override {
+ CommonRuntimeTest::SetUpRuntimeOptions(options);
+ options->emplace_back(std::make_pair("-Xzygote", nullptr));
+ }
+};
+
+TEST_F(RuntimeInitMetricsZygoteTest, MetricsAreInitialized) {
+ ASSERT_TRUE(runtime_->AreMetricsInitialized());
+}
+
+class RuntimeInitMetricsForceEnableTest : public CommonRuntimeTest {
+ void SetUpRuntimeOptions(RuntimeOptions* options) override {
+ CommonRuntimeTest::SetUpRuntimeOptions(options);
+ options->emplace_back(std::make_pair("-Xmetrics-force-enable:true", nullptr));
+ }
+};
+
+TEST_F(RuntimeInitMetricsForceEnableTest, MetricsAreInitialized) {
+ ASSERT_TRUE(runtime_->AreMetricsInitialized());
+}
+
} // namespace art
diff --git a/test/2232-write-metrics-to-log/run.py b/test/2232-write-metrics-to-log/run.py
index 89fe040087..167c2bbc17 100644
--- a/test/2232-write-metrics-to-log/run.py
+++ b/test/2232-write-metrics-to-log/run.py
@@ -21,7 +21,10 @@ def run(ctx, args):
android_log_tags="*:i",
diff_min_log_tag="i",
runtime_option=[
- "-Xmetrics-write-to-logcat:true", "-Xmetrics-reporting-mods:100"
+ "-Xmetrics-force-enable:true",
+ "-Xmetrics-write-to-statsd:false",
+ "-Xmetrics-write-to-logcat:true",
+ "-Xmetrics-reporting-mods:100",
])
# Check that one of the metrics appears in stderr.
diff --git a/test/2233-metrics-background-thread/run.py b/test/2233-metrics-background-thread/run.py
index e0d86ac13d..6b63488292 100644
--- a/test/2233-metrics-background-thread/run.py
+++ b/test/2233-metrics-background-thread/run.py
@@ -18,7 +18,12 @@ def run(ctx, args):
args,
android_log_tags="*:d",
diff_min_log_tag="d",
- runtime_option=["-Xmetrics-reporting-mods:100",]
+ runtime_option=[
+ "-Xmetrics-force-enable:true",
+ "-Xmetrics-write-to-statsd:false",
+ "-Xmetrics-write-to-logcat:true",
+ "-Xmetrics-reporting-mods:100",
+ ]
)
# Check that log messages from the metrics reporting thread appear in stderr.