Authored by ZhangTonghai

【add】增加pagechain

... ... @@ -314,6 +314,7 @@ typedef NS_ENUM(NSInteger, YHPointType) {
#define YOHOAppReportCrashSignalName @"sign" // 中断信号名称
#define YOHOAppReportCrashExceptionName @"exn" // 异常名称
#define YOHOAppReportCrashExceptionReason @"exr" // 异常原因
#define YOHOAppReportCrashPageChain @"pagechain"// 异常页面调用流
... ...
... ... @@ -63,6 +63,15 @@
if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isControllerPerformanceTrackEnable && ![[YHEventReport sharedInstance] isPerformanceViewControllerStringIgnored:NSStringFromClass([self class])]) {
[[YH_EventCollector sharedInstance] timeEventEndWithViewController:self];
}
if ([YHEventReport sharedInstance].isAppCrashReportEnable && [YHEventReport sharedInstance].isAutoTrackEnabled) {
//UICompatibilityInputViewController,UIInputWindowController,UISystemKeyboardDockController
if (![self isKindOfClass:[UINavigationController class]] && [self isKindOfClass:NSClassFromString(@"YH_ViewController")]) {
[[YH_EventCollector sharedInstance] pageChainEventWithViewController:self];
}else{
// UIViewController *controller = [[(UINavigationController *)self viewControllers] firstObject];
// [[YH_EventCollector sharedInstance] pageChainEventWithViewController:controller];
}
}
} @catch (NSException *exception) {
YHLog(@"%@ error: %@", self, exception);
}
... ...
... ... @@ -13,6 +13,7 @@
#import "YHEventReportMacros.h"
#import "YHLog.h"
#import "YHEventReport.h"
#import "YH_EventCollector.h"
#pragma mark - C Fuctions
... ... @@ -29,10 +30,12 @@ void yh_sighandler(int signal)
YH_CrashReporter *crash = [[YH_CrashReporter alloc] init];
NSString *str = [crash callstackString];
NSString *pageChains = [[YH_EventCollector sharedInstance] pageChainStr] ?:@"";
NSDictionary *userInfo = @{
YOHOAppReportCrashCallstack : str,
YOHOAppReportCrashSignal : @(signal),
YOHOAppReportCrashSignalName : [NSString stringWithUTF8String:names[signal]],
YOHOAppReportCrashPageChain : pageChains,
};
[crash performSelectorOnMainThread:@selector(handleSignal:) withObject:userInfo waitUntilDone:YES];
}
... ... @@ -43,10 +46,12 @@ void yh_uncaughtCrashExceptionHandler(NSException *exception)
NSArray *arr = [exception callStackSymbols];
NSString *str = [crash getStringFromArray:arr];
NSString *pageChains = [[YH_EventCollector sharedInstance] pageChainStr] ?:@"";
NSDictionary *userInfo = @{
YOHOAppReportCrashCallstack : str,
YOHOAppReportCrashExceptionName : exception.name,
YOHOAppReportCrashExceptionReason : exception.reason,
YOHOAppReportCrashPageChain : pageChains,
};
[crash performSelectorOnMainThread:@selector(handleNSException:) withObject:userInfo waitUntilDone:YES];
}
... ...
... ... @@ -39,6 +39,10 @@
- (void)timeEventStartWithView:(id)targetView collectionView:(UICollectionView*)collectionView indexPath:(NSIndexPath*)indexPath;
- (void)timeEventEndWithView:(id)targetView collectionView:(UICollectionView*)collectionView indexPath:(NSIndexPath*)indexPath;
/**记录页面调用链*/
- (void)pageChainEventWithViewController:(UIViewController *)viewController;
/**获取页面调用链,以逗号隔开*/
- (NSString *)pageChainStr;
+ (NSString *)viewPathOfPurposeView:(UIView *)purposeView;
... ...
... ... @@ -34,6 +34,8 @@
@property (nonatomic) dispatch_queue_t serialQueue;
@property (nonatomic, strong) NSMutableDictionary *timedEvents;
@property (nonatomic, strong) NSMutableArray *tabViewControllerArray;
/**页面调用链*/
@property (nonatomic, strong) NSMutableArray *pageChains;
@end
... ... @@ -55,7 +57,7 @@
if (self=[super init]) {
self.serialQueue = dispatch_queue_create([kYHEventReportQueue UTF8String], DISPATCH_QUEUE_SERIAL);
self.timedEvents = [NSMutableDictionary dictionary];
self.pageChains = [NSMutableArray array];
NSArray *tabAry= @[];
self.tabViewControllerArray = [NSMutableArray arrayWithArray:tabAry];
... ... @@ -617,6 +619,30 @@
}
}
#pragma mark - record page chain
- (void)pageChainEventWithViewController:(UIViewController *)viewController
{
if (!viewController) {
return;
}
dispatch_async(self.serialQueue, ^{
if (self.pageChains.count > 10) {
[self.pageChains removeObjectAtIndex:0];
}
[self.pageChains addObject:[NSString stringWithFormat:@"%@",[viewController class]]];
});
}
- (NSString *)pageChainStr
{
if (!self.pageChains || self.pageChains.count == 0) {
return nil;
}
return [[[self.pageChains reverseObjectEnumerator] allObjects] componentsJoinedByString:@","];
}
@end
... ...