From dc0df40770ec1f7a1cfff6dbb059f690d056234a Mon Sep 17 00:00:00 2001 From: Aaron Chiu Date: Fri, 17 Feb 2017 16:30:41 -0800 Subject: [PATCH] add a way to call QPL.markerTag() Reviewed By: mhorowitz Differential Revision: D4564193 fbshipit-source-id: a63262eeb62c2945249e7021a59da0ff5df44918 --- .../main/jni/xreact/jni/JSCPerfLogging.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ReactAndroid/src/main/jni/xreact/jni/JSCPerfLogging.cpp b/ReactAndroid/src/main/jni/xreact/jni/JSCPerfLogging.cpp index e1a306665..0212e590f 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/JSCPerfLogging.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/JSCPerfLogging.cpp @@ -37,6 +37,12 @@ class JObjectWrapper : public JObjectWrapper { markerEndMethod(this_, markerId, instanceKey, actionId, timestamp); } + void markerTag(int markerId, int instanceKey, alias_ref tag) { + static auto markerTagMethod = + qplClass()->getMethod)>("markerTag"); + markerTagMethod(this_, markerId, instanceKey, tag); + } + void markerNote(int markerId, int instanceKey, short actionId, long timestamp) { static auto markerNoteMethod = qplClass()->getMethod("markerNote"); @@ -146,6 +152,15 @@ static bool grabDoubles( return true; } +static local_ref getJStringFromJSValueRef(JSContextRef ctx, JSValueRef ref) { + JSStringRef jsStringRef = JSValueToStringCopy(ctx, ref, nullptr); + const JSChar* chars = JSStringGetCharactersPtr(jsStringRef); + const size_t length = JSStringGetLength(jsStringRef); + local_ref returnStr = adopt_local(Environment::current()->NewString(chars, length)); + JSStringRelease(jsStringRef); + return returnStr; +} + static JSValueRef nativeQPLMarkerStart( JSContextRef ctx, JSObjectRef function, @@ -181,6 +196,23 @@ static JSValueRef nativeQPLMarkerEnd( return JSValueMakeUndefined(ctx); } +static JSValueRef nativeQPLMarkerTag( + JSContextRef ctx, + JSObjectRef function, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) { + double targets[2]; + if (isReady() && grabDoubles(2, targets, ctx, argumentCount, arguments, exception)) { + int32_t markerId = (int32_t) targets[0]; + int32_t instanceKey = (int32_t) targets[1]; + local_ref tag = getJStringFromJSValueRef(ctx, arguments[2]); + JQuickPerformanceLoggerProvider::get()->markerTag(markerId, instanceKey, tag); + } + return JSValueMakeUndefined(ctx); +} + static JSValueRef nativeQPLMarkerNote( JSContextRef ctx, JSObjectRef function, @@ -236,6 +268,7 @@ namespace react { void addNativePerfLoggingHooks(JSGlobalContextRef ctx) { installGlobalFunction(ctx, "nativeQPLMarkerStart", nativeQPLMarkerStart); installGlobalFunction(ctx, "nativeQPLMarkerEnd", nativeQPLMarkerEnd); + installGlobalFunction(ctx, "nativeQPLMarkerTag", nativeQPLMarkerTag); installGlobalFunction(ctx, "nativeQPLMarkerNote", nativeQPLMarkerNote); installGlobalFunction(ctx, "nativeQPLMarkerCancel", nativeQPLMarkerCancel); installGlobalFunction(ctx, "nativeQPLTimestamp", nativeQPLTimestamp);