1 |
efrain |
1 |
// Copyright 2020 Google LLC
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
|
|
|
15 |
#import "FirebasePerformance/Sources/Loggers/FPRGDTLogger.h"
|
|
|
16 |
#import "FirebasePerformance/Sources/Loggers/FPRGDTLogger_Private.h"
|
|
|
17 |
|
|
|
18 |
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations.h"
|
|
|
19 |
|
|
|
20 |
#import "FirebasePerformance/Sources/Loggers/FPRGDTEvent.h"
|
|
|
21 |
#import "FirebasePerformance/Sources/Loggers/FPRGDTLogSampler.h"
|
|
|
22 |
#import "FirebasePerformance/Sources/Loggers/FPRGDTRateLimiter.h"
|
|
|
23 |
|
|
|
24 |
#import <GoogleDataTransport/GoogleDataTransport.h>
|
|
|
25 |
|
|
|
26 |
#import "FirebasePerformance/Sources/Protogen/nanopb/perf_metric.nanopb.h"
|
|
|
27 |
|
|
|
28 |
@implementation FPRGDTLogger
|
|
|
29 |
|
|
|
30 |
- (instancetype)initWithLogSource:(NSInteger)logSource {
|
|
|
31 |
if (self = [super init]) {
|
|
|
32 |
_logSource = logSource;
|
|
|
33 |
|
|
|
34 |
_queue = dispatch_queue_create("com.google.FPRGDTLogger", DISPATCH_QUEUE_SERIAL);
|
|
|
35 |
_configurations = [FPRConfigurations sharedInstance];
|
|
|
36 |
FPRGDTLogSampler *logSampler = [[FPRGDTLogSampler alloc] init];
|
|
|
37 |
FPRGDTRateLimiter *rateLimiter = [[FPRGDTRateLimiter alloc] init];
|
|
|
38 |
|
|
|
39 |
_gdtfllTransport = [[GDTCORTransport alloc] initWithMappingID:@(logSource).stringValue
|
|
|
40 |
transformers:@[ logSampler, rateLimiter ]
|
|
|
41 |
target:kGDTCORTargetFLL];
|
|
|
42 |
_isSimulator = NO;
|
|
|
43 |
// If app is running on simulator, environment variable SIMULATOR_UDID exists.
|
|
|
44 |
// Otherwise, SIMULATOR_UDID is not provided when app is running on real device.
|
|
|
45 |
// For development, developers can dispatch performance events immediately if
|
|
|
46 |
// they are running app on simulator, so it can expedite development process.
|
|
|
47 |
if ([[[NSProcessInfo processInfo] environment] objectForKey:@"SIMULATOR_UDID"]) {
|
|
|
48 |
_isSimulator = YES;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
_instanceSeed = -1.0; // -1.0 means instanceSeed has not been computed.
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
return self;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
- (void)logEvent:(firebase_perf_v1_PerfMetric)event {
|
|
|
58 |
GDTCORTransport *eventTransporter = self.gdtfllTransport;
|
|
|
59 |
|
|
|
60 |
dispatch_async(self.queue, ^{
|
|
|
61 |
GDTCOREvent *gdtEvent = [eventTransporter eventForTransport];
|
|
|
62 |
if (self.isSimulator) {
|
|
|
63 |
gdtEvent.qosTier = GDTCOREventQoSFast;
|
|
|
64 |
} else {
|
|
|
65 |
gdtEvent.qosTier = GDTCOREventQosDefault;
|
|
|
66 |
}
|
|
|
67 |
gdtEvent.dataObject = [FPRGDTEvent gdtEventForPerfMetric:event];
|
|
|
68 |
[eventTransporter sendDataEvent:gdtEvent];
|
|
|
69 |
});
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
@end
|