QuickPerformanceLogger.js: markerPoint + iOS/Android JS binding
Reviewed By: alexeylang Differential Revision: D8125546 fbshipit-source-id: bb02921c7d89faba64001bff3b9aaf13f64a7f8b
This commit is contained in:
parent
291c01f4ff
commit
078d6e3a9d
|
@ -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 {
|
currentTimestamp(): number {
|
||||||
if (global.nativeQPLTimestamp) {
|
if (global.nativeQPLTimestamp) {
|
||||||
return global.nativeQPLTimestamp();
|
return global.nativeQPLTimestamp();
|
||||||
|
|
|
@ -62,6 +62,12 @@ struct JQuickPerformanceLogger : JavaClass<JQuickPerformanceLogger> {
|
||||||
javaClassStatic()->getMethod<jlong()>("currentMonotonicTimestamp");
|
javaClassStatic()->getMethod<jlong()>("currentMonotonicTimestamp");
|
||||||
return currentTimestampMethod(self());
|
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> {
|
struct JQuickPerformanceLoggerProvider : JavaClass<JQuickPerformanceLoggerProvider> {
|
||||||
|
@ -106,6 +112,14 @@ static bool isNan(double value) {
|
||||||
return (value != 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.
|
// Safely translates JSValues to an array of doubles.
|
||||||
static bool grabDoubles(
|
static bool grabDoubles(
|
||||||
size_t targetsCount,
|
size_t targetsCount,
|
||||||
|
@ -118,7 +132,7 @@ static bool grabDoubles(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (size_t i = 0 ; i < targetsCount ; i++) {
|
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])) {
|
if (isNan(targets[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -254,6 +268,30 @@ static JSValueRef nativeQPLTimestamp(
|
||||||
return JSValueMakeNumber(ctx, timestamp);
|
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) {
|
void addNativePerfLoggingHooks(JSGlobalContextRef ctx) {
|
||||||
installGlobalFunction(ctx, "nativeQPLMarkerStart", nativeQPLMarkerStart);
|
installGlobalFunction(ctx, "nativeQPLMarkerStart", nativeQPLMarkerStart);
|
||||||
installGlobalFunction(ctx, "nativeQPLMarkerEnd", nativeQPLMarkerEnd);
|
installGlobalFunction(ctx, "nativeQPLMarkerEnd", nativeQPLMarkerEnd);
|
||||||
|
@ -262,6 +300,7 @@ void addNativePerfLoggingHooks(JSGlobalContextRef ctx) {
|
||||||
installGlobalFunction(ctx, "nativeQPLMarkerNote", nativeQPLMarkerNote);
|
installGlobalFunction(ctx, "nativeQPLMarkerNote", nativeQPLMarkerNote);
|
||||||
installGlobalFunction(ctx, "nativeQPLMarkerCancel", nativeQPLMarkerCancel);
|
installGlobalFunction(ctx, "nativeQPLMarkerCancel", nativeQPLMarkerCancel);
|
||||||
installGlobalFunction(ctx, "nativeQPLTimestamp", nativeQPLTimestamp);
|
installGlobalFunction(ctx, "nativeQPLTimestamp", nativeQPLTimestamp);
|
||||||
|
installGlobalFunction(ctx, "nativeQPLMarkerPoint", nativeQPLMarkerPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
Loading…
Reference in New Issue