2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2021-12-31 02:08:43 +03:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2015-06-20 00:59:42 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03: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-20 00:59:42 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import <QuartzCore/QuartzCore.h>
|
|
|
|
|
2015-10-13 13:43:43 +03:00
|
|
|
#import "RCTLog.h"
|
2020-03-09 08:58:01 +03:00
|
|
|
#import "RCTPerformanceLogger.h"
|
2021-12-09 01:49:16 +03:00
|
|
|
#import "RCTPerformanceLoggerLabels.h"
|
2016-03-15 15:40:09 +03:00
|
|
|
#import "RCTProfile.h"
|
2020-03-09 08:58:01 +03:00
|
|
|
#import "RCTRootView.h"
|
2015-06-20 00:59:42 +03:00
|
|
|
|
2020-03-09 08:58:01 +03:00
|
|
|
@interface RCTPerformanceLogger () {
|
2016-07-07 17:20:03 +03:00
|
|
|
int64_t _data[RCTPLSize][2];
|
2021-12-09 01:49:16 +03:00
|
|
|
NSInteger _cookies[RCTPLSize];
|
2015-10-21 20:53:35 +03:00
|
|
|
}
|
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
@end
|
2016-03-15 15:40:09 +03:00
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
@implementation RCTPerformanceLogger
|
2015-06-20 00:59:42 +03:00
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
- (void)markStartForTag:(RCTPLTag)tag
|
|
|
|
{
|
2016-08-02 09:51:28 +03:00
|
|
|
#if RCT_PROFILE
|
2016-07-07 17:20:03 +03:00
|
|
|
if (RCTProfileIsProfiling()) {
|
2021-12-09 01:49:16 +03:00
|
|
|
NSString *label = RCTPLLabelForTag(tag);
|
2016-07-07 17:20:03 +03:00
|
|
|
_cookies[tag] = RCTProfileBeginAsyncEvent(RCTProfileTagAlways, label, nil);
|
|
|
|
}
|
2016-08-02 09:51:28 +03:00
|
|
|
#endif
|
2016-07-07 17:20:03 +03:00
|
|
|
_data[tag][0] = CACurrentMediaTime() * 1000;
|
|
|
|
_data[tag][1] = 0;
|
|
|
|
}
|
2015-06-20 00:59:42 +03:00
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
- (void)markStopForTag:(RCTPLTag)tag
|
|
|
|
{
|
2016-08-02 09:51:28 +03:00
|
|
|
#if RCT_PROFILE
|
2016-07-07 17:20:03 +03:00
|
|
|
if (RCTProfileIsProfiling()) {
|
2021-12-09 01:49:16 +03:00
|
|
|
NSString *label = RCTPLLabelForTag(tag);
|
2016-09-05 21:11:37 +03:00
|
|
|
RCTProfileEndAsyncEvent(RCTProfileTagAlways, @"native", _cookies[tag], label, @"RCTPerformanceLogger");
|
2016-07-07 17:20:03 +03:00
|
|
|
}
|
2016-08-02 09:51:28 +03:00
|
|
|
#endif
|
2016-07-07 17:20:03 +03: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-20 00:59:42 +03:00
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
- (void)setValue:(int64_t)value forTag:(RCTPLTag)tag
|
|
|
|
{
|
|
|
|
_data[tag][0] = 0;
|
|
|
|
_data[tag][1] = value;
|
|
|
|
}
|
2015-06-20 00:59:42 +03:00
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
- (void)addValue:(int64_t)value forTag:(RCTPLTag)tag
|
2016-05-04 17:06:09 +03:00
|
|
|
{
|
2016-07-07 17:20:03 +03:00
|
|
|
_data[tag][0] = 0;
|
|
|
|
_data[tag][1] += value;
|
2016-05-04 17:06:09 +03:00
|
|
|
}
|
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
- (void)appendStartForTag:(RCTPLTag)tag
|
2015-06-20 00:59:42 +03:00
|
|
|
{
|
2016-07-07 17:20:03 +03:00
|
|
|
_data[tag][0] = CACurrentMediaTime() * 1000;
|
|
|
|
}
|
2015-11-25 14:09:00 +03:00
|
|
|
|
2016-07-07 17:20:03 +03: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-20 00:59:42 +03:00
|
|
|
}
|
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
- (NSArray<NSNumber *> *)valuesForTags
|
2015-06-20 00:59:42 +03:00
|
|
|
{
|
2016-07-07 17:20:03 +03: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-20 00:59:42 +03:00
|
|
|
}
|
|
|
|
|
2016-07-07 17:20:03 +03:00
|
|
|
- (int64_t)durationForTag:(RCTPLTag)tag
|
2015-06-20 00:59:42 +03:00
|
|
|
{
|
2016-07-07 17:20:03 +03:00
|
|
|
return _data[tag][1] - _data[tag][0];
|
|
|
|
}
|
2015-07-09 17:26:54 +03:00
|
|
|
|
2016-07-12 15:51:56 +03:00
|
|
|
- (int64_t)valueForTag:(RCTPLTag)tag
|
2016-07-07 17:20:03 +03:00
|
|
|
{
|
|
|
|
return _data[tag][1];
|
2015-06-20 00:59:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|