react-native-firebase/ios/RNFirebase/RNFirebasePerformance.m

56 lines
1.3 KiB
Mathematica
Raw Normal View History

#import "RNFirebasePerformance.h"
#if __has_include(<FirebasePerformance/FIRPerformance.h>)
#import <FirebasePerformance/FIRPerformance.h>
@implementation RNFirebasePerformance
RCT_EXPORT_MODULE();
- (id)init {
self = [super init];
if (self != nil) {
_traces = [[NSMutableDictionary alloc] init];
}
return self;
}
- (FIRTrace *)getOrCreateTrace:(NSString *)identifier {
if (_traces[identifier]) {
return _traces[identifier];
}
FIRTrace *trace = [FIRPerformance startTraceWithName:identifier];
_traces[identifier] = trace;
return trace;
}
RCT_EXPORT_METHOD(setPerformanceCollectionEnabled:
(BOOL *) enabled) {
[FIRPerformance sharedInstance].dataCollectionEnabled = (BOOL) enabled;
}
RCT_EXPORT_METHOD(start:
(NSString *) identifier) {
[[self getOrCreateTrace:identifier] start];
}
RCT_EXPORT_METHOD(stop:
(NSString *) identifier) {
[[self getOrCreateTrace:identifier] stop];
_traces[identifier] = nil;
}
RCT_EXPORT_METHOD(incrementCounter:
(NSString *) identifier
event:
(NSString *) event) {
[[self getOrCreateTrace:identifier] incrementCounterNamed:event];
}
@end
#else
@implementation RNFirebasePerformance
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif