Authored by 孙凯

add http review by daiqiang

... ... @@ -132,7 +132,7 @@
- (void)yher_start
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventStartWithRequest:self.currentRequest];
[[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[self.currentRequest.URL absoluteString]];
}
[self yher_start];
}
... ... @@ -140,13 +140,19 @@
+ (nullable NSData *)yher_sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse * _Nullable * _Nullable)response error:(NSError **)error
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventStartWithRequest:request];
[[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[request.URL absoluteString]];
}
NSData *data = [self yher_sendSynchronousRequest:request returningResponse:response error:error];
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventEndWithRequest:request response:*response];
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && !error && ![[request.URL absoluteString] isEqualToString:@"http://app.yoho.cn/collect/v2"]) {
NSURLResponse *res = *response;
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)res;
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
NSString *statusCode = [NSString stringWithFormat:@"%lld",httpResponse.statusCode];
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[request.URL absoluteString] HTTPMethod:request.HTTPMethod statusCode:statusCode contentLength:contentLength];
}
return data;
}
... ... @@ -157,15 +163,22 @@
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventStartWithRequest:request];
[[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[request.URL absoluteString]];
}
[self yher_sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
if (handler) {
handler(response,data,connectionError);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventEndWithRequest:request response:response];
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && !connectionError && ![[request.URL absoluteString] isEqualToString:@"http://app.yoho.cn/collect/v2"]) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
NSString *statusCode = [NSString stringWithFormat:@"%lld",httpResponse.statusCode];
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[request.URL absoluteString] HTTPMethod:request.HTTPMethod statusCode:statusCode contentLength:contentLength];
}
}];
}
... ... @@ -189,8 +202,13 @@
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(connectionDidFinishLoading:)]) {
[self.my_delegate connectionDidFinishLoading:connection];
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventEndWithRequest:connection.currentRequest response:connection.my_response];
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && ![[connection.currentRequest.URL absoluteString] isEqualToString:@"http://app.yoho.cn/collect/v2"]) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)connection.my_response;
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
NSString *statusCode = [NSString stringWithFormat:@"%lld",httpResponse.statusCode];
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[connection.currentRequest.URL absoluteString] HTTPMethod:connection.currentRequest.HTTPMethod statusCode:statusCode contentLength:contentLength];
}
}
... ... @@ -198,9 +216,6 @@
if (self.my_delegate && [self.my_delegate respondsToSelector:@selector(connection:didFailWithError:)]) {
[self.my_delegate connection:connection didFailWithError:error];
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventEndWithRequest:connection.currentRequest response:nil];
}
}
... ...
... ... @@ -63,8 +63,13 @@
if (completionHandler) {
completionHandler(data,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventEndWithRequest:request response:response];
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && !error && ![[request.URL absoluteString] isEqualToString:@"http://app.yoho.cn/collect/v2"]) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
NSString *statusCode = [NSString stringWithFormat:@"%lld",httpResponse.statusCode];
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[request.URL absoluteString] HTTPMethod:request.HTTPMethod statusCode:statusCode contentLength:contentLength];
}
}];
}
... ... @@ -80,8 +85,13 @@
if (completionHandler) {
completionHandler(location,response,error);
}
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
[[YH_EventCollector sharedInstance] timeEventEndWithRequest:request response:response];
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable && !error && ![[request.URL absoluteString] isEqualToString:@"http://app.yoho.cn/collect/v2"]) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
NSDictionary *httpResponseHeaderFields = [httpResponse allHeaderFields];
NSString *contentLength = [NSString stringWithFormat:@"%lld",[[httpResponseHeaderFields objectForKey:@"Content-Length"] longLongValue]];
NSString *statusCode = [NSString stringWithFormat:@"%lld",httpResponse.statusCode];
[[YH_EventCollector sharedInstance] timeEventEndWithRequestUrl:[request.URL absoluteString] HTTPMethod:request.HTTPMethod statusCode:statusCode contentLength:contentLength];
}
}];
}
... ... @@ -138,7 +148,7 @@ static inline BOOL yher_addMethod(Class class, SEL selector, Method method) {
{
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].httpPerformanceTrackEnable) {
NSURLSessionTask *task = (NSURLSessionTask*)self;
[[YH_EventCollector sharedInstance] timeEventStartWithRequest:task.currentRequest];
[[YH_EventCollector sharedInstance] timeEventStartWithRequestUrl:[task.currentRequest.URL absoluteString]];
}
[self yher_resume];
}
... ...
... ... @@ -30,8 +30,8 @@
- (void)timeEventStartWithUIGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
- (void)timeEventEndWithUIGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
- (void)timeEventStartWithRequest:(NSURLRequest*)request;
- (void)timeEventEndWithRequest:(NSURLRequest*)request response:(NSURLResponse*)response;
- (void)timeEventStartWithRequestUrl:(NSString*)requestUrl;
- (void)timeEventEndWithRequestUrl:(NSString*)requestUrl HTTPMethod:(NSString*)method statusCode:(NSString*)statusCode contentLength:(NSString*)length;
- (void)timeEventEndWithUITableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath;
- (void)timeEventStartWithUITableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath;
... ...
... ... @@ -550,18 +550,18 @@
}
#pragma mark - http performance time
- (void)timeEventStartWithRequest:(NSURLRequest*)request
- (void)timeEventStartWithRequestUrl:(NSString*)requestUrl
{
NSString *collectionURL = [[request URL]absoluteString];
NSNumber *startTime = @([[NSDate date] timeIntervalSince1970]);
NSString *viewId = [NSString stringWithFormat:@"%@",collectionURL];
NSString *viewId = [NSString stringWithFormat:@"%@",requestUrl];
NSLog(@"startTime = %f",[[NSDate date] timeIntervalSince1970]);
if (startTime==0||IsStrEmpty(viewId)) {
return;
}
if (!collectionURL) {
if (!requestUrl) {
return;
}
... ... @@ -570,21 +570,20 @@
});
}
- (void)timeEventEndWithRequest:(NSURLRequest*)request response:(NSURLResponse*)response
- (void)timeEventEndWithRequestUrl:(NSString*)requestUrl HTTPMethod:(NSString*)method statusCode:(NSString*)statusCode contentLength:(NSString*)length
{
NSString *collectionURL = [[request URL]absoluteString];
NSTimeInterval elapsedTime = [self eventElapsedTime:collectionURL];
NSTimeInterval elapsedTime = [self eventElapsedTime:requestUrl];
if (elapsedTime==0) {
return;
}
if (!IsStrEmpty(collectionURL)) {
if (!IsStrEmpty(requestUrl)) {
dispatch_async(self.serialQueue, ^{
[self.timedEvents removeObjectForKey:collectionURL];
[self.timedEvents removeObjectForKey:requestUrl];
});
}
NSDictionary *param = [YH_EventDataFactory factoryTimeEventDataWithRequest:request response:response ElapsedTime:elapsedTime];
NSDictionary *param = [YH_EventDataFactory factoryTimeEventDataWithRequestUrl:requestUrl HTTPMethod:method statusCode:statusCode contentLength:length ElapsedTime:elapsedTime];
NSLog(@"%@",param);
if (param) {
... ...
... ... @@ -35,6 +35,6 @@
+(NSString *)getDataType:(YHEventReportTrackDataType)type;
+(NSDictionary *)factoryTimeEventDataWithRequest:(NSURLRequest*)request response:(NSURLResponse*)response ElapsedTime:(NSTimeInterval)elapsedTime;
+(NSDictionary *)factoryTimeEventDataWithRequestUrl:(NSString*)requestUrl HTTPMethod:(NSString*)method statusCode:(NSString*)statusCode contentLength:(NSString*)length ElapsedTime:(NSTimeInterval)elapsedTime;
@end
... ...
... ... @@ -106,11 +106,10 @@
}
+(NSDictionary *)factoryTimeEventDataWithRequest:(NSURLRequest*)request response:(NSURLResponse*)response ElapsedTime:(NSTimeInterval)elapsedTime
+(NSDictionary *)factoryTimeEventDataWithRequestUrl:(NSString*)requestUrl HTTPMethod:(NSString*)method statusCode:(NSString*)statusCode contentLength:(NSString*)length ElapsedTime:(NSTimeInterval)elapsedTime
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSString *status = [NSString stringWithFormat:@"%ld",(long)[httpResponse statusCode]];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[[request.URL absoluteString] er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,status,kYHEventReportTimeHttpCode,[NSString stringWithFormat:@"%lld",response.expectedContentLength],kYHEventReportTimeHttpLength,request.HTTPMethod,kYHEventReportTimeHttpMethod,@"",kYHEventReportTimeHttpEi,nil];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[requestUrl er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,statusCode,kYHEventReportTimeHttpCode,length,kYHEventReportTimeHttpLength,method,kYHEventReportTimeHttpMethod,@"",kYHEventReportTimeHttpEi,nil];
return dict;
}
... ...