2015-06-19 21:59:42 +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 <QuartzCore/QuartzCore.h>
|
|
|
|
|
|
|
|
#import "RCTPerformanceLogger.h"
|
|
|
|
#import "RCTRootView.h"
|
2015-10-13 10:43:43 +00:00
|
|
|
#import "RCTLog.h"
|
2015-06-19 21:59:42 +00:00
|
|
|
|
|
|
|
static int64_t RCTPLData[RCTPLSize][2] = {};
|
|
|
|
|
|
|
|
void RCTPerformanceLoggerStart(RCTPLTag tag)
|
|
|
|
{
|
|
|
|
RCTPLData[tag][0] = CACurrentMediaTime() * 1000;
|
2015-10-13 10:43:43 +00:00
|
|
|
RCTPLData[tag][1] = 0;
|
2015-06-19 21:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RCTPerformanceLoggerEnd(RCTPLTag tag)
|
|
|
|
{
|
2015-10-13 10:43:43 +00:00
|
|
|
if (RCTPLData[tag][0] != 0 && RCTPLData[tag][1] == 0) {
|
|
|
|
RCTPLData[tag][1] = CACurrentMediaTime() * 1000;
|
|
|
|
} else {
|
|
|
|
RCTLogInfo(@"Unbalanced calls start/end for tag %li", (unsigned long)tag);
|
|
|
|
}
|
2015-06-19 21:59:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-21 17:53:35 +00:00
|
|
|
void RCTPerformanceLoggerSet(RCTPLTag tag, int64_t value)
|
|
|
|
{
|
|
|
|
RCTPLData[tag][0] = 0;
|
|
|
|
RCTPLData[tag][1] = value;
|
|
|
|
}
|
|
|
|
|
2015-11-03 22:45:46 +00:00
|
|
|
NSArray<NSNumber *> *RCTPerformanceLoggerOutput(void)
|
2015-06-19 21:59:42 +00:00
|
|
|
{
|
|
|
|
return @[
|
2015-08-21 18:33:04 +00:00
|
|
|
@(RCTPLData[RCTPLScriptDownload][0]),
|
|
|
|
@(RCTPLData[RCTPLScriptDownload][1]),
|
|
|
|
@(RCTPLData[RCTPLScriptExecution][0]),
|
|
|
|
@(RCTPLData[RCTPLScriptExecution][1]),
|
|
|
|
@(RCTPLData[RCTPLNativeModuleInit][0]),
|
|
|
|
@(RCTPLData[RCTPLNativeModuleInit][1]),
|
2015-10-08 15:41:55 +00:00
|
|
|
@(RCTPLData[RCTPLNativeModulePrepareConfig][0]),
|
|
|
|
@(RCTPLData[RCTPLNativeModulePrepareConfig][1]),
|
2015-10-05 17:53:33 +00:00
|
|
|
@(RCTPLData[RCTPLNativeModuleInjectConfig][0]),
|
|
|
|
@(RCTPLData[RCTPLNativeModuleInjectConfig][1]),
|
2015-08-21 18:33:04 +00:00
|
|
|
@(RCTPLData[RCTPLTTI][0]),
|
|
|
|
@(RCTPLData[RCTPLTTI][1]),
|
2015-10-21 17:53:35 +00:00
|
|
|
@(RCTPLData[RCTPLBundleSize][0]),
|
|
|
|
@(RCTPLData[RCTPLBundleSize][1]),
|
2015-06-19 21:59:42 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-10-30 23:51:48 +00:00
|
|
|
NSArray *RCTPerformanceLoggerLabels(void)
|
|
|
|
{
|
|
|
|
return @[
|
|
|
|
@"ScriptDownload",
|
|
|
|
@"ScriptExecution",
|
|
|
|
@"NativeModuleInit",
|
|
|
|
@"NativeModulePrepareConfig",
|
|
|
|
@"NativeModuleInjectConfig",
|
|
|
|
@"TTI",
|
|
|
|
@"BundleSize",
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:59:42 +00:00
|
|
|
@interface RCTPerformanceLogger : NSObject <RCTBridgeModule>
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTPerformanceLogger
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
if ((self = [super init])) {
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(sendTimespans)
|
|
|
|
name:RCTContentDidAppearNotification
|
|
|
|
object:nil];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendTimespans
|
|
|
|
{
|
2015-07-09 14:26:54 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
|
2015-06-19 21:59:42 +00:00
|
|
|
[_bridge enqueueJSCall:@"PerformanceLogger.addTimespans" args:@[
|
|
|
|
RCTPerformanceLoggerOutput(),
|
2015-10-30 23:51:48 +00:00
|
|
|
RCTPerformanceLoggerLabels(),
|
2015-06-19 21:59:42 +00:00
|
|
|
]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|