2015-06-19 21:59:42 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-06-19 21:59:42 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-06-19 21:59:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import <QuartzCore/QuartzCore.h>
|
|
|
|
|
|
|
|
#import "RCTPerformanceLogger.h"
|
|
|
|
#import "RCTRootView.h"
|
2015-10-13 10:43:43 +00:00
|
|
|
#import "RCTLog.h"
|
2016-03-15 12:40:09 +00:00
|
|
|
#import "RCTProfile.h"
|
2015-06-19 21:59:42 +00:00
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
@interface RCTPerformanceLogger ()
|
2015-10-21 17:53:35 +00:00
|
|
|
{
|
2016-07-07 14:20:03 +00:00
|
|
|
int64_t _data[RCTPLSize][2];
|
|
|
|
NSUInteger _cookies[RCTPLSize];
|
2015-10-21 17:53:35 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
@property (nonatomic, copy) NSArray<NSString *> *labelsForTags;
|
2016-04-01 14:24:40 +00:00
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
@end
|
2016-03-15 12:40:09 +00:00
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
@implementation RCTPerformanceLogger
|
2015-06-19 21:59:42 +00:00
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (instancetype)init
|
2015-10-30 23:51:48 +00:00
|
|
|
{
|
2016-07-07 14:20:03 +00:00
|
|
|
if (self = [super init]) {
|
|
|
|
_labelsForTags = @[
|
2016-03-15 12:40:09 +00:00
|
|
|
@"ScriptDownload",
|
|
|
|
@"ScriptExecution",
|
2016-04-01 14:24:40 +00:00
|
|
|
@"RAMBundleLoad",
|
|
|
|
@"RAMStartupCodeSize",
|
2016-09-09 22:22:20 +00:00
|
|
|
@"RAMStartupNativeRequires",
|
|
|
|
@"RAMStartupNativeRequiresCount",
|
2016-04-01 18:08:19 +00:00
|
|
|
@"RAMNativeRequires",
|
2016-04-01 14:24:40 +00:00
|
|
|
@"RAMNativeRequiresCount",
|
2016-03-15 12:40:09 +00:00
|
|
|
@"NativeModuleInit",
|
|
|
|
@"NativeModuleMainThread",
|
|
|
|
@"NativeModulePrepareConfig",
|
|
|
|
@"NativeModuleInjectConfig",
|
2016-03-17 14:26:54 +00:00
|
|
|
@"NativeModuleMainThreadUsesCount",
|
2016-05-31 19:50:48 +00:00
|
|
|
@"JSCWrapperOpenLibrary",
|
2016-03-15 12:40:09 +00:00
|
|
|
@"JSCExecutorSetup",
|
2016-04-01 14:24:40 +00:00
|
|
|
@"BridgeStartup",
|
2016-03-15 12:40:09 +00:00
|
|
|
@"RootViewTTI",
|
|
|
|
@"BundleSize",
|
|
|
|
];
|
2016-07-07 14:20:03 +00:00
|
|
|
}
|
|
|
|
return self;
|
2015-10-30 23:51:48 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (void)markStartForTag:(RCTPLTag)tag
|
|
|
|
{
|
2016-08-02 06:51:28 +00:00
|
|
|
#if RCT_PROFILE
|
2016-07-07 14:20:03 +00:00
|
|
|
if (RCTProfileIsProfiling()) {
|
|
|
|
NSString *label = _labelsForTags[tag];
|
|
|
|
_cookies[tag] = RCTProfileBeginAsyncEvent(RCTProfileTagAlways, label, nil);
|
|
|
|
}
|
2016-08-02 06:51:28 +00:00
|
|
|
#endif
|
2016-07-07 14:20:03 +00:00
|
|
|
_data[tag][0] = CACurrentMediaTime() * 1000;
|
|
|
|
_data[tag][1] = 0;
|
|
|
|
}
|
2015-06-19 21:59:42 +00:00
|
|
|
|
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (void)markStopForTag:(RCTPLTag)tag
|
|
|
|
{
|
2016-08-02 06:51:28 +00:00
|
|
|
#if RCT_PROFILE
|
2016-07-07 14:20:03 +00:00
|
|
|
if (RCTProfileIsProfiling()) {
|
|
|
|
NSString *label =_labelsForTags[tag];
|
2016-09-05 18:11:37 +00:00
|
|
|
RCTProfileEndAsyncEvent(RCTProfileTagAlways, @"native", _cookies[tag], label, @"RCTPerformanceLogger");
|
2016-07-07 14:20:03 +00:00
|
|
|
}
|
2016-08-02 06:51:28 +00:00
|
|
|
#endif
|
2016-07-07 14:20:03 +00:00
|
|
|
if (_data[tag][0] != 0 && _data[tag][1] == 0) {
|
|
|
|
_data[tag][1] = CACurrentMediaTime() * 1000;
|
|
|
|
} else {
|
|
|
|
RCTLogInfo(@"Unbalanced calls start/end for tag %li", (unsigned long)tag);
|
|
|
|
}
|
|
|
|
}
|
2015-06-19 21:59:42 +00:00
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (void)setValue:(int64_t)value forTag:(RCTPLTag)tag
|
|
|
|
{
|
|
|
|
_data[tag][0] = 0;
|
|
|
|
_data[tag][1] = value;
|
|
|
|
}
|
2015-06-19 21:59:42 +00:00
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (void)addValue:(int64_t)value forTag:(RCTPLTag)tag
|
2016-05-04 14:06:09 +00:00
|
|
|
{
|
2016-07-07 14:20:03 +00:00
|
|
|
_data[tag][0] = 0;
|
|
|
|
_data[tag][1] += value;
|
2016-05-04 14:06:09 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (void)appendStartForTag:(RCTPLTag)tag
|
2015-06-19 21:59:42 +00:00
|
|
|
{
|
2016-07-07 14:20:03 +00:00
|
|
|
_data[tag][0] = CACurrentMediaTime() * 1000;
|
|
|
|
}
|
2015-11-25 11:09:00 +00:00
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (void)appendStopForTag:(RCTPLTag)tag
|
|
|
|
{
|
|
|
|
if (_data[tag][0] != 0) {
|
|
|
|
_data[tag][1] += CACurrentMediaTime() * 1000 - _data[tag][0];
|
|
|
|
_data[tag][0] = 0;
|
|
|
|
} else {
|
|
|
|
RCTLogInfo(@"Unbalanced calls start/end for tag %li", (unsigned long)tag);
|
|
|
|
}
|
2015-06-19 21:59:42 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (NSArray<NSNumber *> *)valuesForTags
|
2015-06-19 21:59:42 +00:00
|
|
|
{
|
2016-07-07 14:20:03 +00:00
|
|
|
NSMutableArray *result = [NSMutableArray array];
|
|
|
|
for (NSUInteger index = 0; index < RCTPLSize; index++) {
|
|
|
|
[result addObject:@(_data[index][0])];
|
|
|
|
[result addObject:@(_data[index][1])];
|
|
|
|
}
|
|
|
|
return result;
|
2015-06-19 21:59:42 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 14:20:03 +00:00
|
|
|
- (int64_t)durationForTag:(RCTPLTag)tag
|
2015-06-19 21:59:42 +00:00
|
|
|
{
|
2016-07-07 14:20:03 +00:00
|
|
|
return _data[tag][1] - _data[tag][0];
|
|
|
|
}
|
2015-07-09 14:26:54 +00:00
|
|
|
|
2016-07-12 12:51:56 +00:00
|
|
|
- (int64_t)valueForTag:(RCTPLTag)tag
|
2016-07-07 14:20:03 +00:00
|
|
|
{
|
|
|
|
return _data[tag][1];
|
2015-06-19 21:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|