Skip to content

Commit

Permalink
Bug 632954 - Add an explicit __llvm_profile_dump() call for Android; …
Browse files Browse the repository at this point in the history
…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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
mshal committed Mar 18, 2019
1 parent 5607f84 commit 14770d9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mozglue/android/APKOpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ Java_org_mozilla_gecko_mozglue_GeckoLoader_nativeRun(JNIEnv* jenv, jclass jc,
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);
}
Expand Down
3 changes: 3 additions & 0 deletions mozglue/android/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ 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

Expand Down
14 changes: 14 additions & 0 deletions toolkit/xre/Bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

#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 {
Expand Down Expand Up @@ -75,6 +81,14 @@ class BootstrapImpl final : public Bootstrap {
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
Expand Down
3 changes: 3 additions & 0 deletions toolkit/xre/Bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class Bootstrap {

virtual void XRE_SetAndroidChildFds(JNIEnv* aEnv,
const XRE_AndroidChildFds& fds) = 0;
# ifdef MOZ_PROFILE_GENERATE
virtual void XRE_WriteLLVMProfData() = 0;
# endif
#endif

#ifdef LIBFUZZER
Expand Down
3 changes: 3 additions & 0 deletions toolkit/xre/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,6 @@ if CONFIG['CC_TYPE'] in ('clang', 'gcc'):

if CONFIG['MOZ_IPDL_TESTS']:
DEFINES['MOZ_IPDL_TESTS'] = True

if CONFIG['MOZ_PROFILE_GENERATE']:
DEFINES['MOZ_PROFILE_GENERATE'] = True

0 comments on commit 14770d9

Please sign in to comment.