Preload perfetto_hprof library in Zygote.
This is to reduce the startup time for profileable or debuggable apps.
Test: flash, run benchmarks
Bug: 147667830
Change-Id: Iee5d60664cad5b6e445c2291d6de07f2bb555017
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index b534fd2..0420e0b 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1788,6 +1788,14 @@
callbacks_->NextRuntimePhase(RuntimePhaseCallback::RuntimePhase::kInitialAgents);
}
+ if (IsZygote() && IsPerfettoHprofEnabled()) {
+ constexpr const char* plugin_name = kIsDebugBuild ?
+ "libperfetto_hprofd.so" : "libperfetto_hprof.so";
+ // Load eagerly in Zygote to improve app startup times. This will make
+ // subsequent dlopens for the library no-ops.
+ dlopen(plugin_name, RTLD_NOW | RTLD_LOCAL);
+ }
+
VLOG(startup) << "Runtime::Init exiting";
// Set OnlyUseSystemOatFiles only after boot classpath has been set up.