Make js perf API available to js

Reviewed By: tadeuzagallo

Differential Revision: D3011680

fb-gh-sync-id: 051864689af0b9041318cc314d339ae841fe35aa
shipit-source-id: 051864689af0b9041318cc314d339ae841fe35aa
This commit is contained in:
Michał Gregorczyk 2016-03-08 10:14:57 -08:00 committed by Facebook Github Bot 6
parent 9d09efdd53
commit 6e3710f36b
4 changed files with 87 additions and 0 deletions

View File

@ -54,6 +54,7 @@ react_library(
'MethodCall.cpp',
'JSCHelpers.cpp',
'JSCExecutor.cpp',
'JSCPerfStats.cpp',
'JSCTracing.cpp',
'JSCMemory.cpp',
'JSCLegacyProfiler.cpp',
@ -63,6 +64,7 @@ react_library(
'JSCTracing.h',
'JSCLegacyProfiler.h',
'JSCMemory.h',
'JSCPerfStats.h',
],
exported_headers = [
'Bridge.h',

View File

@ -40,6 +40,10 @@ using fbsystrace::FbSystraceSection;
#include <jsc_config_android.h>
#endif
#ifdef JSC_HAS_PERF_STATS_API
#include "JSCPerfStats.h"
#endif
static const int64_t NANOSECONDS_IN_SECOND = 1000000000LL;
static const int64_t NANOSECONDS_IN_MILLISECOND = 1000000LL;
@ -179,6 +183,10 @@ void JSCExecutor::initOnJSVMThread() {
#ifdef WITH_FB_MEMORY_PROFILING
addNativeMemoryHooks(m_context);
#endif
#ifdef JSC_HAS_PERF_STATS_API
addJSCPerfStatsHooks(m_context);
#endif
}
void JSCExecutor::terminateOnJSVMThread() {

View File

@ -0,0 +1,65 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#include "JSCPerfStats.h"
#ifdef JSC_HAS_PERF_STATS_API
#include <JavaScriptCore/JSPerfStats.h>
#include <JavaScriptCore/JSValueRef.h>
#include "JSCHelpers.h"
#include "Value.h"
static JSValueRef nativeGetHeapStats(
JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception) {
JSHeapStats heapStats = {0};
JSGetHeapStats(ctx, &heapStats);
auto result = facebook::react::Object::create(ctx);
result.setProperty("size", {ctx, JSValueMakeNumber(ctx, heapStats.size)});
result.setProperty("extra_size", {ctx, JSValueMakeNumber(ctx, heapStats.extraSize)});
result.setProperty("capacity", {ctx, JSValueMakeNumber(ctx, heapStats.capacity)});
result.setProperty("object_count", {ctx, JSValueMakeNumber(ctx, heapStats.objectCount)});
return (JSObjectRef) result;
}
static JSValueRef nativeGetGCStats(
JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception) {
JSGCStats gcStats = {0};
JSGetGCStats(ctx, &gcStats);
auto result = facebook::react::Object::create(ctx);
result.setProperty(
"last_full_gc_length",
{ctx, JSValueMakeNumber(ctx, gcStats.lastFullGCLength)});
result.setProperty(
"last_eden_gc_length",
{ctx, JSValueMakeNumber(ctx, gcStats.lastEdenGCLength)});
return (JSObjectRef) result;
}
#endif
namespace facebook {
namespace react {
void addJSCPerfStatsHooks(JSGlobalContextRef ctx) {
#ifdef JSC_HAS_PERF_STATS_API
installGlobalFunction(ctx, "nativeGetHeapStats", nativeGetHeapStats);
installGlobalFunction(ctx, "nativeGetGCStats", nativeGetGCStats);
#endif
}
} }

View File

@ -0,0 +1,12 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
#include <JavaScriptCore/JSContextRef.h>
namespace facebook {
namespace react {
void addJSCPerfStatsHooks(JSGlobalContextRef ctx);
} }