perfetto_hprof: add flag to enable.
Add flag whether to allow loading of the perfetto hprof plugin.
Even with this option set, we will still only actually load the plugin
if we are on a userdebug build or the app is debuggable or profileable.
We do not want to enable this by default because PerfettoHprof does not
work on host, and we do not want to enable it in tests.
Test: flash flame-userdebug. get java heap dump.
Bug: 147667830
Change-Id: If978556dbf44b27828cba47e1fb95084a12838b7
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index 351d5e8..c62caa9 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -389,6 +389,10 @@
.WithType<bool>()
.WithValueMap({{"false", false}, {"true", true}})
.IntoKey(M::VerifierMissingKThrowFatal)
+ .Define("-XX:PerfettoHprof=_")
+ .WithType<bool>()
+ .WithValueMap({{"false", false}, {"true", true}})
+ .IntoKey(M::PerfettoHprof)
.Ignore({
"-ea", "-da", "-enableassertions", "-disableassertions", "--runtime-arg", "-esa",
"-dsa", "-enablesystemassertions", "-disablesystemassertions", "-Xrs", "-Xint:_",
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 5104297..b534fd2 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -296,7 +296,8 @@
process_state_(kProcessStateJankPerceptible),
zygote_no_threads_(false),
verifier_logging_threshold_ms_(100),
- verifier_missing_kthrow_fatal_(false) {
+ verifier_missing_kthrow_fatal_(false),
+ perfetto_hprof_enabled_(false) {
static_assert(Runtime::kCalleeSaveSize ==
static_cast<uint32_t>(CalleeSaveType::kLastCalleeSaveType), "Unexpected size");
CheckConstants();
@@ -1062,8 +1063,9 @@
StartSignalCatcher();
ScopedObjectAccess soa(Thread::Current());
- if (Dbg::IsJdwpAllowed() || IsProfileableFromShell() || IsJavaDebuggable() ||
- Runtime::Current()->IsSystemServer()) {
+ if (IsPerfettoHprofEnabled() &&
+ (Dbg::IsJdwpAllowed() || IsProfileableFromShell() || IsJavaDebuggable() ||
+ Runtime::Current()->IsSystemServer())) {
std::string err;
ScopedTrace tr("perfetto_hprof init.");
ScopedThreadSuspension sts(Thread::Current(), ThreadState::kNative);
@@ -1199,6 +1201,7 @@
MemMap::Init();
verifier_missing_kthrow_fatal_ = runtime_options.GetOrDefault(Opt::VerifierMissingKThrowFatal);
+ perfetto_hprof_enabled_ = runtime_options.GetOrDefault(Opt::PerfettoHprof);
// Try to reserve a dedicated fault page. This is allocated for clobbered registers and sentinels.
// If we cannot reserve it, log a warning.
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 655f05f..822c0ac 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -976,6 +976,10 @@
return verifier_missing_kthrow_fatal_;
}
+ bool IsPerfettoHprofEnabled() const {
+ return perfetto_hprof_enabled_;
+ }
+
// Return true if we should load oat files as executable or not.
bool GetOatFilesExecutable() const;
@@ -1336,6 +1340,7 @@
gc::space::ImageSpaceLoadingOrder::kSystemFirst;
bool verifier_missing_kthrow_fatal_;
+ bool perfetto_hprof_enabled_;
// Note: See comments on GetFaultMessage.
friend std::string GetFaultMessageForAbortLogging();
diff --git a/runtime/runtime_options.def b/runtime/runtime_options.def
index 877a5a0..5707a33 100644
--- a/runtime/runtime_options.def
+++ b/runtime/runtime_options.def
@@ -173,4 +173,17 @@
RUNTIME_OPTIONS_KEY (bool, FastClassNotFoundException, true)
RUNTIME_OPTIONS_KEY (bool, VerifierMissingKThrowFatal, true)
+// Whether to allow loading of the perfetto hprof plugin.
+// Even with this option set, we will still only actually load the plugin
+// if we are on a userdebug build or the app is debuggable or profileable.
+//
+// We do not want to enable this by default because PerfettoHprof does not
+// work on host, and we do not want to enable it in tests.
+//
+// Switching this on adds ~500us to the startup on userdebug builds, or for
+// profileable / debuggable apps.
+//
+// This is set to true in frameworks/base/core/jni/AndroidRuntime.cpp.
+RUNTIME_OPTIONS_KEY (bool, PerfettoHprof, false)
+
#undef RUNTIME_OPTIONS_KEY