diff --git a/BUCK b/BUCK index 5c0d1f00391d1d..8ff9dac75560e8 100644 --- a/BUCK +++ b/BUCK @@ -287,9 +287,11 @@ REACT_PUBLIC_HEADERS = { "React/RCTModuleMethod.h": RCTBASE_PATH + "RCTModuleMethod.h", "React/RCTMultipartStreamReader.h": RCTBASE_PATH + "RCTMultipartStreamReader.h", "React/RCTNullability.h": RCTBASE_PATH + "RCTNullability.h", + "React/RCTPLTag.h": RCTBASE_PATH + "RCTPLTag.h", "React/RCTPackagerClient.h": RCTDEVSUPPORT_PATH + "RCTPackagerClient.h", "React/RCTPackagerConnection.h": RCTDEVSUPPORT_PATH + "RCTPackagerConnection.h", "React/RCTPerformanceLogger.h": RCTBASE_PATH + "RCTPerformanceLogger.h", + "React/RCTPerformanceLoggerLabels.h": RCTBASE_PATH + "RCTPerformanceLoggerLabels.h", "React/RCTPointerEvents.h": RCTVIEWS_PATH + "RCTPointerEvents.h", "React/RCTProfile.h": "React/Profiler/RCTProfile.h", "React/RCTPushNotificationManager.h": RCTLIB_PATH + "PushNotificationIOS/RCTPushNotificationManager.h", diff --git a/React/Base/RCTPLTag.h b/React/Base/RCTPLTag.h new file mode 100644 index 00000000000000..434948eff1aab5 --- /dev/null +++ b/React/Base/RCTPLTag.h @@ -0,0 +1,29 @@ +/* + * 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. + */ + +typedef NS_ENUM(NSInteger, RCTPLTag) { + RCTPLScriptDownload = 0, + RCTPLScriptExecution, + RCTPLRAMBundleLoad, + RCTPLRAMStartupCodeSize, + RCTPLRAMStartupNativeRequires, + RCTPLRAMStartupNativeRequiresCount, + RCTPLRAMNativeRequires, + RCTPLRAMNativeRequiresCount, + RCTPLNativeModuleInit, + RCTPLNativeModuleMainThread, + RCTPLNativeModulePrepareConfig, + RCTPLNativeModuleMainThreadUsesCount, + RCTPLNativeModuleSetup, + RCTPLTurboModuleSetup, + RCTPLJSCWrapperOpenLibrary, + RCTPLBridgeStartup, + RCTPLTTI, + RCTPLBundleSize, + RCTPLReactInstanceInit, + RCTPLSize // This is used to count the size +}; diff --git a/React/Base/RCTPerformanceLogger.h b/React/Base/RCTPerformanceLogger.h index bb4e40db2e3e47..d5e7313a9bf674 100644 --- a/React/Base/RCTPerformanceLogger.h +++ b/React/Base/RCTPerformanceLogger.h @@ -6,30 +6,7 @@ */ #import - -// Keep this in sync with _labelsForTags -typedef NS_ENUM(NSInteger, RCTPLTag) { - RCTPLScriptDownload = 0, - RCTPLScriptExecution, - RCTPLRAMBundleLoad, - RCTPLRAMStartupCodeSize, - RCTPLRAMStartupNativeRequires, - RCTPLRAMStartupNativeRequiresCount, - RCTPLRAMNativeRequires, - RCTPLRAMNativeRequiresCount, - RCTPLNativeModuleInit, - RCTPLNativeModuleMainThread, - RCTPLNativeModulePrepareConfig, - RCTPLNativeModuleMainThreadUsesCount, - RCTPLNativeModuleSetup, - RCTPLTurboModuleSetup, - RCTPLJSCWrapperOpenLibrary, - RCTPLBridgeStartup, - RCTPLTTI, - RCTPLBundleSize, - RCTPLReactInstanceInit, - RCTPLSize // This is used to count the size -}; +#import "RCTPLTag.h" @interface RCTPerformanceLogger : NSObject @@ -95,10 +72,4 @@ typedef NS_ENUM(NSInteger, RCTPLTag) { */ - (int64_t)valueForTag:(RCTPLTag)tag; -/** - * Returns an array with values for all tags. - * Use RCTPLTag to go over the array. - */ -- (NSArray *)labelsForTags; - @end diff --git a/React/Base/RCTPerformanceLogger.m b/React/Base/RCTPerformanceLogger.m index ee71be042a9503..fbec3c920738ac 100644 --- a/React/Base/RCTPerformanceLogger.m +++ b/React/Base/RCTPerformanceLogger.m @@ -9,54 +9,24 @@ #import "RCTLog.h" #import "RCTPerformanceLogger.h" +#import "RCTPerformanceLoggerLabels.h" #import "RCTProfile.h" #import "RCTRootView.h" @interface RCTPerformanceLogger () { int64_t _data[RCTPLSize][2]; - NSUInteger _cookies[RCTPLSize]; + NSInteger _cookies[RCTPLSize]; } -@property (nonatomic, copy) NSArray *labelsForTags; - @end @implementation RCTPerformanceLogger -- (instancetype)init -{ - if (self = [super init]) { - // Keep this in sync with RCTPLTag - _labelsForTags = @[ - @"ScriptDownload", - @"ScriptExecution", - @"RAMBundleLoad", - @"RAMStartupCodeSize", - @"RAMStartupNativeRequires", - @"RAMStartupNativeRequiresCount", - @"RAMNativeRequires", - @"RAMNativeRequiresCount", - @"NativeModuleInit", - @"NativeModuleMainThread", - @"NativeModulePrepareConfig", - @"NativeModuleMainThreadUsesCount", - @"NativeModuleSetup", - @"TurboModuleSetup", - @"JSCWrapperOpenLibrary", - @"BridgeStartup", - @"RootViewTTI", - @"BundleSize", - @"ReactInstanceInit", - ]; - } - return self; -} - - (void)markStartForTag:(RCTPLTag)tag { #if RCT_PROFILE if (RCTProfileIsProfiling()) { - NSString *label = _labelsForTags[tag]; + NSString *label = RCTPLLabelForTag(tag); _cookies[tag] = RCTProfileBeginAsyncEvent(RCTProfileTagAlways, label, nil); } #endif @@ -68,7 +38,7 @@ - (void)markStopForTag:(RCTPLTag)tag { #if RCT_PROFILE if (RCTProfileIsProfiling()) { - NSString *label = _labelsForTags[tag]; + NSString *label = RCTPLLabelForTag(tag); RCTProfileEndAsyncEvent(RCTProfileTagAlways, @"native", _cookies[tag], label, @"RCTPerformanceLogger"); } #endif diff --git a/React/Base/RCTPerformanceLoggerLabels.h b/React/Base/RCTPerformanceLoggerLabels.h new file mode 100644 index 00000000000000..42d9003f087af6 --- /dev/null +++ b/React/Base/RCTPerformanceLoggerLabels.h @@ -0,0 +1,12 @@ +/* + * 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 +#import "RCTPLTag.h" + +// Return the string label for the enum RCTPLTag for performance logging +__attribute__((used)) RCT_EXTERN NSString *RCTPLLabelForTag(RCTPLTag tag); diff --git a/React/Base/RCTPerformanceLoggerLabels.m b/React/Base/RCTPerformanceLoggerLabels.m new file mode 100644 index 00000000000000..92c6ddc1d83994 --- /dev/null +++ b/React/Base/RCTPerformanceLoggerLabels.m @@ -0,0 +1,56 @@ +/* + * 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 "RCTPerformanceLoggerLabels.h" +#import + +NSString *RCTPLLabelForTag(RCTPLTag tag) +{ + switch (tag) { + case RCTPLScriptDownload: + return @"ScriptDownload"; + case RCTPLScriptExecution: + return @"ScriptExecution"; + case RCTPLRAMBundleLoad: + return @"RAMBundleLoad"; + case RCTPLRAMStartupCodeSize: + return @"RAMStartupCodeSize"; + case RCTPLRAMStartupNativeRequires: + return @"RAMStartupNativeRequires"; + case RCTPLRAMStartupNativeRequiresCount: + return @"RAMStartupNativeRequiresCount"; + case RCTPLRAMNativeRequires: + return @"RAMNativeRequires"; + case RCTPLRAMNativeRequiresCount: + return @"RAMNativeRequiresCount"; + case RCTPLNativeModuleInit: + return @"NativeModuleInit"; + case RCTPLNativeModuleMainThread: + return @"NativeModuleMainThread"; + case RCTPLNativeModulePrepareConfig: + return @"NativeModulePrepareConfig"; + case RCTPLNativeModuleMainThreadUsesCount: + return @"NativeModuleMainThreadUsesCount"; + case RCTPLNativeModuleSetup: + return @"NativeModuleSetup"; + case RCTPLTurboModuleSetup: + return @"TurboModuleSetup"; + case RCTPLJSCWrapperOpenLibrary: + return @"JSCWrapperOpenLibrary"; + case RCTPLBridgeStartup: + return @"BridgeStartup"; + case RCTPLTTI: + return @"RootViewTTI"; + case RCTPLBundleSize: + return @"BundleSize"; + case RCTPLReactInstanceInit: + return @"ReactInstanceInit"; + case RCTPLSize: // Only used to count enum size + RCTAssert(NO, @"RCTPLSize should not be used to track performance timestamps."); + return nil; + } +} diff --git a/React/CoreModules/RCTPerfMonitor.mm b/React/CoreModules/RCTPerfMonitor.mm index a28305f7f7c0c1..0065cdee32a350 100644 --- a/React/CoreModules/RCTPerfMonitor.mm +++ b/React/CoreModules/RCTPerfMonitor.mm @@ -24,6 +24,7 @@ #import #import #import +#import #import #import #import @@ -40,6 +41,8 @@ typedef BOOL (*RCTJSCSetOptionType)(const char *); +NSArray *LabelsForRCTPerformanceLoggerTags(); + static BOOL RCTJSCSetOption(const char *option) { static RCTJSCSetOptionType setOption; @@ -515,7 +518,7 @@ - (void)loadPerformanceLoggerData NSMutableArray *data = [NSMutableArray new]; RCTPerformanceLogger *performanceLogger = [_bridge performanceLogger]; NSArray *values = [performanceLogger valuesForTags]; - for (NSString *label in [performanceLogger labelsForTags]) { + for (NSString *label in LabelsForRCTPerformanceLoggerTags()) { long long value = values[i + 1].longLongValue - values[i].longLongValue; NSString *unit = @"ms"; if ([label hasSuffix:@"Size"]) { @@ -572,6 +575,15 @@ - (CGFloat)tableView:(__unused UITableView *)tableView heightForRowAtIndexPath:( @end +NSArray *LabelsForRCTPerformanceLoggerTags() +{ + NSMutableArray *labels = [NSMutableArray new]; + for (int i = 0; i < RCTPLSize; i++) { + [labels addObject:RCTPLLabelForTag((RCTPLTag)i)]; + } + return labels; +} + #endif Class RCTPerfMonitorCls(void) diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 23dbb9fc53a505..a223c62690e02a 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -891,7 +891,7 @@ SPEC CHECKSUMS: CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662 FBLazyVector: b81a2b70c72d8b0aefb652cea22c11e9ffd02949 - FBReactNativeSpec: 755b7fee1b08aefd74fb2fa9f7312b253719d536 + FBReactNativeSpec: 5bd61f19eb8d9ab489a9f89f6e862767fbb6cced Flipper: 30e8eeeed6abdc98edaf32af0cda2f198be4b733 Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c @@ -904,7 +904,7 @@ SPEC CHECKSUMS: fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 glog: c10b67b343303f51715e5c5eedb18a41402f350a libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 - MyNativeView: 4eaeecdc16568e81e702ef0a901127823d1ddc80 + MyNativeView: 68ba0ad4bcfc2bc9b776a346c70ca9d19a2f2542 OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b RCT-Folly: 803a9cfd78114b2ec0f140cfa6fa2a6bafb2d685 RCTRequired: af2d6080a4b9ba0885b28ca78879a92066c71cab @@ -934,10 +934,10 @@ SPEC CHECKSUMS: React-RCTTest: 12bbd7fc2e72bd9920dc7286c5b8ef96639582b6 React-RCTText: e9146b2c0550a83d1335bfe2553760070a2d75c7 React-RCTVibration: 50be9c390f2da76045ef0dfdefa18b9cf9f35cfa - React-rncore: d09af3a25cbff0b484776785676c28f3729e07f5 + React-rncore: 03e9b66d28812371afe3e7f180968f8e2a4ea71e React-runtimeexecutor: 4b0c6eb341c7d3ceb5e2385cb0fdb9bf701024f3 ReactCommon: 7a2714d1128f965392b6f99a8b390e3aa38c9569 - ScreenshotManager: e8a3fc9b2e24b81127b36cb4ebe0eed65090c949 + ScreenshotManager: 6923f27c7ce9505117b8c743c9f099fa3054df6a Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/packages/rn-tester/RNTesterUnitTests/RCTPerformanceLoggerTests.m b/packages/rn-tester/RNTesterUnitTests/RCTPerformanceLoggerTests.m index a0a524e6ca4141..b232fb6a4d1030 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTPerformanceLoggerTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTPerformanceLoggerTests.m @@ -15,10 +15,4 @@ @interface RCTPerformanceLoggerTests : XCTestCase @implementation RCTPerformanceLoggerTests -- (void)testLabelCountInSyncWithRCTPLTag -{ - RCTPerformanceLogger *logger = [RCTPerformanceLogger new]; - XCTAssertEqual([logger labelsForTags].count, RCTPLSize); -} - @end