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];
|
|
|
|
}
|
2017-11-08 08:07:12 +00:00
|
|
|
FIRTrace *trace = [FIRPerformance traceWithName:identifier];
|
2017-05-25 09:39:54 +00:00
|
|
|
_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];
|
|
|
|
}
|
|
|
|
|
2017-10-12 08:18:01 +00:00
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2017-05-25 09:39:54 +00:00
|
|
|
@end
|
2017-05-25 14:03:20 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
@implementation RNFirebasePerformance
|
|
|
|
@end
|
|
|
|
#endif
|