2017-02-24 16:21:24 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTSamplingProfilerPackagerMethod.h"
|
|
|
|
|
|
|
|
#import <JavaScriptCore/JavaScriptCore.h>
|
|
|
|
|
|
|
|
#import <jschelpers/JavaScriptCore.h>
|
|
|
|
|
2017-06-15 18:52:08 +00:00
|
|
|
#import "RCTJSEnvironment.h"
|
2017-02-24 16:21:24 +00:00
|
|
|
#import "RCTLog.h"
|
|
|
|
|
|
|
|
#if RCT_DEV // Only supported in dev mode
|
|
|
|
|
|
|
|
@implementation RCTSamplingProfilerPackagerMethod {
|
2017-06-15 18:52:08 +00:00
|
|
|
__weak id<RCTJSEnvironment> _jsEnvironment;
|
2017-02-24 16:21:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 18:52:08 +00:00
|
|
|
- (instancetype)initWithJSEnvironment:(id<RCTJSEnvironment>)jsEnvironment
|
2017-02-24 16:21:24 +00:00
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
2017-06-15 18:52:08 +00:00
|
|
|
_jsEnvironment = jsEnvironment;
|
2017-02-24 16:21:24 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-03-23 18:25:28 +00:00
|
|
|
- (void)handleRequest:(__unused id)params withResponder:(RCTPackagerClientResponder *)responder
|
2017-02-24 16:21:24 +00:00
|
|
|
{
|
2017-06-15 18:52:08 +00:00
|
|
|
JSGlobalContextRef globalContext = _jsEnvironment.jsContextRef;
|
2017-02-24 16:21:24 +00:00
|
|
|
if (!JSC_JSSamplingProfilerEnabled(globalContext)) {
|
|
|
|
[responder respondWithError:@"The JSSamplingProfiler is disabled. See 'iOS specific setup' section here https://fburl.com/u4lw7xeq for some help"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// JSPokeSamplingProfiler() toggles the profiling process
|
|
|
|
JSValueRef jsResult = JSC_JSPokeSamplingProfiler(globalContext);
|
|
|
|
if (JSC_JSValueGetType(globalContext, jsResult) == kJSTypeNull) {
|
|
|
|
[responder respondWithResult:@"started"];
|
|
|
|
} else {
|
2017-06-15 18:52:08 +00:00
|
|
|
JSContext *context = _jsEnvironment.jsContext;
|
2017-02-24 16:21:24 +00:00
|
|
|
NSString *results = [[JSC_JSValue(globalContext) valueWithJSValueRef:jsResult inContext:context] toObject];
|
|
|
|
[responder respondWithResult:results];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 18:25:28 +00:00
|
|
|
- (void)handleNotification:(__unused id)params
|
2017-02-24 16:21:24 +00:00
|
|
|
{
|
|
|
|
RCTLogError(@"%@ does not implement onNotification", [self class]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#endif
|