diff options
author | Anwar Ghuloum <anwarg@google.com> | 2014-09-05 14:22:50 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-05 14:22:51 +0000 |
commit | 248b369661f412bfac9b9b117d6911106558c1a0 (patch) | |
tree | 7922d5a0354fb6a91f31d92d55901b5da84dbf83 /core/jni | |
parent | ffd09aed4e31cc52d273ce0280488c38547866b2 (diff) | |
parent | 629dc1801331ce89e8ee0ff7ee5dcde1d7512417 (diff) | |
download | frameworks_base-248b369661f412bfac9b9b117d6911106558c1a0.zip frameworks_base-248b369661f412bfac9b9b117d6911106558c1a0.tar.gz frameworks_base-248b369661f412bfac9b9b117d6911106558c1a0.tar.bz2 |
Merge "Timing Hacks DO NOT MERGE" into lmp-dev
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/com_android_internal_os_Zygote.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index 1f7acec..3d2d471 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -43,6 +43,7 @@ #include <utils/String8.h> #include <selinux/android.h> #include <processgroup/processgroup.h> +#include <inttypes.h> #include "android_runtime/AndroidRuntime.h" #include "JNIHelp.h" @@ -398,6 +399,22 @@ void SetThreadName(const char* thread_name) { } } + // Temporary timing check. +uint64_t MsTime() { + timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000) + now.tv_nsec / UINT64_C(1000000); +} + + +void ckTime(uint64_t start, const char* where) { + uint64_t now = MsTime(); + if ((now-start) > 1000) { + // If we are taking more than a second, log about it. + ALOGW("Slow operation: %"PRIu64" ms in %s", (uint64_t)(now-start), where); + } +} + // Utility routine to fork zygote and specialize the child process. static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray javaGids, jint debug_flags, jobjectArray javaRlimits, @@ -405,7 +422,9 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra jint mount_external, jstring java_se_info, jstring java_se_name, bool is_system_server, jintArray fdsToClose) { + uint64_t start = MsTime(); SetSigChldHandler(); + ckTime(start, "ForkAndSpecializeCommon:SetSigChldHandler"); pid_t pid = fork(); @@ -413,9 +432,12 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra // The child process. gMallocLeakZygoteChild = 1; + // Clean up any descriptors which must be closed immediately DetachDescriptors(env, fdsToClose); + ckTime(start, "ForkAndSpecializeCommon:Fork and detach"); + // Keep capabilities across UID change, unless we're staying root. if (uid != 0) { EnableKeepCapabilities(env); @@ -518,7 +540,10 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra UnsetSigChldHandler(); + ckTime(start, "ForkAndSpecializeCommon:child process setup"); + env->CallStaticVoidMethod(gZygoteClass, gCallPostForkChildHooks, debug_flags); + ckTime(start, "ForkAndSpecializeCommon:PostForkChildHooks returns"); if (env->ExceptionCheck()) { ALOGE("Error calling post fork hooks."); RuntimeAbort(env); |