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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Shal 2019-03-18 23:52:31 +00:00
Родитель 5607f84fdf
Коммит 14770d9dbf
5 изменённых файлов: 28 добавлений и 0 удалений

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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 {
@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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