3535typedef NS_ENUM(NSUInteger , RCTBridgeFields) {
3636 RCTBridgeFieldRequestModuleIDs = 0 ,
3737 RCTBridgeFieldMethodIDs,
38- RCTBridgeFieldParamss,
38+ RCTBridgeFieldParams,
39+ RCTBridgeFieldCallID,
3940};
4041
4142RCT_EXTERN NSArray <Class > *RCTGetModuleClasses (void );
@@ -65,6 +66,9 @@ @implementation RCTBatchedBridge
6566 NSUInteger _asyncInitializedModules;
6667}
6768
69+ @synthesize flowID = _flowID;
70+ @synthesize flowIDMap = _flowIDMap;
71+
6872- (instancetype )initWithParentBridge : (RCTBridge *)bridge
6973{
7074 RCTAssertMainThread ();
@@ -591,6 +595,9 @@ - (void)invalidate
591595 _modulesByName_DEPRECATED = nil ;
592596 _frameUpdateObservers = nil ;
593597
598+ if (_flowIDMap != NULL ) {
599+ CFRelease (_flowIDMap);
600+ }
594601 }];
595602 });
596603}
@@ -793,15 +800,22 @@ - (void)handleBuffer:(id)buffer batchEnded:(BOOL)batchEnded
793800- (void )handleBuffer : (NSArray *)buffer
794801{
795802 NSArray *requestsArray = [RCTConvert NSArray: buffer];
796- if (RCT_DEBUG && requestsArray.count <= RCTBridgeFieldParamss) {
803+
804+ if (RCT_DEBUG && requestsArray.count <= RCTBridgeFieldParams) {
797805 RCTLogError (@" Buffer should contain at least %tu sub-arrays. Only found %tu " ,
798- RCTBridgeFieldParamss + 1 , requestsArray.count );
806+ RCTBridgeFieldParams + 1 , requestsArray.count );
799807 return ;
800808 }
801809
802810 NSArray <NSNumber *> *moduleIDs = [RCTConvert NSNumberArray: requestsArray[RCTBridgeFieldRequestModuleIDs]];
803811 NSArray <NSNumber *> *methodIDs = [RCTConvert NSNumberArray: requestsArray[RCTBridgeFieldMethodIDs]];
804- NSArray <NSArray *> *paramsArrays = [RCTConvert NSArrayArray: requestsArray[RCTBridgeFieldParamss]];
812+ NSArray <NSArray *> *paramsArrays = [RCTConvert NSArrayArray: requestsArray[RCTBridgeFieldParams]];
813+
814+ int64_t callID = -1 ;
815+
816+ if (requestsArray.count > 3 ) {
817+ callID = [requestsArray[RCTBridgeFieldCallID] longLongValue ];
818+ }
805819
806820 if (RCT_DEBUG && (moduleIDs.count != methodIDs.count || moduleIDs.count != paramsArrays.count )) {
807821 RCTLogError (@" Invalid data message - all must be length: %zd " , moduleIDs.count );
@@ -835,6 +849,11 @@ - (void)handleBuffer:(NSArray *)buffer
835849 @autoreleasepool {
836850 for (NSNumber *indexObj in calls) {
837851 NSUInteger index = indexObj.unsignedIntegerValue ;
852+ if (callID != -1 ) {
853+ int64_t newFlowID = (int64_t )CFDictionaryGetValue (_flowIDMap, (const void *)(_flowID + index));
854+ _RCTProfileEndFlowEvent (@(newFlowID));
855+ CFDictionaryRemoveValue (_flowIDMap, (const void *)(_flowID + index));
856+ }
838857 [self _handleRequestNumber: index
839858 moduleID: [moduleIDs[index] integerValue ]
840859 methodID: [methodIDs[index] integerValue ]
@@ -853,6 +872,8 @@ - (void)handleBuffer:(NSArray *)buffer
853872 dispatch_async (queue, block);
854873 }
855874 }
875+
876+ _flowID = callID;
856877}
857878
858879- (void )partialBatchDidFlush
0 commit comments