summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2019-05-14 10:34:46 -0700
committerFabian Guerra Soto <fabian.guerra@mapbox.com>2019-05-16 11:13:39 -0700
commit65990b3e2574fc52c0c382adf818367580443c6b (patch)
treeb351c9b39bb8a6d19b1a619bec31a1ec21b52e6a /platform/darwin
parent517e8f8ae585763fd0bb026ee493170e9e9d2bed (diff)
downloadqtlocation-mapboxgl-65990b3e2574fc52c0c382adf818367580443c6b.tar.gz
[ios] Rename performance's metrics variable names.android-v7.5.0-beta.1
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLNetworkConfiguration.m44
-rw-r--r--platform/darwin/src/MGLNetworkConfiguration_Private.h4
-rw-r--r--platform/darwin/src/http_file_source.mm4
3 files changed, 35 insertions, 17 deletions
diff --git a/platform/darwin/src/MGLNetworkConfiguration.m b/platform/darwin/src/MGLNetworkConfiguration.m
index bac4d12ee5..40993c97b5 100644
--- a/platform/darwin/src/MGLNetworkConfiguration.m
+++ b/platform/darwin/src/MGLNetworkConfiguration.m
@@ -1,5 +1,7 @@
#import "MGLNetworkConfiguration_Private.h"
+#include <mbgl/storage/reachability.h>
+
static NSString * const MGLStartTime = @"start_time";
static NSString * const MGLResourceType = @"resource_type";
NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace";
@@ -68,25 +70,30 @@ NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace";
}
}
-- (void)stopDownloadEvent:(NSString *)urlString {
- [self sendEventForURL:urlString withAction:nil];
+- (void)stopDownloadEventForResponse:(NSURLResponse *)response {
+ [self sendEventForURLResponse:response withAction:nil];
}
-- (void)cancelDownloadEvent:(NSString *)urlString {
- [self sendEventForURL:urlString withAction:@"cancel"];
+- (void)cancelDownloadEventForResponse:(NSURLResponse *)response {
+ [self sendEventForURLResponse:response withAction:@"cancel"];
}
-- (void)sendEventForURL:(NSString *)urlString withAction:(NSString *)action
+- (void)sendEventForURLResponse:(NSURLResponse *)response withAction:(NSString *)action
{
- if (urlString && [self.events objectForKey:urlString]) {
- NSDictionary *eventAttributes = [self eventAttributesForURL:urlString withAction:action];
- [self.metricsDelegate networkConfiguration:self didGenerateMetricEvent:eventAttributes];
- [self.events removeObjectForKey:urlString];
+ if ([response isKindOfClass:[NSURLResponse class]]) {
+ NSString *urlString = response.URL.relativePath;
+ if (urlString && [self.events objectForKey:urlString]) {
+ NSDictionary *eventAttributes = [self eventAttributesForURL:response withAction:action];
+ [self.metricsDelegate networkConfiguration:self didGenerateMetricEvent:eventAttributes];
+ [self.events removeObjectForKey:urlString];
+ }
}
+
}
-- (NSDictionary *)eventAttributesForURL:(NSString *)urlString withAction:(NSString *)action
+- (NSDictionary *)eventAttributesForURL:(NSURLResponse *)response withAction:(NSString *)action
{
+ NSString *urlString = response.URL.relativePath;
NSDictionary *parameters = [self.events objectForKey:urlString];
NSDate *startDate = [parameters objectForKey:MGLStartTime];
NSDate *endDate = [NSDate date];
@@ -96,17 +103,28 @@ NSString * const kMGLDownloadPerformanceEvent = @"mobile.performance_trace";
NSString *createdDate = [iso8601Formatter stringFromDate:[NSDate date]];
NSMutableArray *attributes = [NSMutableArray array];
- [attributes addObject:@{ @"name" : @"resource" , @"value" : urlString }];
+ [attributes addObject:@{ @"name" : @"requestUrl" , @"value" : urlString }];
[attributes addObject:@{ @"name" : MGLResourceType , @"value" : [parameters objectForKey:MGLResourceType] }];
+
+ if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
+ NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode];
+ [attributes addObject:@{ @"name" : @"responseCode", @"value" : @(responseCode)}];
+ }
+
+ BOOL isWIFIOn = [[MGLReachability reachabilityWithHostName:response.URL.host] isReachableViaWiFi];
+ [attributes addObject:@{ @"name" : @"wifiOn", @"value" : @(isWIFIOn)}];
+
if (action) {
[attributes addObject:@{ @"name" : @"action" , @"value" : action }];
}
-
+
+ double elapsedTimeInMS = elapsedTime * 1000.0;
+
return @{
@"event" : kMGLDownloadPerformanceEvent,
@"created" : createdDate,
@"sessionId" : [NSUUID UUID].UUIDString,
- @"counters" : @[ @{ @"name" : @"elapsed_time" , @"value" : @(elapsedTime) } ],
+ @"counters" : @[ @{ @"name" : @"elapsedMS" , @"value" : @(elapsedTimeInMS) } ],
@"attributes" : attributes
};
}
diff --git a/platform/darwin/src/MGLNetworkConfiguration_Private.h b/platform/darwin/src/MGLNetworkConfiguration_Private.h
index 18c78a004a..06f5c7d1b5 100644
--- a/platform/darwin/src/MGLNetworkConfiguration_Private.h
+++ b/platform/darwin/src/MGLNetworkConfiguration_Private.h
@@ -17,8 +17,8 @@ extern NSString * const kMGLDownloadPerformanceEvent;
@property (nonatomic, weak) id<MGLNetworkConfigurationMetricsDelegate> metricsDelegate;
- (void)startDownloadEvent:(NSString *)urlString type:(NSString *)resourceType;
-- (void)stopDownloadEvent:(NSString *)urlString;
-- (void)cancelDownloadEvent:(NSString *)urlString;
+- (void)stopDownloadEventForResponse:(NSURLResponse *)response;
+- (void)cancelDownloadEventForResponse:(NSURLResponse *)response;
@end
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm
index 26f6149b3f..20b9ead7af 100644
--- a/platform/darwin/src/http_file_source.mm
+++ b/platform/darwin/src/http_file_source.mm
@@ -242,10 +242,10 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
dataTaskWithRequest:req
completionHandler:^(NSData* data, NSURLResponse* res, NSError* error) {
if (error && [error code] == NSURLErrorCancelled) {
- [[MGLNetworkConfiguration sharedManager] cancelDownloadEvent:res.URL.relativePath];
+ [[MGLNetworkConfiguration sharedManager] cancelDownloadEventForResponse:res];
return;
}
- [[MGLNetworkConfiguration sharedManager] stopDownloadEvent:res.URL.relativePath];
+ [[MGLNetworkConfiguration sharedManager] stopDownloadEventForResponse:res];
Response response;
using Error = Response::Error;