diff --git a/mobile/android/base/GeckoJavaSampler.java b/mobile/android/base/GeckoJavaSampler.java index cb0d60d06c202..8d7ac3553af72 100644 --- a/mobile/android/base/GeckoJavaSampler.java +++ b/mobile/android/base/GeckoJavaSampler.java @@ -22,6 +22,7 @@ public class GeckoJavaSampler { // Use the same timer primitive as the profiler // to get a perfect sample syncing. + @WrapForJNI private static native double getProfilerTime(); private static class Sample { @@ -208,6 +209,3 @@ public static void stop() { } } } - - - diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index 50ff84f67e0a2..5fbbddaf5f175 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -35,6 +35,10 @@ #include "AndroidBridge.h" #endif +#ifdef SPS_OS_android +#include "GeneratedJNINatives.h" +#endif + #ifndef SPS_STANDALONE #if defined(SPS_PLAT_amd64_linux) || defined(SPS_PLAT_x86_linux) # define USE_LUL_STACKWALK @@ -43,6 +47,22 @@ #endif #endif +#ifdef SPS_OS_android +class GeckoJavaSampler : public widget::GeckoJavaSampler::Natives +{ +private: + GeckoJavaSampler(); + +public: + static double GetProfilerTime() { + if (!profiler_is_active()) { + return 0.0; + } + return profiler_time(); + }; +}; +#endif + mozilla::ThreadLocal tlsPseudoStack; mozilla::ThreadLocal tlsTicker; mozilla::ThreadLocal tlsStackTop; @@ -473,6 +493,12 @@ void mozilla_sampler_init(void* stackTop) set_stderr_callback(mozilla_sampler_log); #endif +#ifdef SPS_OS_android + if (mozilla::jni::IsAvailable()) { + GeckoJavaSampler::Init(); + } +#endif + // We can't open pref so we use an environment variable // to know if we should trigger the profiler on startup // NOTE: Default diff --git a/widget/android/AndroidJNI.cpp b/widget/android/AndroidJNI.cpp index 6b75536a0c69a..db2686ba3cdf1 100644 --- a/widget/android/AndroidJNI.cpp +++ b/widget/android/AndroidJNI.cpp @@ -680,7 +680,7 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyFilePickerResult(JNIEnv* jenv, jclass { class NotifyFilePickerResultRunnable : public nsRunnable { public: - NotifyFilePickerResultRunnable(nsString& fileDir, long callback) : + NotifyFilePickerResultRunnable(nsString& fileDir, long callback) : mFileDir(fileDir), mCallback(callback) {} NS_IMETHODIMP Run() { @@ -694,7 +694,7 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyFilePickerResult(JNIEnv* jenv, jclass long mCallback; }; nsString path = nsJNIString(filePath, jenv); - + nsCOMPtr runnable = new NotifyFilePickerResultRunnable(path, (long)callback); NS_DispatchToMainThread(runnable); @@ -767,7 +767,7 @@ Java_org_mozilla_gecko_GeckoAppShell_getSurfaceBits(JNIEnv* jenv, jclass, jobjec for (int i = 0; i < srcHeight; i++) { memcpy(bitsCopy + ((dstHeight - i - 1) * dstWidth * bpp), bits + (i * srcStride * bpp), srcStride * bpp); } - + if (!jSurfaceBitsClass) { jSurfaceBitsClass = (jclass)jenv->NewGlobalRef(jenv->FindClass("org/mozilla/gecko/SurfaceBits")); jSurfaceBitsCtor = jenv->GetMethodID(jSurfaceBitsClass, "", "()V"); @@ -852,15 +852,6 @@ Java_org_mozilla_gecko_GeckoAppShell_dispatchMemoryPressure(JNIEnv* jenv, jclass NS_DispatchMemoryPressure(MemPressure_New); } -NS_EXPORT jdouble JNICALL -Java_org_mozilla_gecko_GeckoJavaSampler_getProfilerTime(JNIEnv *jenv, jclass jc) -{ - if (!profiler_is_active()) { - return 0.0; - } - return profiler_time(); -} - NS_EXPORT void JNICALL Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation(JNIEnv* env, jobject instance) { diff --git a/widget/android/GeneratedJNINatives.h b/widget/android/GeneratedJNINatives.h index ed062caab8c28..3e04a51888bc2 100644 --- a/widget/android/GeneratedJNINatives.h +++ b/widget/android/GeneratedJNINatives.h @@ -36,6 +36,21 @@ class ANRReporter::Natives : public mozilla::jni::NativeImpl template constexpr JNINativeMethod ANRReporter::Natives::methods[]; +template +class GeckoJavaSampler::Natives : public mozilla::jni::NativeImpl +{ +public: + static constexpr JNINativeMethod methods[] = { + + mozilla::jni::MakeNativeMethod( + mozilla::jni::NativeStub + ::template Wrap<&Impl::GetProfilerTime>) + }; +}; + +template +constexpr JNINativeMethod GeckoJavaSampler::Natives::methods[]; + template class GeckoThread::Natives : public mozilla::jni::NativeImpl { diff --git a/widget/android/GeneratedJNIWrappers.cpp b/widget/android/GeneratedJNIWrappers.cpp index 9ddd80864443c..363d5de0baa2c 100644 --- a/widget/android/GeneratedJNIWrappers.cpp +++ b/widget/android/GeneratedJNIWrappers.cpp @@ -715,6 +715,9 @@ auto GeckoJavaSampler::GetFrameNameJavaProfilingWrapper(int32_t a0, int32_t a1, return mozilla::jni::Method::Call(nullptr, nullptr, a0, a1, a2); } +constexpr char GeckoJavaSampler::GetProfilerTime_t::name[]; +constexpr char GeckoJavaSampler::GetProfilerTime_t::signature[]; + constexpr char GeckoJavaSampler::GetSampleTimeJavaProfiling_t::name[]; constexpr char GeckoJavaSampler::GetSampleTimeJavaProfiling_t::signature[]; diff --git a/widget/android/GeneratedJNIWrappers.h b/widget/android/GeneratedJNIWrappers.h index a36ff9666db22..f222acce0580b 100644 --- a/widget/android/GeneratedJNIWrappers.h +++ b/widget/android/GeneratedJNIWrappers.h @@ -1694,6 +1694,21 @@ class GeckoJavaSampler : public mozilla::jni::Class static auto GetFrameNameJavaProfilingWrapper(int32_t, int32_t, int32_t) -> mozilla::jni::String::LocalRef; +public: + struct GetProfilerTime_t { + typedef GeckoJavaSampler Owner; + typedef double ReturnType; + typedef double SetterType; + typedef mozilla::jni::Args<> Args; + static constexpr char name[] = "getProfilerTime"; + static constexpr char signature[] = + "()D"; + static const bool isStatic = true; + static const bool isMultithreaded = false; + static const mozilla::jni::ExceptionMode exceptionMode = + mozilla::jni::ExceptionMode::ABORT; + }; + public: struct GetSampleTimeJavaProfiling_t { typedef GeckoJavaSampler Owner; @@ -1801,6 +1816,8 @@ class GeckoJavaSampler : public mozilla::jni::Class static auto UnpauseJavaProfiling() -> void; +public: + template class Natives; }; class GeckoThread : public mozilla::jni::Class diff --git a/widget/android/moz.build b/widget/android/moz.build index 03dd17ea37b04..402e69ab957c3 100644 --- a/widget/android/moz.build +++ b/widget/android/moz.build @@ -19,6 +19,7 @@ EXPORTS += [ 'AndroidBridge.h', 'AndroidJavaWrappers.h', 'AndroidJNIWrapper.h', + 'GeneratedJNINatives.h', 'GeneratedJNIWrappers.h', ]