diff options
author | lizeb <lizeb@chromium.org> | 2016-01-08 09:23:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-08 17:24:22 +0000 |
commit | e38b9a18fc67c8107f4aefe97311f593c43e43fa (patch) | |
tree | c64984cab3473ffe7328bc7d15537817471b59a8 /base | |
parent | 83c66066dafe22d7a723175938459f4440b044c2 (diff) | |
download | chromium_src-e38b9a18fc67c8107f4aefe97311f593c43e43fa.zip chromium_src-e38b9a18fc67c8107f4aefe97311f593c43e43fa.tar.gz chromium_src-e38b9a18fc67c8107f4aefe97311f593c43e43fa.tar.bz2 |
android: Properly record the "native library residency" histogram.
Histograms are silently dropped when recorded before the initialization
of StatisticsRecorder. This means that the cold start histogram is
usually dropped as well (since StatisticsRecorder is initialized in
another thread around the same time).
Fix this by recording the histogram much later.
Also record this histogram for warm starts as well.
BUG=568115
Review URL: https://codereview.chromium.org/1568483002
Cr-Commit-Position: refs/heads/master@{#368358}
Diffstat (limited to 'base')
4 files changed, 47 insertions, 27 deletions
diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java index b5186942..5a6153a 100644 --- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java +++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java @@ -170,16 +170,30 @@ public class LibraryLoader { * detrimental to the startup time. */ public void asyncPrefetchLibrariesToMemory() { - if (!mPrefetchLibraryHasBeenCalled.compareAndSet(false, true)) return; + final boolean coldStart = mPrefetchLibraryHasBeenCalled.compareAndSet(false, true); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { TraceEvent.begin("LibraryLoader.asyncPrefetchLibrariesToMemory"); - boolean success = nativeForkAndPrefetchNativeLibrary(true); - if (!success) { - Log.w(TAG, "Forking a process to prefetch the native library failed."); + int percentage = nativePercentageOfResidentNativeLibraryCode(); + boolean success = false; + if (coldStart) { + success = nativeForkAndPrefetchNativeLibrary(); + if (!success) { + Log.w(TAG, "Forking a process to prefetch the native library failed."); + } + } + // As this runs in a background thread, it can be called before histograms are + // initialized. In this instance, histograms are dropped. + RecordHistogram.initialize(); + if (coldStart) { + RecordHistogram.recordBooleanHistogram("LibraryLoader.PrefetchStatus", success); + } + if (percentage != -1) { + String histogram = "LibraryLoader.PercentageOfResidentCodeBeforePrefetch" + + (coldStart ? "_ColdStartup" : "_WarmStartup"); + RecordHistogram.recordEnumeratedHistogram(histogram, percentage, 101); } - RecordHistogram.recordBooleanHistogram("LibraryLoader.PrefetchStatus", success); TraceEvent.end("LibraryLoader.asyncPrefetchLibrariesToMemory"); return null; } @@ -451,5 +465,9 @@ public class LibraryLoader { // Finds the ranges corresponding to the native library pages, forks a new // process to prefetch these pages and waits for it. The new process then // terminates. This is blocking. - private static native boolean nativeForkAndPrefetchNativeLibrary(boolean isColdStart); + private static native boolean nativeForkAndPrefetchNativeLibrary(); + + // Returns the percentage of the native library code page that are currently reseident in + // memory. + private static native int nativePercentageOfResidentNativeLibraryCode(); } diff --git a/base/android/library_loader/library_loader_hooks.cc b/base/android/library_loader/library_loader_hooks.cc index 240c809..bbc9935 100644 --- a/base/android/library_loader/library_loader_hooks.cc +++ b/base/android/library_loader/library_loader_hooks.cc @@ -144,9 +144,14 @@ void LibraryLoaderExitHook() { static jboolean ForkAndPrefetchNativeLibrary( JNIEnv* env, - const JavaParamRef<jclass>& clazz, - jboolean is_cold_start) { - return NativeLibraryPrefetcher::ForkAndPrefetchNativeLibrary(is_cold_start); + const JavaParamRef<jclass>& clazz) { + return NativeLibraryPrefetcher::ForkAndPrefetchNativeLibrary(); +} + +static jint PercentageOfResidentNativeLibraryCode( + JNIEnv* env, + const JavaParamRef<jclass>& clazz) { + return NativeLibraryPrefetcher::PercentageOfResidentNativeLibraryCode(); } bool RegisterLibraryLoaderEntryHook(JNIEnv* env) { diff --git a/base/android/library_loader/library_prefetcher.cc b/base/android/library_loader/library_prefetcher.cc index f62ed6a..c7ec990f0 100644 --- a/base/android/library_loader/library_prefetcher.cc +++ b/base/android/library_loader/library_prefetcher.cc @@ -14,7 +14,6 @@ #include <vector> #include "base/macros.h" -#include "base/metrics/histogram_macros.h" #include "base/posix/eintr_wrapper.h" #include "base/strings/string_util.h" @@ -121,7 +120,7 @@ bool NativeLibraryPrefetcher::FindRanges(std::vector<AddressRange>* ranges) { } // static -bool NativeLibraryPrefetcher::ForkAndPrefetchNativeLibrary(bool is_cold_start) { +bool NativeLibraryPrefetcher::ForkAndPrefetchNativeLibrary() { // Avoid forking with cygprofile instrumentation because the latter performs // memory allocations. #if defined(CYGPROFILE_INSTRUMENTATION) @@ -137,19 +136,6 @@ bool NativeLibraryPrefetcher::ForkAndPrefetchNativeLibrary(bool is_cold_start) { if (!FindRanges(&ranges)) return false; - int percentage = PercentageOfResidentCode(ranges); - if (percentage != -1) { - if (is_cold_start) { - UMA_HISTOGRAM_PERCENTAGE( - "LibraryLoader.PercentageOfResidentCodeBeforePrefetch_ColdStartup", - percentage); - } else { - UMA_HISTOGRAM_PERCENTAGE( - "LibraryLoader.PercentageOfResidentCodeBeforePrefetch_WarmStartup", - percentage); - } - } - pid_t pid = fork(); if (pid == 0) { setpriority(PRIO_PROCESS, 0, kBackgroundPriority); @@ -198,5 +184,13 @@ int NativeLibraryPrefetcher::PercentageOfResidentCode( return static_cast<int>((100 * resident_pages) / total_pages); } +// static +int NativeLibraryPrefetcher::PercentageOfResidentNativeLibraryCode() { + std::vector<AddressRange> ranges; + if (!FindRanges(&ranges)) + return -1; + return PercentageOfResidentCode(ranges); +} + } // namespace android } // namespace base diff --git a/base/android/library_loader/library_prefetcher.h b/base/android/library_loader/library_prefetcher.h index 7ee4260..44a93e6 100644 --- a/base/android/library_loader/library_prefetcher.h +++ b/base/android/library_loader/library_prefetcher.h @@ -30,7 +30,10 @@ class BASE_EXPORT NativeLibraryPrefetcher { // Finds the ranges matching the native library, forks a low priority // process pre-fetching these ranges and wait()s for it. // Returns true for success. - static bool ForkAndPrefetchNativeLibrary(bool is_cold_start); + static bool ForkAndPrefetchNativeLibrary(); + // Returns the percentage of the native library code currently resident in + // memory, or -1 in case of error. + static int PercentageOfResidentNativeLibraryCode(); private: using AddressRange = std::pair<uintptr_t, uintptr_t>; @@ -44,8 +47,8 @@ class BASE_EXPORT NativeLibraryPrefetcher { // Returns true for success. static bool FindRanges(std::vector<AddressRange>* ranges); - // Returns the percentage of the given address ranges that are currently - // resident in memory, or -1 in case of error. + // Returns the percentage of the given address ranges currently resident in + // memory, or -1 in case of error. static int PercentageOfResidentCode(const std::vector<AddressRange>& ranges); FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, |