mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
cd2f8c567b
Summary: With the introduction of TurboModules, it would be beneficial to measure the setup time of these modules, as we currently have it in place for NativeModules. The instantiation of the TMs occurs in the `RCTTurboModuleManager`. In order to successfully measure the time it took to setup the module, we need to ensure that we don't take into account cached modules. As such, we need to: 1. Check if module is in `_turboModuleCache` a. Start mark for `RCTPLTurboModuleSetup` tag if not found 2. Get the TM via `[self provideTurboModule:]` 3. Check if module is in `_turboModuleCache` a. Stop mark for `RCTPLTurboModuleSetup` if we did not find module in cache prior to **step 2** and if it's now present in the cache. b. Notify about setup time if the above is true. 4. Return TM ## Changelog [iOS] [Added] - Gain insights on the the turbo module setup times by observing `RCTDidSetupModuleNotification`. The userInfo dictionary will contain the module name and setup time in milliseconds. These values can be extracted via `RCTDidSetupModuleNotificationModuleNameKey` and `RCTDidSetupModuleNotificationSetupTimeKey`. Pull Request resolved: https://github.com/facebook/react-native/pull/24732 Differential Revision: D15362088 Pulled By: RSNara fbshipit-source-id: e6a8044e4aba5a12ae63e9c7dbf707a17ec00180
132 lines
2.9 KiB
Objective-C
132 lines
2.9 KiB
Objective-C
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <QuartzCore/QuartzCore.h>
|
|
|
|
#import "RCTPerformanceLogger.h"
|
|
#import "RCTRootView.h"
|
|
#import "RCTLog.h"
|
|
#import "RCTProfile.h"
|
|
|
|
@interface RCTPerformanceLogger ()
|
|
{
|
|
int64_t _data[RCTPLSize][2];
|
|
NSUInteger _cookies[RCTPLSize];
|
|
}
|
|
|
|
@property (nonatomic, copy) NSArray<NSString *> *labelsForTags;
|
|
|
|
@end
|
|
|
|
@implementation RCTPerformanceLogger
|
|
|
|
- (instancetype)init
|
|
{
|
|
if (self = [super init]) {
|
|
_labelsForTags = @[
|
|
@"ScriptDownload",
|
|
@"ScriptExecution",
|
|
@"RAMBundleLoad",
|
|
@"RAMStartupCodeSize",
|
|
@"RAMStartupNativeRequires",
|
|
@"RAMStartupNativeRequiresCount",
|
|
@"RAMNativeRequires",
|
|
@"RAMNativeRequiresCount",
|
|
@"NativeModuleInit",
|
|
@"NativeModuleMainThread",
|
|
@"NativeModulePrepareConfig",
|
|
@"NativeModuleInjectConfig",
|
|
@"NativeModuleMainThreadUsesCount",
|
|
@"NativeModuleSetup",
|
|
@"TurboModuleSetup",
|
|
@"JSCWrapperOpenLibrary",
|
|
@"JSCExecutorSetup",
|
|
@"BridgeStartup",
|
|
@"RootViewTTI",
|
|
@"BundleSize",
|
|
];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)markStartForTag:(RCTPLTag)tag
|
|
{
|
|
#if RCT_PROFILE
|
|
if (RCTProfileIsProfiling()) {
|
|
NSString *label = _labelsForTags[tag];
|
|
_cookies[tag] = RCTProfileBeginAsyncEvent(RCTProfileTagAlways, label, nil);
|
|
}
|
|
#endif
|
|
_data[tag][0] = CACurrentMediaTime() * 1000;
|
|
_data[tag][1] = 0;
|
|
}
|
|
|
|
|
|
- (void)markStopForTag:(RCTPLTag)tag
|
|
{
|
|
#if RCT_PROFILE
|
|
if (RCTProfileIsProfiling()) {
|
|
NSString *label =_labelsForTags[tag];
|
|
RCTProfileEndAsyncEvent(RCTProfileTagAlways, @"native", _cookies[tag], label, @"RCTPerformanceLogger");
|
|
}
|
|
#endif
|
|
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);
|
|
}
|
|
}
|
|
|
|
- (void)setValue:(int64_t)value forTag:(RCTPLTag)tag
|
|
{
|
|
_data[tag][0] = 0;
|
|
_data[tag][1] = value;
|
|
}
|
|
|
|
- (void)addValue:(int64_t)value forTag:(RCTPLTag)tag
|
|
{
|
|
_data[tag][0] = 0;
|
|
_data[tag][1] += value;
|
|
}
|
|
|
|
- (void)appendStartForTag:(RCTPLTag)tag
|
|
{
|
|
_data[tag][0] = CACurrentMediaTime() * 1000;
|
|
}
|
|
|
|
- (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);
|
|
}
|
|
}
|
|
|
|
- (NSArray<NSNumber *> *)valuesForTags
|
|
{
|
|
NSMutableArray *result = [NSMutableArray array];
|
|
for (NSUInteger index = 0; index < RCTPLSize; index++) {
|
|
[result addObject:@(_data[index][0])];
|
|
[result addObject:@(_data[index][1])];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
- (int64_t)durationForTag:(RCTPLTag)tag
|
|
{
|
|
return _data[tag][1] - _data[tag][0];
|
|
}
|
|
|
|
- (int64_t)valueForTag:(RCTPLTag)tag
|
|
{
|
|
return _data[tag][1];
|
|
}
|
|
|
|
@end
|