Bug 632954 - Add an explicit __llvm_profile_dump() call for Android; r=snorp
☠☠ backed out by d7e6fff52db3 ☠ ☠
authorMike Shal <mshal@mozilla.com>
Mon, 18 Mar 2019 23:52:31 +0000
changeset 465135 0615c775a0cf6e8f98e1c051cd574c0d602a738a
parent 465134 3dfc0e4f8e7c8cd48b911033222fb3c3edb9762b
child 465136 142ae187478da8a6c3899ef6409cafc6e60a9115
push id35732
push useropoprus@mozilla.com
push dateWed, 20 Mar 2019 10:52:37 +0000
treeherdermozilla-central@708979f9c3f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs632954
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 632954 - Add an explicit __llvm_profile_dump() call for Android; r=snorp When Android shuts down the ndk process, it doesn't call the registered atexit() handlers, which is normally where the profile data gets written to file. Since the PGO test suite closes the browser when it is finished, the nativeRun routine can manually call out to __llvm_profile_dump() before returning. This method has a downside that only the profile data from the calling library gets written out, rather than for the whole process. Since we are most interested in optimizing libxul, a new hook is added in Bootstrap to make sure we get the profile data for the right library. Differential Revision: https://phabricator.services.mozilla.com/D22817
mozglue/android/APKOpen.cpp
mozglue/android/moz.build
toolkit/xre/Bootstrap.cpp
toolkit/xre/Bootstrap.h
toolkit/xre/moz.build
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -374,16 +374,21 @@ Java_org_mozilla_gecko_mozglue_GeckoLoad
     gBootstrap->XRE_SetAndroidChildFds(
         jenv, {prefsFd, prefMapFd, ipcFd, crashFd, crashAnnotationFd});
     gBootstrap->XRE_SetProcessType(argv[argc - 1]);
 
     XREChildData childData;
     gBootstrap->XRE_InitChildProcess(argc - 1, argv, &childData);
   }
 
+#ifdef MOZ_WIDGET_ANDROID
+#  ifdef MOZ_PROFILE_GENERATE
+  gBootstrap->XRE_WriteLLVMProfData();
+#  endif
+#endif
   gBootstrap.reset();
   FreeArgv(argv, argc);
 }
 
 extern "C" APKOPEN_EXPORT mozglueresult ChildProcessInit(int argc,
                                                          char* argv[]) {
   if (loadNSSLibs() != SUCCESS) {
     return FAILURE;
--- a/mozglue/android/moz.build
+++ b/mozglue/android/moz.build
@@ -28,16 +28,19 @@ if CONFIG['MOZ_CRASHREPORTER']:
     ]
 
 FINAL_LIBRARY = 'mozglue'
 
 for var in ('ANDROID_PACKAGE_NAME',
             'ANDROID_CPU_ARCH'):
     DEFINES[var] = '"%s"' % CONFIG[var]
 
+if CONFIG['MOZ_PROFILE_GENERATE']:
+    DEFINES['MOZ_PROFILE_GENERATE'] = True
+
 if CONFIG['MOZ_FOLD_LIBS']:
     DEFINES['MOZ_FOLD_LIBS'] = True
 
 LOCAL_INCLUDES += [
     '!/build',
     '../linker',
     '/db/sqlite3/src',
     '/ipc/chromium/src',
--- a/toolkit/xre/Bootstrap.cpp
+++ b/toolkit/xre/Bootstrap.cpp
@@ -3,16 +3,22 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Bootstrap.h"
 #include "nsXPCOM.h"
 
 #include "AutoSQLiteLifetime.h"
 
+#ifdef MOZ_WIDGET_ANDROID
+#  ifdef MOZ_PROFILE_GENERATE
+extern "C" int __llvm_profile_dump(void);
+#  endif
+#endif
+
 namespace mozilla {
 
 class BootstrapImpl final : public Bootstrap {
  protected:
   AutoSQLiteLifetime mSQLLT;
 
   virtual void Dispose() override { delete this; }
 
@@ -70,16 +76,24 @@ class BootstrapImpl final : public Boots
                           const StaticXREAppData& aAppData) override {
     ::GeckoStart(aEnv, argv, argc, aAppData);
   }
 
   virtual void XRE_SetAndroidChildFds(
       JNIEnv* aEnv, const XRE_AndroidChildFds& aFds) override {
     ::XRE_SetAndroidChildFds(aEnv, aFds);
   }
+
+#  ifdef MOZ_PROFILE_GENERATE
+  virtual void XRE_WriteLLVMProfData() override {
+    __android_log_print(ANDROID_LOG_INFO, "GeckoLibLoad",
+                        "Calling __llvm_profile_dump()");
+    __llvm_profile_dump();
+  }
+#  endif
 #endif
 
 #ifdef LIBFUZZER
   virtual void XRE_LibFuzzerSetDriver(LibFuzzerDriver aDriver) override {
     ::XRE_LibFuzzerSetDriver(aDriver);
   }
 #endif
 
--- a/toolkit/xre/Bootstrap.h
+++ b/toolkit/xre/Bootstrap.h
@@ -109,16 +109,19 @@ class Bootstrap {
   virtual void XRE_EnableSameExecutableForContentProc() = 0;
 
 #ifdef MOZ_WIDGET_ANDROID
   virtual void GeckoStart(JNIEnv* aEnv, char** argv, int argc,
                           const StaticXREAppData& aAppData) = 0;
 
   virtual void XRE_SetAndroidChildFds(JNIEnv* aEnv,
                                       const XRE_AndroidChildFds& fds) = 0;
+#  ifdef MOZ_PROFILE_GENERATE
+  virtual void XRE_WriteLLVMProfData() = 0;
+#  endif
 #endif
 
 #ifdef LIBFUZZER
   virtual void XRE_LibFuzzerSetDriver(LibFuzzerDriver aDriver) = 0;
 #endif
 
 #ifdef MOZ_IPDL_TESTS
   virtual int XRE_RunIPDLTest(int argc, char** argv) = 0;
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -252,8 +252,11 @@ FINAL_TARGET_PP_FILES += [
     'platform.ini'
 ]
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
 
 if CONFIG['MOZ_IPDL_TESTS']:
     DEFINES['MOZ_IPDL_TESTS'] = True
+
+if CONFIG['MOZ_PROFILE_GENERATE']:
+    DEFINES['MOZ_PROFILE_GENERATE'] = True