mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support JS Systrace on all platforms
Reviewed By: tadeuzagallo Differential Revision: D3234830 fbshipit-source-id: 94cc870d47d620c8bd8d35f83d0b017e5ddba90d
This commit is contained in:
1 parent
b7fe8e68be
commit
86f2eb18e5
6 files changed
+127
-72
No files matched your search
@@ -1,10 +1,11 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#ifdef WITH_JSC_EXTRA_TRACING
|
||||
#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG
|
||||
|
||||
#include "JSCTracing.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <JavaScriptCore/JavaScript.h>
|
||||
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
||||
#include <fbsystrace.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -12,20 +13,6 @@
|
||||
|
||||
using std::min;
|
||||
|
||||
static const char *ENABLED_FBSYSTRACE_PROFILE_NAME = "__fbsystrace__";
|
||||
|
||||
static uint64_t tagFromJSValue(
|
||||
JSContextRef ctx,
|
||||
JSValueRef value,
|
||||
JSValueRef* exception) {
|
||||
// XXX validate that this is a lossless conversion.
|
||||
// XXX should we just have separate functions for bridge, infra, and apps,
|
||||
// then drop this argument to save time?
|
||||
(void)exception;
|
||||
uint64_t tag = (uint64_t) JSValueToNumber(ctx, value, NULL);
|
||||
return tag;
|
||||
}
|
||||
|
||||
static int64_t int64FromJSValue(
|
||||
JSContextRef ctx,
|
||||
JSValueRef value,
|
||||
@@ -105,7 +92,7 @@ static JSValueRef nativeTraceBeginSection(
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
@@ -145,7 +132,7 @@ static JSValueRef nativeTraceEndSection(
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
@@ -189,7 +176,7 @@ static JSValueRef beginOrEndAsync(
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
@@ -252,7 +239,7 @@ static JSValueRef stageAsync(
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
@@ -398,7 +385,7 @@ static JSValueRef nativeTraceCounter(
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
@@ -414,60 +401,24 @@ static JSValueRef nativeTraceCounter(
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
static JSValueRef nativeTraceBeginLegacy(
|
||||
JSContextRef ctx,
|
||||
JSObjectRef function,
|
||||
JSObjectRef thisObject,
|
||||
size_t argumentCount,
|
||||
const JSValueRef arguments[],
|
||||
JSValueRef* exception) {
|
||||
if (FBSYSTRACE_LIKELY(argumentCount >= 1)) {
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
JSStringRef title = JSStringCreateWithUTF8CString(ENABLED_FBSYSTRACE_PROFILE_NAME);
|
||||
#if WITH_REACT_INTERNAL_SETTINGS
|
||||
JSStartProfiling(ctx, title, true);
|
||||
#else
|
||||
JSStartProfiling(ctx, title);
|
||||
#endif
|
||||
JSStringRelease(title);
|
||||
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
static JSValueRef nativeTraceEndLegacy(
|
||||
JSContextRef ctx,
|
||||
JSObjectRef function,
|
||||
JSObjectRef thisObject,
|
||||
size_t argumentCount,
|
||||
const JSValueRef arguments[],
|
||||
JSValueRef* exception) {
|
||||
if (FBSYSTRACE_LIKELY(argumentCount >= 1)) {
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
JSStringRef title = JSStringCreateWithUTF8CString(ENABLED_FBSYSTRACE_PROFILE_NAME);
|
||||
JSEndProfiling(ctx, title);
|
||||
JSStringRelease(title);
|
||||
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
uint64_t tracingTagFromJSValue(
|
||||
JSContextRef ctx,
|
||||
JSValueRef value,
|
||||
JSValueRef* exception) {
|
||||
// XXX validate that this is a lossless conversion.
|
||||
// XXX should we just have separate functions for bridge, infra, and apps,
|
||||
// then drop this argument to save time?
|
||||
(void)exception;
|
||||
uint64_t tag = (uint64_t) JSValueToNumber(ctx, value, NULL);
|
||||
return tag;
|
||||
}
|
||||
|
||||
void addNativeTracingHooks(JSGlobalContextRef ctx) {
|
||||
installGlobalFunction(ctx, "nativeTraceBeginSection", nativeTraceBeginSection);
|
||||
installGlobalFunction(ctx, "nativeTraceEndSection", nativeTraceEndSection);
|
||||
installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy);
|
||||
installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy);
|
||||
installGlobalFunction(ctx, "nativeTraceBeginAsyncSection", nativeTraceBeginAsyncSection);
|
||||
installGlobalFunction(ctx, "nativeTraceEndAsyncSection", nativeTraceEndAsyncSection);
|
||||
installGlobalFunction(ctx, "nativeTraceAsyncSectionStage", nativeTraceAsyncSectionStage);
|
||||
|
||||
Reference in new issue
Block a user