Skip to content

Commit

Permalink
Add android app start time implementation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Xin Chen authored and facebook-github-bot committed Mar 3, 2023
1 parent 02e29ab commit ec99ba1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void logFabricMarker(
private static final List<FabricMarkerListener> 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)) {
Expand Down Expand Up @@ -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;
}
}
7 changes: 7 additions & 0 deletions ReactAndroid/src/main/jni/react/jni/JReactMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void JReactMarker::setLogPerfMarkerIfNeeded() {
ReactMarker::logTaggedMarkerImpl = JReactMarker::logPerfMarker;
ReactMarker::logTaggedMarkerBridgelessImpl =
JReactMarker::logPerfMarkerBridgeless;
ReactMarker::getAppStartTimeImpl = JReactMarker::getAppStartTime;
});
}

Expand Down Expand Up @@ -103,5 +104,11 @@ void JReactMarker::logPerfMarkerWithInstanceKey(
}
}

double JReactMarker::getAppStartTime() {
static auto cls = javaClassStatic();
static auto meth = cls->getStaticMethod<double()>("getAppStartTime");
return meth(cls);
}

} // namespace react
} // namespace facebook
1 change: 1 addition & 0 deletions ReactAndroid/src/main/jni/react/jni/JReactMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class JReactMarker : public facebook::jni::JavaClass<JReactMarker> {
const ReactMarker::ReactMarkerId markerId,
const char *tag,
const int instanceKey);
static double getAppStartTime();
};

} // namespace react
Expand Down

0 comments on commit ec99ba1

Please sign in to comment.