2017-05-25 09:39:54 +00:00
|
|
|
#import "RNFirebasePerformance.h"
|
|
|
|
|
2017-05-25 14:03:20 +00:00
|
|
|
#if __has_include(<FirebasePerformance/FIRPerformance.h>)
|
|
|
|
#import <FirebasePerformance/FIRPerformance.h>
|
2017-05-25 09:39:54 +00:00
|
|
|
@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
|
2017-05-25 14:03:20 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
@implementation RNFirebasePerformance
|
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
RCT_EXPORT_METHOD(nativeSDKMissing) {}
|
|
|
|
@end
|
|
|
|
#endif
|