QuickPerformanceLogger.js: markerPoint + iOS/Android JS binding

Reviewed By: alexeylang

Differential Revision: D8125546

fbshipit-source-id: bb02921c7d89faba64001bff3b9aaf13f64a7f8b
This commit is contained in:
Oleksandr Sokolov 2018-06-08 08:24:47 -07:00 committed by Facebook Github Bot
parent 291c01f4ff
commit 078d6e3a9d
2 changed files with 51 additions and 1 deletions

View File

@ -81,6 +81,17 @@ const QuickPerformanceLogger = {
}
},
markerPoint(
markerId: number,
name: string,
instanceKey: number = DUMMY_INSTANCE_KEY,
timestamp: number = AUTO_SET_TIMESTAMP,
): void {
if (global.nativeQPLMarkerPoint) {
global.nativeQPLMarkerPoint(markerId, name, instanceKey, timestamp);
}
},
currentTimestamp(): number {
if (global.nativeQPLTimestamp) {
return global.nativeQPLTimestamp();

View File

@ -62,6 +62,12 @@ struct JQuickPerformanceLogger : JavaClass<JQuickPerformanceLogger> {
javaClassStatic()->getMethod<jlong()>("currentMonotonicTimestamp");
return currentTimestampMethod(self());
}
void markerPoint(int markerId, alias_ref<jstring> name, int instanceKey) {
static auto markerPointMethod =
javaClassStatic()->getMethod<void(jint, jint, alias_ref<jstring>)>("markerPoint");
markerPointMethod(self(), markerId, instanceKey, name);
}
};
struct JQuickPerformanceLoggerProvider : JavaClass<JQuickPerformanceLoggerProvider> {
@ -106,6 +112,14 @@ static bool isNan(double value) {
return (value != value);
}
static double grabDouble(
JSContextRef ctx,
const JSValueRef arguments[],
size_t argumentIndex,
JSValueRef* exception) {
return JSValueToNumber(ctx, arguments[argumentIndex], exception);
}
// Safely translates JSValues to an array of doubles.
static bool grabDoubles(
size_t targetsCount,
@ -118,7 +132,7 @@ static bool grabDoubles(
return false;
}
for (size_t i = 0 ; i < targetsCount ; i++) {
targets[i] = JSValueToNumber(ctx, arguments[i], exception);
targets[i] = grabDouble(ctx, arguments, i, exception);
if (isNan(targets[i])) {
return false;
}
@ -254,6 +268,30 @@ static JSValueRef nativeQPLTimestamp(
return JSValueMakeNumber(ctx, timestamp);
}
static JSValueRef nativeQPLMarkerPoint(
JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception) {
if (isReady() && argumentCount == 4) {
double markerIdArgument = grabDouble(ctx, arguments, 0, exception);
double instanceKeyArgument = grabDouble(ctx, arguments, 2, exception);
if (isNan(markerIdArgument) || isNan(instanceKeyArgument)) {
return JSValueMakeUndefined(ctx);
}
int32_t markerId = (int32_t) markerIdArgument;
local_ref<jstring> name = getJStringFromJSValueRef(ctx, arguments[1]);
int32_t instanceKey = (int32_t) instanceKeyArgument;
// timestamp is not used as QuickPerformanceLogger::markerPoint with all
// params is missing
JQuickPerformanceLoggerProvider::get()->markerPoint(markerId, name, instanceKey);
}
return JSValueMakeUndefined(ctx);
}
void addNativePerfLoggingHooks(JSGlobalContextRef ctx) {
installGlobalFunction(ctx, "nativeQPLMarkerStart", nativeQPLMarkerStart);
installGlobalFunction(ctx, "nativeQPLMarkerEnd", nativeQPLMarkerEnd);
@ -262,6 +300,7 @@ void addNativePerfLoggingHooks(JSGlobalContextRef ctx) {
installGlobalFunction(ctx, "nativeQPLMarkerNote", nativeQPLMarkerNote);
installGlobalFunction(ctx, "nativeQPLMarkerCancel", nativeQPLMarkerCancel);
installGlobalFunction(ctx, "nativeQPLTimestamp", nativeQPLTimestamp);
installGlobalFunction(ctx, "nativeQPLMarkerPoint", nativeQPLMarkerPoint);
}
} }