Authored by 王钱钧

性能统计数据 先持久化到本地,文件大于50K之后上传服务器。 code reivew by 枪兵

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<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">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
... ...
... ... @@ -38,5 +38,22 @@
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>alipay.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
</dict>
</plist>
... ...
... ... @@ -83,10 +83,14 @@
- (IBAction)performanceAction:(id)sender {
[[YH_Analytics sharedInstance]logPerformanceWithType:kPerformanceTypeImageLoad parameters:@{
JsonKeyPerformanceTag:@"YH_TAGS",
JsonKeyPerformanceURL:@"http://ad.yoho.cn/yohobuy/img/home/02.jpg",
JsonKeyPerformanceEvt:JsonKeyPerformanceEvtBegin
}];
for (int i = 0; i<101; i++) {
[[YH_Analytics sharedInstance]logPerformanceWithType:kPerformanceTypeImageLoad parameters:@{
@"index":@(i),
JsonKeyPerformanceTag:@"YH_TAGS",
JsonKeyPerformanceURL:@"http://ad.yoho.cn/yohobuy/img/home/02.jpg",
JsonKeyPerformanceEvt:JsonKeyPerformanceEvtBegin
}];
}
}
@end
... ...
... ... @@ -12,7 +12,7 @@
/*
用于组装数据
*/
@class YHPerformance;
@interface YHAssemblyAssistant : NSObject
+ (instancetype)sharedInstance;
... ... @@ -21,6 +21,8 @@
- (void)saveItemData:(YHAnalyItemData *)itemData;
- (void)savePerformanceData:(YHPerformance *)perf;
- (NSUInteger)getAllEventCount;
- (NSDictionary *)getUploadData;
... ...
... ... @@ -270,6 +270,29 @@ static dispatch_queue_t persisting_queue() {
}
#pragma mark - 持久化数据
- (void)savePerformanceData:(YHPerformance *)perf
{
if (perf == nil || ![perf isKindOfClass:[YHPerformance class]]) {
NSException *exception = [NSException exceptionWithName:NSInvalidArgumentException
reason:@"The input parameter is nil or an unexpected value."
userInfo:nil];
[exception raise];
}
if ([self canPersisting]) {
perf.net = self.currentStatus.net;
dispatch_async(persisting_queue(), ^{
if ([self writePerformanceToFile:perf]) {
[self autoUploadData];
}
});
}
}
- (void)saveItemData:(YHAnalyItemData *)itemData
{
if (itemData == nil || ![itemData isKindOfClass:[YHAnalyItemData class]]) {
... ... @@ -652,6 +675,8 @@ static dispatch_queue_t persisting_queue() {
collectData = [[NSMutableDictionary alloc]init];
//直接添加 immediUploadDataDic 内容(里面包含 device 信息)
[self.immediUploadItemDic removeObjectForKey:JsonKeyDataTypeErrors];
[self.immediUploadItemDic removeObjectForKey:JsonKeyDataTypeEvents];
[collectData addEntriesFromDictionary:self.immediUploadItemDic];
//组合performance信息
... ...
... ... @@ -32,8 +32,8 @@
#define kYHAnalyticsSDKVersion @"1.0" // 数据分析库版本
#define kDefalutChannelNum @"2119" // 推广渠道号
#define kMinInterval 60 // 间隔发送的最小时间周期,60秒
#define kMaxLocalEventsCount 3000 // 本地持久化event最大条数,3000条
#define kMaxLocalRecoderFileSize (1024 * 300) // 本地持久化文件大小(300KB)
#define kMaxLocalEventsCount 100 // 本地持久化event最大条数,3000条
#define kMaxLocalRecoderFileSize (1024 * 50) // 本地持久化文件大小(300KB)
/*********** Path and FileName *************/
... ...
... ... @@ -55,6 +55,16 @@ typedef NS_ENUM(NSInteger, YHLogStrategy) {
*/
- (void)logPerformanceWithType:(NSString *)perfType parameters:(NSDictionary *)param;
///**
// @brief 统一事件记录的接口
//
// @param extraData 统计类型 IMG_LOAD, API_CALL, WEBVIEW_LOAD
// @param param 操作参数
//
// @since 1.0
// */
//- (void)logWithExtraData:(NSString *)extraData dataType:() parameters:(NSDictionary *)param;
/**
* 用户id
... ...
... ... @@ -111,8 +111,8 @@
*/
_logStrategy = LogStrategyAppLaunch | LogStrategyCustom;
_currentInterval = 5*60;
_logStrategy = LogStrategyAppLaunch | LogStrategyImmedi;
// _currentInterval = 5*60;
YALog(@"logStrategy = %d currentInterval = %0.1f", _logStrategy, _currentInterval);
}
... ... @@ -326,11 +326,14 @@
self.perfermance.param = param;
// 立即发送策略
if ((self.logStrategy & LogStrategyImmedi) != 0) {
[[YHAssemblyAssistant sharedInstance] uploadImmedilyWithEvent:self.perfermance];
} else {
[[YHAssemblyAssistant sharedInstance] saveItemData:self.perfermance];
}
// if ((self.logStrategy & LogStrategyImmedi) != 0) {
// [[YHAssemblyAssistant sharedInstance] uploadImmedilyWithEvent:self.perfermance];
// } else {
// [[YHAssemblyAssistant sharedInstance] saveItemData:self.perfermance];
// }
// 性能统计事件不需要立即发送
[[YHAssemblyAssistant sharedInstance]savePerformanceData:self.perfermance];
}
@end
... ...