Bug 1557570 - Call baseprofiler::profiler_init() from the first mozglue function that runs. r=gerald

As far as I can tell there is no single entry-point into C++ code on Android.
Instead, GeckoThread and GeckoLibLoader call various functions to load libraries one-by-one.
We want to capture all that library loading in the profiler, so we need to kick off the base profiler at the beginning of whichever function is called first.

Differential Revision: https://phabricator.services.mozilla.com/D64999

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2020-03-17 04:15:04 +00:00
Родитель 3349423265
Коммит 292f87c1ef
1 изменённых файлов: 34 добавлений и 0 удалений

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

@ -30,6 +30,7 @@
#include <sys/prctl.h>
#include "sqlite3.h"
#include "Linker.h"
#include "BaseProfiler.h"
#include "application.ini.h"
#include "mozilla/arm.h"
@ -188,6 +189,29 @@ static void* dlopenLibrary(const char* libraryName) {
RTLD_GLOBAL | RTLD_LAZY);
}
static void EnsureBaseProfilerInitialized() {
// There is no single entry-point into C++ code on Android.
// Instead, GeckoThread and GeckoLibLoader call various functions to load
// libraries one-by-one.
// We want to capture all that library loading in the profiler, so we need to
// kick off the base profiler at the beginning of whichever function is called
// first.
// We currently assume that all these functions are called on the same thread.
static bool sInitialized = false;
if (sInitialized) {
return;
}
#ifdef MOZ_BASE_PROFILER
// The stack depth we observe here will be determined by the stack of
// whichever caller enters this code first. In practice this means that we may
// miss some root-most frames, which hopefully shouldn't ruin profiling.
int stackBase = 5;
mozilla::baseprofiler::profiler_init(&stackBase);
#endif
sInitialized = true;
}
static mozglueresult loadGeckoLibs() {
TimeStamp t0 = TimeStamp::Now();
struct rusage usage1_thread, usage1;
@ -289,6 +313,8 @@ static mozglueresult loadNSSLibs() {
extern "C" APKOPEN_EXPORT void MOZ_JNICALL
Java_org_mozilla_gecko_mozglue_GeckoLoader_loadGeckoLibsNative(
JNIEnv* jenv, jclass jGeckoAppShellClass) {
EnsureBaseProfilerInitialized();
jenv->GetJavaVM(&sJavaVM);
int res = loadGeckoLibs();
@ -300,6 +326,8 @@ Java_org_mozilla_gecko_mozglue_GeckoLoader_loadGeckoLibsNative(
extern "C" APKOPEN_EXPORT void MOZ_JNICALL
Java_org_mozilla_gecko_mozglue_GeckoLoader_loadSQLiteLibsNative(
JNIEnv* jenv, jclass jGeckoAppShellClass) {
EnsureBaseProfilerInitialized();
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Load sqlite start\n");
mozglueresult rv = loadSQLiteLibs();
if (rv != SUCCESS) {
@ -311,6 +339,8 @@ Java_org_mozilla_gecko_mozglue_GeckoLoader_loadSQLiteLibsNative(
extern "C" APKOPEN_EXPORT void MOZ_JNICALL
Java_org_mozilla_gecko_mozglue_GeckoLoader_loadNSSLibsNative(
JNIEnv* jenv, jclass jGeckoAppShellClass) {
EnsureBaseProfilerInitialized();
__android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Load nss start\n");
mozglueresult rv = loadNSSLibs();
if (rv != SUCCESS) {
@ -361,6 +391,8 @@ Java_org_mozilla_gecko_mozglue_GeckoLoader_nativeRun(JNIEnv* jenv, jclass jc,
int prefsFd, int prefMapFd,
int ipcFd, int crashFd,
int crashAnnotationFd) {
EnsureBaseProfilerInitialized();
int argc = 0;
char** argv = CreateArgvFromObjectArray(jenv, jargs, &argc);
@ -397,6 +429,8 @@ Java_org_mozilla_gecko_mozglue_GeckoLoader_nativeRun(JNIEnv* jenv, jclass jc,
extern "C" APKOPEN_EXPORT mozglueresult ChildProcessInit(int argc,
char* argv[]) {
EnsureBaseProfilerInitialized();
if (loadNSSLibs() != SUCCESS) {
return FAILURE;
}