zygote children: propagate profileability to bionic for native heap profiling

go/heapprofd is a native heap profiler for android Q+. Its triggering is
implemented within /bionic/libc. App processes (i.e.  zygote children) are not
considered profileable by default on "user" builds. To opt-in into being
profileable, the app's manifest needs to have the Q+ go/profileable flag set
(or be marked as debuggable, which is its superset).

With this change, if the app is supposed to be profileable, post-fork runtime
init calls into bionic to mark itself as such, and possibly start "from
startup" profiling.

On userdebug, all zygote children are marked profileable via the same
mechanism. System server is also marked profileable on userdebug (and needs a
separate codepath, as it does not have an activity thread).

See go/heapprofd-java-trigger for details on why we're taking this approach.
Context on the profiler itself: go/heapprofd-design.

Test: flashed blueline-userdebug, confirmed that java profiling activates from startup and at runtime.
Test: flashed crosshatch-user, confirmed that no java profiling is enabled by default.
Bug: 120409382
Change-Id: Ia038871acfa6b9cae7b6a81f666aecce4b68a4fc
This commit is contained in:
Ryan Savitski
2018-12-14 16:20:52 +00:00
parent 2e2692d3e4
commit cfdc151d52
5 changed files with 34 additions and 1 deletions

View File

@@ -326,6 +326,11 @@ public final class SystemServer {
*/
private static native void startHidlServices();
/**
* Mark this process' heap as profileable. Only for debug builds.
*/
private static native void initZygoteChildHeapProfiling();
/**
* The main entry point from zygote.
*/
@@ -448,6 +453,11 @@ public final class SystemServer {
// Initialize native services.
System.loadLibrary("android_servers");
// Debug builds - allow heap profiling.
if (Build.IS_DEBUGGABLE) {
initZygoteChildHeapProfiling();
}
// Check whether we failed to shut down last time we tried.
// This call may not return.
performPendingShutdown();