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
103 lines
3.1 KiB
Objective-C
103 lines
3.1 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 <Foundation/Foundation.h>
|
|
|
|
typedef NS_ENUM(NSUInteger, RCTPLTag) {
|
|
RCTPLScriptDownload = 0,
|
|
RCTPLScriptExecution,
|
|
RCTPLRAMBundleLoad,
|
|
RCTPLRAMStartupCodeSize,
|
|
RCTPLRAMStartupNativeRequires,
|
|
RCTPLRAMStartupNativeRequiresCount,
|
|
RCTPLRAMNativeRequires,
|
|
RCTPLRAMNativeRequiresCount,
|
|
RCTPLNativeModuleInit,
|
|
RCTPLNativeModuleMainThread,
|
|
RCTPLNativeModulePrepareConfig,
|
|
RCTPLNativeModuleMainThreadUsesCount,
|
|
RCTPLNativeModuleSetup,
|
|
RCTPLTurboModuleSetup,
|
|
RCTPLJSCWrapperOpenLibrary,
|
|
RCTPLBridgeStartup,
|
|
RCTPLTTI,
|
|
RCTPLBundleSize,
|
|
RCTPLSize
|
|
};
|
|
|
|
@interface RCTPerformanceLogger : NSObject
|
|
|
|
/**
|
|
* Starts measuring a metric with the given tag.
|
|
* Overrides previous value if the measurement has been already started.
|
|
* If RCTProfile is enabled it also begins appropriate async event.
|
|
* All work is scheduled on the background queue so this doesn't block current thread.
|
|
*/
|
|
- (void)markStartForTag:(RCTPLTag)tag;
|
|
|
|
/**
|
|
* Stops measuring a metric with given tag.
|
|
* Checks if RCTPerformanceLoggerStart() has been called before
|
|
* and doesn't do anything and log a message if it hasn't.
|
|
* If RCTProfile is enabled it also ends appropriate async event.
|
|
* All work is scheduled on the background queue so this doesn't block current thread.
|
|
*/
|
|
- (void)markStopForTag:(RCTPLTag)tag;
|
|
|
|
/**
|
|
* Sets given value for a metric with given tag.
|
|
* All work is scheduled on the background queue so this doesn't block current thread.
|
|
*/
|
|
- (void)setValue:(int64_t)value forTag:(RCTPLTag)tag;
|
|
|
|
/**
|
|
* Adds given value to the current value for a metric with given tag.
|
|
* All work is scheduled on the background queue so this doesn't block current thread.
|
|
*/
|
|
- (void)addValue:(int64_t)value forTag:(RCTPLTag)tag;
|
|
|
|
/**
|
|
* Starts an additional measurement for a metric with given tag.
|
|
* It doesn't override previous measurement, instead it'll append a new value
|
|
* to the old one.
|
|
* All work is scheduled on the background queue so this doesn't block current thread.
|
|
*/
|
|
- (void)appendStartForTag:(RCTPLTag)tag;
|
|
|
|
/**
|
|
* Stops measurement and appends the result to the metric with given tag.
|
|
* Checks if RCTPerformanceLoggerAppendStart() has been called before
|
|
* and doesn't do anything and log a message if it hasn't.
|
|
* All work is scheduled on the background queue so this doesn't block current thread.
|
|
*/
|
|
- (void)appendStopForTag:(RCTPLTag)tag;
|
|
|
|
/**
|
|
* Returns an array with values for all tags.
|
|
* Use RCTPLTag to go over the array, there's a pair of values
|
|
* for each tag: start and stop (with indexes 2 * tag and 2 * tag + 1).
|
|
*/
|
|
- (NSArray<NSNumber *> *)valuesForTags;
|
|
|
|
/**
|
|
* Returns a duration in ms (stop_time - start_time) for given RCTPLTag.
|
|
*/
|
|
- (int64_t)durationForTag:(RCTPLTag)tag;
|
|
|
|
/**
|
|
* Returns a value for given RCTPLTag.
|
|
*/
|
|
- (int64_t)valueForTag:(RCTPLTag)tag;
|
|
|
|
/**
|
|
* Returns an array with values for all tags.
|
|
* Use RCTPLTag to go over the array.
|
|
*/
|
|
- (NSArray<NSString *> *)labelsForTags;
|
|
|
|
@end
|