From ec99ba141372b8c1485edd19e5c317e120fbb7af Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Thu, 2 Mar 2023 22:40:12 -0800 Subject: [PATCH] Add android app start time implementation Summary: This diff adds the android `appStartTime` implementation for `ReactMarker`. Changelog: [Android][Internal] - Add the android `appStartTime` implementation for `ReactMarker` Reviewed By: rshest Differential Revision: D43523607 fbshipit-source-id: 9dc95db30e36e7c1bfb262c74598f0ac249522f2 --- .../java/com/facebook/react/bridge/ReactMarker.java | 13 +++++++++++++ .../src/main/jni/react/jni/JReactMarker.cpp | 7 +++++++ ReactAndroid/src/main/jni/react/jni/JReactMarker.h | 1 + 3 files changed, 21 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarker.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarker.java index ac07aca94c7be8..83ecd9d39368e1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarker.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarker.java @@ -42,6 +42,9 @@ void logFabricMarker( private static final List sFabricMarkerListeners = new CopyOnWriteArrayList<>(); + // The android app start time that to be set by the corresponding app + private static long sAppStartTime; + @DoNotStrip public static void addListener(MarkerListener listener) { if (!sListeners.contains(listener)) { @@ -138,4 +141,14 @@ public static void logMarker(ReactMarkerConstants name, @Nullable String tag, in listener.logMarker(name, tag, instanceKey); } } + + @DoNotStrip + public static void setAppStartTime(long appStartTime) { + sAppStartTime = appStartTime; + } + + @DoNotStrip + public static double getAppStartTime() { + return (double) sAppStartTime; + } } diff --git a/ReactAndroid/src/main/jni/react/jni/JReactMarker.cpp b/ReactAndroid/src/main/jni/react/jni/JReactMarker.cpp index d0da85929f1d69..6708d0d1ba8770 100644 --- a/ReactAndroid/src/main/jni/react/jni/JReactMarker.cpp +++ b/ReactAndroid/src/main/jni/react/jni/JReactMarker.cpp @@ -20,6 +20,7 @@ void JReactMarker::setLogPerfMarkerIfNeeded() { ReactMarker::logTaggedMarkerImpl = JReactMarker::logPerfMarker; ReactMarker::logTaggedMarkerBridgelessImpl = JReactMarker::logPerfMarkerBridgeless; + ReactMarker::getAppStartTimeImpl = JReactMarker::getAppStartTime; }); } @@ -103,5 +104,11 @@ void JReactMarker::logPerfMarkerWithInstanceKey( } } +double JReactMarker::getAppStartTime() { + static auto cls = javaClassStatic(); + static auto meth = cls->getStaticMethod("getAppStartTime"); + return meth(cls); +} + } // namespace react } // namespace facebook diff --git a/ReactAndroid/src/main/jni/react/jni/JReactMarker.h b/ReactAndroid/src/main/jni/react/jni/JReactMarker.h index 7ee91f0019aaaf..b945d5555a9631 100644 --- a/ReactAndroid/src/main/jni/react/jni/JReactMarker.h +++ b/ReactAndroid/src/main/jni/react/jni/JReactMarker.h @@ -38,6 +38,7 @@ class JReactMarker : public facebook::jni::JavaClass { const ReactMarker::ReactMarkerId markerId, const char *tag, const int instanceKey); + static double getAppStartTime(); }; } // namespace react