Authored by 孙凯

add http review by daiqiang

... ... @@ -26,6 +26,7 @@
#import "YH_CrashDataManager.h"
#import "YH_EventDataFactory.h"
#import "YH_CrashReporter.h"
#import "NSURLSession+AutoTrack.h"
#define kYHEventReportIgnoredViewController @"YHEventReportQueue"
... ... @@ -157,13 +158,21 @@ static NSArray *kYHEventReportIgnoredViewControllerArray;
*/
-(void)startPerformanceTrack{
self.performanceTrackEnabled = YES;
if ([YHEventReport sharedInstance].isControllerPerformanceTrackEnable) {
[UIViewController startTrack];
[UITabBar startTrack];
}
// [UIControl startTrack];
// [UITapGestureRecognizer startTrack];
// [NSURLConnection startTrack];
if ([YHEventReport sharedInstance].isButtonPerformanceTrackEnable) {
[UIControl startTrack];
[UITapGestureRecognizer startTrack];
}
if ([YHEventReport sharedInstance].isHttpPerformanceTrackEnable) {
[NSURLConnection startTrack];
//[NSURLSession startTrack];
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
... ...
... ... @@ -10,8 +10,6 @@
@interface NSURLConnection (AutoTrack)
@property(nonatomic,copy)NSString *yh_viewId;//唯一ID
+(void)startTrack;
@end
... ...
... ... @@ -12,50 +12,16 @@
#import <objc/message.h>
#import "YHEventReport.h"
#import "YHLog.h"
#import "YHSwizzle.h"
typedef void(^ActionHandlerBlock)(NSURLResponse* _Nullable response, NSData* _Nullable data, NSError* _Nullable connectionError);
static const void *yher_actionHandlerBlock = &yher_actionHandlerBlock;
#import "YH_EventCollector.h"
@interface NSURLConnection()
@property(nullable,nonatomic,weak) id my_delegate;
@property (nonatomic, copy) ActionHandlerBlock actionHandlerBlock;
@end
@implementation NSURLConnection (AutoTrack)
#pragma mark - 属性
- (ActionHandlerBlock)actionHandlerBlock{
return objc_getAssociatedObject(self, @selector(actionHandlerBlock));
}
- (void)setActionHandlerBlock:(ActionHandlerBlock)actionHandlerBlock{
objc_setAssociatedObject(self, @selector(actionHandlerBlock), actionHandlerBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (void)setYh_viewId:(NSString *)yh_viewId{
objc_setAssociatedObject(self,@selector(yh_viewId),yh_viewId,OBJC_ASSOCIATION_RETAIN);
}
- (NSString *)yh_viewId{
return objc_getAssociatedObject(self, @selector(yh_viewId));
}
- (id)my_delegate
{
return objc_getAssociatedObject(self, _cmd);
}
- (void)setMy_delegate:(id)my_delegate
{
objc_setAssociatedObject(self, @selector(my_delegate), my_delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
+(void)startTrack{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
... ... @@ -110,14 +76,12 @@ static const void *yher_actionHandlerBlock = &yher_actionHandlerBlock;
- (nullable instancetype)yher_initWithRequest:(NSURLRequest *)request delegate:(nullable id)delegate startImmediately:(BOOL)startImmediately
{
[self setMy_delegate:delegate];
return [self yher_initWithRequest:request delegate:self startImmediately:startImmediately];
return [self yher_initWithRequest:request delegate:delegate startImmediately:startImmediately];
}
- (nullable instancetype)yher_initWithRequest:(NSURLRequest *)request delegate:(nullable id)delegate
{
[self setMy_delegate:delegate];
return [self yher_initWithRequest:request delegate:self];
return [self yher_initWithRequest:request delegate:delegate];
}
- (void)yher_start
... ... @@ -127,48 +91,41 @@ static const void *yher_actionHandlerBlock = &yher_actionHandlerBlock;
+ (nullable NSData *)yher_sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse * _Nullable * _Nullable)response error:(NSError **)error
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventStartWithCollectionURL:[request.URL absoluteString]];
}
NSData *data = [self yher_sendSynchronousRequest:request returningResponse:response error:error];
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (error) {
[[YH_EventCollector sharedInstance] timeEventEndWithCollectionURL:[request.URL absoluteString] status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithCollectionURL:[request.URL absoluteString] status:YHEventLoadStatusSuc];
}
}
return data;
}
+ (void)yher_sendAsynchronousRequest:(NSURLRequest*) request
queue:(NSOperationQueue*) queue
completionHandler:(void (^)(NSURLResponse* _Nullable response, NSData* _Nullable data, NSError* _Nullable connectionError)) handler
queue:(NSOperationQueue*) queue
completionHandler:(void (^)(NSURLResponse* _Nullable response, NSData* _Nullable data, NSError* _Nullable connectionError)) handler
{
objc_setAssociatedObject(self, yher_actionHandlerBlock, handler, OBJC_ASSOCIATION_COPY_NONATOMIC);
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventStartWithCollectionURL:[request.URL absoluteString]];
}
[self yher_sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
ActionHandlerBlock actionHandlerBlock = objc_getAssociatedObject(self, yher_actionHandlerBlock);
if (actionHandlerBlock) {
actionHandlerBlock(response,data,connectionError);
if (handler) {
handler(response,data,connectionError);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (connectionError) {
[[YH_EventCollector sharedInstance] timeEventEndWithCollectionURL:[request.URL absoluteString] status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithCollectionURL:[request.URL absoluteString] status:YHEventLoadStatusSuc];
}
}
}];
}
#pragma mark - NSURLConnectionDelegate
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(connection:didReceiveResponse:)]) {
[self.my_delegate connection:connection didReceiveResponse:response];
}
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(connection:didReceiveData:)]) {
[self.my_delegate connection:connection didReceiveData:data];
}
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(connectionDidFinishLoading:)]) {
[self.my_delegate connectionDidFinishLoading:connection];
}
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(connection:didFailWithError:)]) {
[self.my_delegate connection:connection didFailWithError:error];
}
}
@end
... ...
... ... @@ -10,4 +10,14 @@
@interface NSURLSession (AutoTrack)
+(void)startTrack;
@end
@interface NSURLSessionTask (AutoTrack)
@property(nonatomic,copy)NSString *yh_viewId;//唯一ID
+(void)startTrack;
@end
... ...
... ... @@ -7,7 +7,243 @@
//
#import "NSURLSession+AutoTrack.h"
#import "YHSwizzle.h"
#import <objc/runtime.h>
#import <objc/message.h>
#import "YHEventReport.h"
#import "YHLog.h"
#import "YH_EventCollector.h"
@interface NSURLSession()
@end
@implementation NSURLSession (AutoTrack)
#pragma mark - 属性
+(void)startTrack{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@try {
[NSURLSessionTask startTrack];
SEL class_selectors[] = {
@selector(dataTaskWithRequest:completionHandler:),
@selector(dataTaskWithURL:completionHandler:),
@selector(uploadTaskWithRequest:fromData:completionHandler:),
@selector(uploadTaskWithRequest:fromFile:completionHandler:),
@selector(downloadTaskWithRequest:completionHandler:),
@selector(downloadTaskWithURL:completionHandler:),
@selector(downloadTaskWithResumeData:completionHandler:),
};
for (NSUInteger index = 0; index < sizeof(class_selectors) / sizeof(SEL); ++index) {
Class selfClass = object_getClass([self class]);
SEL oriSEL = class_selectors[index];
Method oriMethod = class_getClassMethod(selfClass, oriSEL);
SEL cusSEL = NSSelectorFromString([@"yher_" stringByAppendingString:NSStringFromSelector(oriSEL)]);
Method cusMethod = class_getClassMethod(selfClass, cusSEL);
BOOL addSucc = class_addMethod(selfClass, oriSEL, method_getImplementation(cusMethod), method_getTypeEncoding(cusMethod));
if (addSucc) {
class_replaceMethod(selfClass, cusSEL, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
}else {
method_exchangeImplementations(oriMethod, cusMethod);
}
}
} @catch (NSException *exception) {
YHLog(@"%@ error: %@", self, exception);
}
});
}
- (NSURLSessionDataTask *)yher_dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler
{
__block NSURLSessionDataTask *task = [self yher_dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (completionHandler) {
completionHandler(data,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (error) {
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusSuc];
}
}
}];
return task;
}
- (NSURLSessionDataTask *)yher_dataTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler
{
__block NSURLSessionDataTask *task = [self yher_dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (completionHandler) {
completionHandler(data,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (error) {
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusSuc];
}
}
}];
return task;
}
- (NSURLSessionUploadTask *)yher_uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler
{
__block NSURLSessionUploadTask *task = [self yher_uploadTaskWithRequest:request fromFile:fileURL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (completionHandler) {
completionHandler(data,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (error) {
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusSuc];
}
}
}];
return task;
}
- (NSURLSessionUploadTask *)yher_uploadTaskWithRequest:(NSURLRequest *)request fromData:(nullable NSData *)bodyData completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler
{
__block NSURLSessionUploadTask *task = [self yher_uploadTaskWithRequest:request fromData:bodyData completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (completionHandler) {
completionHandler(data,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (error) {
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusSuc];
}
}
}];
return task;
}
- (NSURLSessionDownloadTask *)yher_downloadTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler
{
__block NSURLSessionDownloadTask *task = [self yher_downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (completionHandler) {
completionHandler(location,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (error) {
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusSuc];
}
}
}];
return task;
}
- (NSURLSessionDownloadTask *)yher_downloadTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler
{
__block NSURLSessionDownloadTask *task = [self yher_downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (completionHandler) {
completionHandler(location,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (error) {
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusSuc];
}
}
}];
return task;
}
- (NSURLSessionDownloadTask *)yher_downloadTaskWithResumeData:(NSData *)resumeData completionHandler:(void (^)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler
{
__block NSURLSessionDownloadTask *task = [self yher_downloadTaskWithResumeData:resumeData completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (completionHandler) {
completionHandler(location,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
if (error) {
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusFailed];
}else{
[[YH_EventCollector sharedInstance] timeEventEndWithSessionTask:task status:YHEventLoadStatusSuc];
}
}
}];
return task;
}
@end
@implementation NSURLSessionTask (AutoTrack)
- (void)setYh_viewId:(NSString *)yh_viewId{
objc_setAssociatedObject(self,@selector(yh_viewId),yh_viewId,OBJC_ASSOCIATION_RETAIN);
}
- (NSString *)yh_viewId{
return objc_getAssociatedObject(self, @selector(yh_viewId));
}
+(void)startTrack{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@try {
SEL class_selectors[] = {
@selector(resume),
};
for (NSUInteger index = 0; index < sizeof(class_selectors) / sizeof(SEL); ++index) {
Class selfClass = object_getClass([self class]);
SEL oriSEL = class_selectors[index];
Method oriMethod = class_getClassMethod(selfClass, oriSEL);
SEL cusSEL = NSSelectorFromString([@"yher_" stringByAppendingString:NSStringFromSelector(oriSEL)]);
Method cusMethod = class_getClassMethod(selfClass, cusSEL);
BOOL addSucc = class_addMethod(selfClass, oriSEL, method_getImplementation(cusMethod), method_getTypeEncoding(cusMethod));
if (addSucc) {
class_replaceMethod(selfClass, cusSEL, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
}else {
method_exchangeImplementations(oriMethod, cusMethod);
}
}
} @catch (NSException *exception) {
YHLog(@"%@ error: %@", self, exception);
}
});
}
- (void)yher_resume
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventStartWithSession:self];
}
[self yher_resume];
}
@end
... ...
... ... @@ -117,10 +117,11 @@
NSString *selectorAction = NSStringFromSelector(action);
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && [self isKindOfClass:[UIButton class]]) {
if ([selectorAction rangeOfString:@":"].location !=NSNotFound) {
[UIControl yher_exchangeSelector:action target:target toSelector:@selector(yher_UIControl_didTouch_cmdWithEvent:)];
}else{
if ([[selectorAction componentsSeparatedByString:@":"]count]==1) {
[UIControl yher_exchangeSelector:action target:target toSelector:@selector(yher_UIControl_didTouch_cmd)];
}else if ([[selectorAction componentsSeparatedByString:@":"]count]==2){
[UIControl yher_exchangeSelector:action target:target toSelector:@selector(yher_UIControl_didTouch_cmdWithEvent:)];
}
}
... ...
... ... @@ -56,16 +56,24 @@
#pragma mark - hook API
- (instancetype)yher_initWithTarget:(nullable id)target action:(nullable SEL)action
{
NSString *selectorAction = NSStringFromSelector(action);
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([target isKindOfClass:[UIViewController class]] || [target isKindOfClass:[UIImageView class]] || [target isKindOfClass:[UILabel class]])) {
[UITapGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
if ([[selectorAction componentsSeparatedByString:@":"]count]==1) {
[UITapGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
}
}
return [self yher_initWithTarget:target action:action];
}
- (void)yher_addTarget:(id)target action:(SEL)action
{
NSString *selectorAction = NSStringFromSelector(action);
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].buttonPerformanceTrackEnable && ([target isKindOfClass:[UIViewController class]] || [target isKindOfClass:[UIImageView class]] || [target isKindOfClass:[UILabel class]])) {
[UITapGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
if ([[selectorAction componentsSeparatedByString:@":"]count]==1) {
[UITapGestureRecognizer yher_exchangeSelector:action target:target toSelector:@selector(yher_gestureRecognizerDidTouch_cmd:)];
}
}
[self yher_addTarget:target action:action];
... ...
... ... @@ -257,6 +257,59 @@
return performanceAryDic;
}
-(NSString *)getPointName:(YHEventReportPointName)pointName{
NSString *str = @"";
switch (pointName) {
case YHPN_VIEWCONTROLLER:
str = @"PAGE";
break;
case YHPN_WEBVIEW:
str = @"WEBVIEW";
break;
case YHPN_IMAGEVIEW:
str = @"IMAGE";
break;
case YHPN_BUTTON:
str = @"BUTTON";
break;
case YHPN_GESTURERECOGNIZER:
str = @"GESTURERECOGNIZER";
break;
case YHPN_HTTP:
str = @"HTTP";
break;
default:
break;
}
return str;
}
-(NSString *)getDataType:(YHEventReportTrackDataType)type{
NSString *str = @"";
switch (type) {
case YHEventReportTrackDataTypeStart:
str = @"start";
break;
case YHEventReportTrackDataTypeDestory:
str = @"destory";
break;
case YHEventReportTrackDataTypeStop:
str = @"stop";
break;
case YHEventReportTrackDataTypeHeartbeat:
str = @"hb";
break;
case YHEventReportTrackDataTypeNONE:
str = @"realTime";
break;
default:
break;
}
return str;
}
- (void)refreshPushStatus
{
... ...
... ... @@ -30,6 +30,20 @@
- (void)timeEventStartWithUIGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
- (void)timeEventEndWithUIGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
- (void)timeEventStartWithCollectionURL:(NSString *)collectionURL;
- (void)timeEventEndWithCollectionURL:(NSString *)collectionURL status:(YHEventLoadStatus)status;
- (void)timeEventStartWithSession:(NSURLSessionTask*)sessionTask;
- (void)timeEventEndWithSessionTask:(NSURLSessionTask *)sessionTask status:(YHEventLoadStatus)status;
+ (void)trackAppClickWithView:(id)targetView UITableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
+ (void)trackAppClickWithView:(id)targetView UICollectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
+ (void)trackAppClickWithView:(id)targetView UITabbar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;
+ (void)trackAppClickWithView:(id)targetView UIAlertView:(UIAlertView *)alertView didSelectIndex:(NSInteger )buttonIndex;
+ (NSString *)viewPathOfPurposeView:(UIView *)purposeView;
@end
... ...
... ... @@ -19,6 +19,8 @@
#import "UITabBarItem+Yoho.h"
#import "UIControl+AutoTrack.h"
#import "UITapGestureRecognizer+AutoTrack.h"
#import "NSURLSession+AutoTrack.h"
#import "NSURLConnection+AutoTrack.h"
#define kYHEventReportQueue @"YHEventReportQueue"
#define kYHEventReporrH5StartKey @"YHEventReporrH5StartKey"
... ... @@ -394,6 +396,89 @@
}
#pragma mark - http performance time
- (void)timeEventStartWithCollectionURL:(NSString *)collectionURL
{
NSNumber *startTime = @([[NSDate date] timeIntervalSince1970]);
NSString *viewId = [NSString stringWithFormat:@"%@",collectionURL];
NSLog(@"startTime = %f",[[NSDate date] timeIntervalSince1970]);
if (startTime==0||IsStrEmpty(viewId)) {
return;
}
if (!collectionURL) {
return;
}
dispatch_async(self.serialQueue, ^{
self.timedEvents[viewId] = startTime;
});
}
- (void)timeEventEndWithCollectionURL:(NSString *)collectionURL status:(YHEventLoadStatus)status
{
NSTimeInterval elapsedTime = [self eventElapsedTime:collectionURL];
if (elapsedTime==0) {
return;
}
if (!IsStrEmpty(collectionURL)) {
dispatch_async(self.serialQueue, ^{
[self.timedEvents removeObjectForKey:collectionURL];
});
}
NSDictionary *param = [YH_EventDataFactory factoryTimeEventDataWithHttp:collectionURL ElapsedTime:elapsedTime];
NSLog(@"%@",param);
if (param) {
[[YH_EventCacheManager sharedInstance] pushPerformanceData:param pointName:YHPN_HTTP];
}
}
- (void)timeEventStartWithSession:(NSURLSessionTask*)sessionTask
{
NSNumber *startTime = @([[NSDate date] timeIntervalSince1970]);
NSString *viewId = [NSString stringWithFormat:@"%@%@",NSStringFromClass([sessionTask class]),startTime];
NSLog(@"startTime = %f",[[NSDate date] timeIntervalSince1970]);
if (startTime==0||IsStrEmpty(viewId)) {
return;
}
if (!sessionTask) {
return;
}
sessionTask.yh_viewId=viewId;
dispatch_async(self.serialQueue, ^{
self.timedEvents[viewId] = startTime;
});
}
- (void)timeEventEndWithSessionTask:(NSURLSessionTask *)sessionTask status:(YHEventLoadStatus)status
{
NSTimeInterval elapsedTime = [self eventElapsedTime:sessionTask.yh_viewId];
if (elapsedTime==0) {
return;
}
if (!IsStrEmpty(sessionTask.yh_viewId)) {
dispatch_async(self.serialQueue, ^{
[self.timedEvents removeObjectForKey:sessionTask.yh_viewId];
});
}
NSDictionary *param = [YH_EventDataFactory factoryTimeEventDataWithHttp:sessionTask ElapsedTime:elapsedTime];
NSLog(@"%@",param);
if (param) {
[[YH_EventCacheManager sharedInstance] pushPerformanceData:param pointName:YHPN_HTTP];
}
}
@end
... ...
... ... @@ -93,6 +93,7 @@ typedef NS_ENUM(NSInteger, YHEventReportPointName) {
YHPN_WEBVIEW,//UIWebView 加载时间 // @"WEBVIEW"
YHPN_IMAGEVIEW,//Image (SDWebImage) 加载时间 // @"IMAGE"
YHPN_BUTTON,//Button 响应时间 // @"BUTTON"
YHPN_TIMEOUT, //网络事件 -网络超时
YHPN_CODE_ERR , //网络事件- 有错误码返回的错误
YHPN_H5_FEATURE_META_FAILED, //feature.yoho.cn的H5页面meta校验失败
... ... @@ -118,7 +119,10 @@ typedef NS_ENUM(NSInteger, YHEventReportPointName) {
YHPN_BUSINESS_ORDER_ACCOUNT,//结算订单相关业务错误
YHPN_BUSINESS_ORDER_CONFIRM,//确认订单相关业务错误
YHPN_BUSINESS_ORDER_PAY,//支付相关业务错误
YHPN_GESTURERECOGNIZER //UITapGestureRecognizer响应时间// @"GESTURERECOGNIZER"
YHPN_GESTURERECOGNIZER, //UITapGestureRecognizer响应时间// @"GESTURERECOGNIZER"
YHPN_HTTP //HTTP响应时间// @"HTTP"
};
typedef NS_ENUM(NSInteger, YHEventReportType) {
... ...
... ... @@ -31,4 +31,6 @@
+(NSString *)getDataType:(YHEventReportTrackDataType)type;
+(NSDictionary *)factoryTimeEventDataWithHttp:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime;
@end
... ...
... ... @@ -79,6 +79,15 @@
return dict;
}
+(NSDictionary *)factoryTimeEventDataWithHttp:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime {
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,@"",kYHEventReportTimeTitle,nil];
return dict;
}
+ (NSDictionary *)factoryEventAppInfo:(YH_PerformanceAppInfo*)appInfo
{
if (IsNilOrNull(appInfo)) {
... ...