性能统计数据 先持久化到本地,文件大于50K之后上传服务器。 code reivew by 枪兵
Showing
8 changed files
with
73 additions
and
12 deletions
1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
2 | -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc"> | 2 | +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="14F1021" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc"> |
3 | <dependencies> | 3 | <dependencies> |
4 | <deployment identifier="iOS"/> | 4 | <deployment identifier="iOS"/> |
5 | - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/> | 5 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/> |
6 | <capability name="Constraints to layout margins" minToolsVersion="6.0"/> | 6 | <capability name="Constraints to layout margins" minToolsVersion="6.0"/> |
7 | </dependencies> | 7 | </dependencies> |
8 | <scenes> | 8 | <scenes> |
@@ -38,5 +38,22 @@ | @@ -38,5 +38,22 @@ | ||
38 | <array> | 38 | <array> |
39 | <string>UIInterfaceOrientationPortrait</string> | 39 | <string>UIInterfaceOrientationPortrait</string> |
40 | </array> | 40 | </array> |
41 | + <key>NSAppTransportSecurity</key> | ||
42 | + <dict> | ||
43 | + <key>NSAllowsArbitraryLoads</key> | ||
44 | + <true/> | ||
45 | + <key>NSExceptionDomains</key> | ||
46 | + <dict> | ||
47 | + <key>alipay.com</key> | ||
48 | + <dict> | ||
49 | + <key>NSIncludesSubdomains</key> | ||
50 | + <true/> | ||
51 | + <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> | ||
52 | + <true/> | ||
53 | + <key>NSTemporaryExceptionMinimumTLSVersion</key> | ||
54 | + <string>TLSv1.1</string> | ||
55 | + </dict> | ||
56 | + </dict> | ||
57 | + </dict> | ||
41 | </dict> | 58 | </dict> |
42 | </plist> | 59 | </plist> |
@@ -83,10 +83,14 @@ | @@ -83,10 +83,14 @@ | ||
83 | 83 | ||
84 | - (IBAction)performanceAction:(id)sender { | 84 | - (IBAction)performanceAction:(id)sender { |
85 | 85 | ||
86 | + for (int i = 0; i<101; i++) { | ||
86 | [[YH_Analytics sharedInstance]logPerformanceWithType:kPerformanceTypeImageLoad parameters:@{ | 87 | [[YH_Analytics sharedInstance]logPerformanceWithType:kPerformanceTypeImageLoad parameters:@{ |
88 | + @"index":@(i), | ||
87 | JsonKeyPerformanceTag:@"YH_TAGS", | 89 | JsonKeyPerformanceTag:@"YH_TAGS", |
88 | JsonKeyPerformanceURL:@"http://ad.yoho.cn/yohobuy/img/home/02.jpg", | 90 | JsonKeyPerformanceURL:@"http://ad.yoho.cn/yohobuy/img/home/02.jpg", |
89 | JsonKeyPerformanceEvt:JsonKeyPerformanceEvtBegin | 91 | JsonKeyPerformanceEvt:JsonKeyPerformanceEvtBegin |
90 | }]; | 92 | }]; |
93 | + } | ||
94 | + | ||
91 | } | 95 | } |
92 | @end | 96 | @end |
@@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
12 | /* | 12 | /* |
13 | 用于组装数据 | 13 | 用于组装数据 |
14 | */ | 14 | */ |
15 | - | 15 | +@class YHPerformance; |
16 | @interface YHAssemblyAssistant : NSObject | 16 | @interface YHAssemblyAssistant : NSObject |
17 | 17 | ||
18 | + (instancetype)sharedInstance; | 18 | + (instancetype)sharedInstance; |
@@ -21,6 +21,8 @@ | @@ -21,6 +21,8 @@ | ||
21 | 21 | ||
22 | - (void)saveItemData:(YHAnalyItemData *)itemData; | 22 | - (void)saveItemData:(YHAnalyItemData *)itemData; |
23 | 23 | ||
24 | +- (void)savePerformanceData:(YHPerformance *)perf; | ||
25 | + | ||
24 | - (NSUInteger)getAllEventCount; | 26 | - (NSUInteger)getAllEventCount; |
25 | 27 | ||
26 | - (NSDictionary *)getUploadData; | 28 | - (NSDictionary *)getUploadData; |
@@ -270,6 +270,29 @@ static dispatch_queue_t persisting_queue() { | @@ -270,6 +270,29 @@ static dispatch_queue_t persisting_queue() { | ||
270 | } | 270 | } |
271 | 271 | ||
272 | #pragma mark - 持久化数据 | 272 | #pragma mark - 持久化数据 |
273 | +- (void)savePerformanceData:(YHPerformance *)perf | ||
274 | +{ | ||
275 | + if (perf == nil || ![perf isKindOfClass:[YHPerformance class]]) { | ||
276 | + NSException *exception = [NSException exceptionWithName:NSInvalidArgumentException | ||
277 | + reason:@"The input parameter is nil or an unexpected value." | ||
278 | + userInfo:nil]; | ||
279 | + [exception raise]; | ||
280 | + | ||
281 | + } | ||
282 | + | ||
283 | + if ([self canPersisting]) { | ||
284 | + perf.net = self.currentStatus.net; | ||
285 | + | ||
286 | + dispatch_async(persisting_queue(), ^{ | ||
287 | + | ||
288 | + if ([self writePerformanceToFile:perf]) { | ||
289 | + [self autoUploadData]; | ||
290 | + } | ||
291 | + }); | ||
292 | + } | ||
293 | + | ||
294 | +} | ||
295 | + | ||
273 | - (void)saveItemData:(YHAnalyItemData *)itemData | 296 | - (void)saveItemData:(YHAnalyItemData *)itemData |
274 | { | 297 | { |
275 | if (itemData == nil || ![itemData isKindOfClass:[YHAnalyItemData class]]) { | 298 | if (itemData == nil || ![itemData isKindOfClass:[YHAnalyItemData class]]) { |
@@ -652,6 +675,8 @@ static dispatch_queue_t persisting_queue() { | @@ -652,6 +675,8 @@ static dispatch_queue_t persisting_queue() { | ||
652 | collectData = [[NSMutableDictionary alloc]init]; | 675 | collectData = [[NSMutableDictionary alloc]init]; |
653 | 676 | ||
654 | //直接添加 immediUploadDataDic 内容(里面包含 device 信息) | 677 | //直接添加 immediUploadDataDic 内容(里面包含 device 信息) |
678 | + [self.immediUploadItemDic removeObjectForKey:JsonKeyDataTypeErrors]; | ||
679 | + [self.immediUploadItemDic removeObjectForKey:JsonKeyDataTypeEvents]; | ||
655 | [collectData addEntriesFromDictionary:self.immediUploadItemDic]; | 680 | [collectData addEntriesFromDictionary:self.immediUploadItemDic]; |
656 | 681 | ||
657 | //组合performance信息 | 682 | //组合performance信息 |
@@ -32,8 +32,8 @@ | @@ -32,8 +32,8 @@ | ||
32 | #define kYHAnalyticsSDKVersion @"1.0" // 数据分析库版本 | 32 | #define kYHAnalyticsSDKVersion @"1.0" // 数据分析库版本 |
33 | #define kDefalutChannelNum @"2119" // 推广渠道号 | 33 | #define kDefalutChannelNum @"2119" // 推广渠道号 |
34 | #define kMinInterval 60 // 间隔发送的最小时间周期,60秒 | 34 | #define kMinInterval 60 // 间隔发送的最小时间周期,60秒 |
35 | -#define kMaxLocalEventsCount 3000 // 本地持久化event最大条数,3000条 | ||
36 | -#define kMaxLocalRecoderFileSize (1024 * 300) // 本地持久化文件大小(300KB) | 35 | +#define kMaxLocalEventsCount 100 // 本地持久化event最大条数,3000条 |
36 | +#define kMaxLocalRecoderFileSize (1024 * 50) // 本地持久化文件大小(300KB) | ||
37 | 37 | ||
38 | /*********** Path and FileName *************/ | 38 | /*********** Path and FileName *************/ |
39 | 39 |
@@ -55,6 +55,16 @@ typedef NS_ENUM(NSInteger, YHLogStrategy) { | @@ -55,6 +55,16 @@ typedef NS_ENUM(NSInteger, YHLogStrategy) { | ||
55 | */ | 55 | */ |
56 | - (void)logPerformanceWithType:(NSString *)perfType parameters:(NSDictionary *)param; | 56 | - (void)logPerformanceWithType:(NSString *)perfType parameters:(NSDictionary *)param; |
57 | 57 | ||
58 | +///** | ||
59 | +// @brief 统一事件记录的接口 | ||
60 | +// | ||
61 | +// @param extraData 统计类型 IMG_LOAD, API_CALL, WEBVIEW_LOAD | ||
62 | +// @param param 操作参数 | ||
63 | +// | ||
64 | +// @since 1.0 | ||
65 | +// */ | ||
66 | +//- (void)logWithExtraData:(NSString *)extraData dataType:() parameters:(NSDictionary *)param; | ||
67 | + | ||
58 | 68 | ||
59 | /** | 69 | /** |
60 | * 用户id | 70 | * 用户id |
@@ -111,8 +111,8 @@ | @@ -111,8 +111,8 @@ | ||
111 | 111 | ||
112 | */ | 112 | */ |
113 | 113 | ||
114 | - _logStrategy = LogStrategyAppLaunch | LogStrategyCustom; | ||
115 | - _currentInterval = 5*60; | 114 | + _logStrategy = LogStrategyAppLaunch | LogStrategyImmedi; |
115 | +// _currentInterval = 5*60; | ||
116 | 116 | ||
117 | YALog(@"logStrategy = %d currentInterval = %0.1f", _logStrategy, _currentInterval); | 117 | YALog(@"logStrategy = %d currentInterval = %0.1f", _logStrategy, _currentInterval); |
118 | } | 118 | } |
@@ -326,11 +326,14 @@ | @@ -326,11 +326,14 @@ | ||
326 | self.perfermance.param = param; | 326 | self.perfermance.param = param; |
327 | 327 | ||
328 | // 立即发送策略 | 328 | // 立即发送策略 |
329 | - if ((self.logStrategy & LogStrategyImmedi) != 0) { | ||
330 | - [[YHAssemblyAssistant sharedInstance] uploadImmedilyWithEvent:self.perfermance]; | ||
331 | - } else { | ||
332 | - [[YHAssemblyAssistant sharedInstance] saveItemData:self.perfermance]; | ||
333 | - } | 329 | +// if ((self.logStrategy & LogStrategyImmedi) != 0) { |
330 | +// [[YHAssemblyAssistant sharedInstance] uploadImmedilyWithEvent:self.perfermance]; | ||
331 | +// } else { | ||
332 | +// [[YHAssemblyAssistant sharedInstance] saveItemData:self.perfermance]; | ||
333 | +// } | ||
334 | + | ||
335 | + // 性能统计事件不需要立即发送 | ||
336 | + [[YHAssemblyAssistant sharedInstance]savePerformanceData:self.perfermance]; | ||
334 | } | 337 | } |
335 | 338 | ||
336 | @end | 339 | @end |
-
Please register or login to post a comment