mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Support JS Systrace on all platforms
Reviewed By: tadeuzagallo Differential Revision: D3234830 fbshipit-source-id: 94cc870d47d620c8bd8d35f83d0b017e5ddba90d
This commit is contained in:
committed by
Facebook Github Bot 8
parent
b7fe8e68be
commit
86f2eb18e5
@@ -48,6 +48,7 @@ elif THIS_IS_FBOBJC:
|
|||||||
],
|
],
|
||||||
**kwargs_add(
|
**kwargs_add(
|
||||||
kwargs,
|
kwargs,
|
||||||
|
preprocessor_flags = DEBUG_PREPROCESSOR_FLAGS,
|
||||||
deps = [
|
deps = [
|
||||||
'//xplat/folly:molly',
|
'//xplat/folly:molly',
|
||||||
]
|
]
|
||||||
@@ -57,6 +58,7 @@ elif THIS_IS_FBOBJC:
|
|||||||
LOCAL_HEADERS = [
|
LOCAL_HEADERS = [
|
||||||
'JSCTracing.h',
|
'JSCTracing.h',
|
||||||
'JSCLegacyProfiler.h',
|
'JSCLegacyProfiler.h',
|
||||||
|
'JSCLegacyTracing.h',
|
||||||
'JSCMemory.h',
|
'JSCMemory.h',
|
||||||
'JSCPerfStats.h',
|
'JSCPerfStats.h',
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -18,9 +18,13 @@
|
|||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "Value.h"
|
#include "Value.h"
|
||||||
|
|
||||||
#ifdef WITH_JSC_EXTRA_TRACING
|
#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG
|
||||||
#include "JSCTracing.h"
|
#include "JSCTracing.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_JSC_EXTRA_TRACING
|
||||||
#include "JSCLegacyProfiler.h"
|
#include "JSCLegacyProfiler.h"
|
||||||
|
#include "JSCLegacyTracing.h"
|
||||||
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -204,9 +208,13 @@ void JSCExecutor::initOnJSVMThread() {
|
|||||||
installGlobalFunction(m_context, "nativeLoggingHook", JSNativeHooks::loggingHook);
|
installGlobalFunction(m_context, "nativeLoggingHook", JSNativeHooks::loggingHook);
|
||||||
installGlobalFunction(m_context, "nativePerformanceNow", JSNativeHooks::nowHook);
|
installGlobalFunction(m_context, "nativePerformanceNow", JSNativeHooks::nowHook);
|
||||||
|
|
||||||
#ifdef WITH_JSC_EXTRA_TRACING
|
#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG
|
||||||
addNativeTracingHooks(m_context);
|
addNativeTracingHooks(m_context);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_JSC_EXTRA_TRACING
|
||||||
addNativeProfilingHooks(m_context);
|
addNativeProfilingHooks(m_context);
|
||||||
|
addNativeTracingLegacyHooks(m_context);
|
||||||
PerfLogging::installNativeHooks(m_context);
|
PerfLogging::installNativeHooks(m_context);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -301,6 +309,8 @@ void JSCExecutor::invokeCallback(const double callbackId, const folly::dynamic&
|
|||||||
}
|
}
|
||||||
|
|
||||||
void JSCExecutor::setGlobalVariable(const std::string& propName, const std::string& jsonValue) {
|
void JSCExecutor::setGlobalVariable(const std::string& propName, const std::string& jsonValue) {
|
||||||
|
// TODO mhorowitz: systrace this.
|
||||||
|
|
||||||
auto globalObject = JSContextGetGlobalObject(m_context);
|
auto globalObject = JSContextGetGlobalObject(m_context);
|
||||||
String jsPropertyName(propName.c_str());
|
String jsPropertyName(propName.c_str());
|
||||||
|
|
||||||
|
|||||||
73
ReactCommon/bridge/JSCLegacyTracing.cpp
Normal file
73
ReactCommon/bridge/JSCLegacyTracing.cpp
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||||
|
|
||||||
|
#ifdef WITH_JSC_EXTRA_TRACING
|
||||||
|
|
||||||
|
#include "JSCLegacyTracing.h"
|
||||||
|
|
||||||
|
#include <JavaScriptCore/JavaScript.h>
|
||||||
|
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
||||||
|
|
||||||
|
#include <fbsystrace.h>
|
||||||
|
|
||||||
|
#include "JSCHelpers.h"
|
||||||
|
#include "JSCTracing.h"
|
||||||
|
|
||||||
|
static const char *ENABLED_FBSYSTRACE_PROFILE_NAME = "__fbsystrace__";
|
||||||
|
|
||||||
|
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 = facebook::react::tracingTagFromJSValue(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 = facebook::react::tracingTagFromJSValue(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 {
|
||||||
|
|
||||||
|
void addNativeTracingLegacyHooks(JSGlobalContextRef ctx) {
|
||||||
|
installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy);
|
||||||
|
installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy);
|
||||||
|
}
|
||||||
|
|
||||||
|
} }
|
||||||
|
|
||||||
|
#endif
|
||||||
15
ReactCommon/bridge/JSCLegacyTracing.h
Normal file
15
ReactCommon/bridge/JSCLegacyTracing.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(WITH_JSC_EXTRA_TRACING)
|
||||||
|
|
||||||
|
#include <JavaScriptCore/JSContextRef.h>
|
||||||
|
namespace facebook {
|
||||||
|
namespace react {
|
||||||
|
|
||||||
|
void addNativeTracingLegacyHooks(JSGlobalContextRef ctx);
|
||||||
|
|
||||||
|
} }
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
// 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 <algorithm>
|
||||||
#include <JavaScriptCore/JavaScript.h>
|
#include <JavaScriptCore/JavaScript.h>
|
||||||
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
|
||||||
#include <fbsystrace.h>
|
#include <fbsystrace.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -12,20 +13,6 @@
|
|||||||
|
|
||||||
using std::min;
|
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(
|
static int64_t int64FromJSValue(
|
||||||
JSContextRef ctx,
|
JSContextRef ctx,
|
||||||
JSValueRef value,
|
JSValueRef value,
|
||||||
@@ -105,7 +92,7 @@ static JSValueRef nativeTraceBeginSection(
|
|||||||
return JSValueMakeUndefined(ctx);
|
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)) {
|
if (!fbsystrace_is_tracing(tag)) {
|
||||||
return JSValueMakeUndefined(ctx);
|
return JSValueMakeUndefined(ctx);
|
||||||
}
|
}
|
||||||
@@ -145,7 +132,7 @@ static JSValueRef nativeTraceEndSection(
|
|||||||
return JSValueMakeUndefined(ctx);
|
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)) {
|
if (!fbsystrace_is_tracing(tag)) {
|
||||||
return JSValueMakeUndefined(ctx);
|
return JSValueMakeUndefined(ctx);
|
||||||
}
|
}
|
||||||
@@ -189,7 +176,7 @@ static JSValueRef beginOrEndAsync(
|
|||||||
return JSValueMakeUndefined(ctx);
|
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)) {
|
if (!fbsystrace_is_tracing(tag)) {
|
||||||
return JSValueMakeUndefined(ctx);
|
return JSValueMakeUndefined(ctx);
|
||||||
}
|
}
|
||||||
@@ -252,7 +239,7 @@ static JSValueRef stageAsync(
|
|||||||
return JSValueMakeUndefined(ctx);
|
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)) {
|
if (!fbsystrace_is_tracing(tag)) {
|
||||||
return JSValueMakeUndefined(ctx);
|
return JSValueMakeUndefined(ctx);
|
||||||
}
|
}
|
||||||
@@ -398,7 +385,7 @@ static JSValueRef nativeTraceCounter(
|
|||||||
return JSValueMakeUndefined(ctx);
|
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)) {
|
if (!fbsystrace_is_tracing(tag)) {
|
||||||
return JSValueMakeUndefined(ctx);
|
return JSValueMakeUndefined(ctx);
|
||||||
}
|
}
|
||||||
@@ -414,60 +401,24 @@ static JSValueRef nativeTraceCounter(
|
|||||||
return JSValueMakeUndefined(ctx);
|
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 facebook {
|
||||||
namespace react {
|
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) {
|
void addNativeTracingHooks(JSGlobalContextRef ctx) {
|
||||||
installGlobalFunction(ctx, "nativeTraceBeginSection", nativeTraceBeginSection);
|
installGlobalFunction(ctx, "nativeTraceBeginSection", nativeTraceBeginSection);
|
||||||
installGlobalFunction(ctx, "nativeTraceEndSection", nativeTraceEndSection);
|
installGlobalFunction(ctx, "nativeTraceEndSection", nativeTraceEndSection);
|
||||||
installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy);
|
|
||||||
installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy);
|
|
||||||
installGlobalFunction(ctx, "nativeTraceBeginAsyncSection", nativeTraceBeginAsyncSection);
|
installGlobalFunction(ctx, "nativeTraceBeginAsyncSection", nativeTraceBeginAsyncSection);
|
||||||
installGlobalFunction(ctx, "nativeTraceEndAsyncSection", nativeTraceEndAsyncSection);
|
installGlobalFunction(ctx, "nativeTraceEndAsyncSection", nativeTraceEndAsyncSection);
|
||||||
installGlobalFunction(ctx, "nativeTraceAsyncSectionStage", nativeTraceAsyncSectionStage);
|
installGlobalFunction(ctx, "nativeTraceAsyncSectionStage", nativeTraceAsyncSectionStage);
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef WITH_JSC_EXTRA_TRACING
|
#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include <JavaScriptCore/JSContextRef.h>
|
#include <JavaScriptCore/JSContextRef.h>
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
|
uint64_t tracingTagFromJSValue(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
|
||||||
void addNativeTracingHooks(JSGlobalContextRef ctx);
|
void addNativeTracingHooks(JSGlobalContextRef ctx);
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|||||||
Reference in New Issue
Block a user