add files changed count to reload metrics
Reviewed By: alexeylang Differential Revision: D5694813 fbshipit-source-id: 2e2517e60a7547e261a7c15a3a9138dbb3cb9783
This commit is contained in:
parent
6ceb4fa53f
commit
259161f872
|
@ -62,6 +62,12 @@ RCT_EXTERN NSString *const RCTBridgeWillDownloadScriptNotification;
|
|||
*/
|
||||
RCT_EXTERN NSString *const RCTBridgeDidDownloadScriptNotification;
|
||||
|
||||
/**
|
||||
* Key for the RCTSource object in the RCTBridgeDidDownloadScriptNotification
|
||||
* userInfo dictionary.
|
||||
*/
|
||||
RCT_EXTERN NSString *const RCTBridgeDidDownloadScriptNotificationSourceKey;
|
||||
|
||||
/**
|
||||
* This block can be used to instantiate modules that require additional
|
||||
* init parameters, or additional configuration prior to being used.
|
||||
|
|
|
@ -32,6 +32,7 @@ NSString *const RCTDidInitializeModuleNotification = @"RCTDidInitializeModuleNot
|
|||
NSString *const RCTBridgeWillReloadNotification = @"RCTBridgeWillReloadNotification";
|
||||
NSString *const RCTBridgeWillDownloadScriptNotification = @"RCTBridgeWillDownloadScriptNotification";
|
||||
NSString *const RCTBridgeDidDownloadScriptNotification = @"RCTBridgeDidDownloadScriptNotification";
|
||||
NSString *const RCTBridgeDidDownloadScriptNotificationSourceKey = @"source";
|
||||
|
||||
static NSMutableArray<Class> *RCTModuleClasses;
|
||||
NSArray<Class> *RCTGetModuleClasses(void)
|
||||
|
|
|
@ -25,6 +25,11 @@ NS_ENUM(NSInteger) {
|
|||
RCTJavaScriptLoaderErrorCannotBeLoadedSynchronously = 1000,
|
||||
};
|
||||
|
||||
NS_ENUM(NSInteger) {
|
||||
RCTSourceFilesChangedCountNotBuiltByBundler = -2,
|
||||
RCTSourceFilesChangedCountRebuiltFromScratch = -1,
|
||||
};
|
||||
|
||||
@interface RCTLoadingProgress : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSString *status;
|
||||
|
@ -55,6 +60,15 @@ NS_ENUM(NSInteger) {
|
|||
*/
|
||||
@property (nonatomic, readonly) NSUInteger length;
|
||||
|
||||
/**
|
||||
* Returns number of files changed when building this bundle:
|
||||
*
|
||||
* - RCTSourceFilesChangedCountNotBuiltByBundler if the source wasn't built by the bundler (e.g. read from disk)
|
||||
* - RCTSourceFilesChangedCountRebuiltFromScratch if the source was rebuilt from scratch by the bundler
|
||||
* - Otherwise, the number of files changed when incrementally rebuilding the source
|
||||
*/
|
||||
@property (nonatomic, readonly) NSInteger filesChangedCount;
|
||||
|
||||
@end
|
||||
|
||||
typedef void (^RCTSourceLoadProgressBlock)(RCTLoadingProgress *progressData);
|
||||
|
|
|
@ -28,6 +28,7 @@ NSString *const RCTJavaScriptLoaderErrorDomain = @"RCTJavaScriptLoaderErrorDomai
|
|||
NSURL *_url;
|
||||
NSData *_data;
|
||||
NSUInteger _length;
|
||||
NSInteger _filesChangedCount;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -40,6 +41,7 @@ static RCTSource *RCTSourceCreate(NSURL *url, NSData *data, int64_t length) NS_R
|
|||
source->_url = url;
|
||||
source->_data = data;
|
||||
source->_length = length;
|
||||
source->_filesChangedCount = RCTSourceFilesChangedCountNotBuiltByBundler;
|
||||
return source;
|
||||
}
|
||||
|
||||
|
@ -205,6 +207,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
return [NSData dataWithBytes:&header length:sizeof(header)];
|
||||
}
|
||||
|
||||
static void parseHeaders(NSDictionary *headers, RCTSource *source) {
|
||||
source->_filesChangedCount = [headers[@"X-Metro-Files-Changed-Count"] integerValue];
|
||||
}
|
||||
|
||||
static void attemptAsynchronousLoadOfBundleAtURL(NSURL *scriptURL, RCTSourceLoadProgressBlock onProgress, RCTSourceLoadBlock onComplete)
|
||||
{
|
||||
scriptURL = sanitizeURL(scriptURL);
|
||||
|
@ -282,7 +288,9 @@ static void attemptAsynchronousLoadOfBundleAtURL(NSURL *scriptURL, RCTSourceLoad
|
|||
return;
|
||||
}
|
||||
|
||||
onComplete(nil, RCTSourceCreate(scriptURL, data, data.length));
|
||||
RCTSource *source = RCTSourceCreate(scriptURL, data, data.length);
|
||||
parseHeaders(headers, source);
|
||||
onComplete(nil, source);
|
||||
} progressHandler:^(NSDictionary *headers, NSNumber *loaded, NSNumber *total) {
|
||||
// Only care about download progress events for the javascript bundle part.
|
||||
if ([headers[@"Content-Type"] isEqualToString:@"application/javascript"]) {
|
||||
|
|
|
@ -390,7 +390,9 @@ struct RCTInstanceCallback : public InstanceCallback {
|
|||
RCTProfileEndAsyncEvent(0, @"native", cookie, @"JavaScript download", @"JS async");
|
||||
[performanceLogger markStopForTag:RCTPLScriptDownload];
|
||||
[performanceLogger setValue:source.length forTag:RCTPLBundleSize];
|
||||
[center postNotificationName:RCTBridgeDidDownloadScriptNotification object:self->_parentBridge];
|
||||
|
||||
NSDictionary *userInfo = source ? @{ RCTBridgeDidDownloadScriptNotificationSourceKey: source } : nil;
|
||||
[center postNotificationName:RCTBridgeDidDownloadScriptNotification object:self->_parentBridge userInfo:userInfo];
|
||||
|
||||
_onSourceLoad(error, source);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue