Authored by 于良

增加卡顿监控,review by 戴强

... ... @@ -9,7 +9,7 @@
Pod::Spec.new do |s|
s.name = "YHEventReport"
s.version = "0.5.8"
s.version = "0.6.0"
s.summary = "YHEventReport."
s.description = "无埋点SDK"
s.homepage = "http://git.yoho.cn/mobile/YH_EventReport"
... ... @@ -34,11 +34,55 @@ Pod::Spec.new do |s|
s.default_subspec = 'classes'
s.subspec 'Core' do |ss|
ss.source_files = 'YHEventReport/YHEventReport/YHEventReport/**/*.{h,m}'
ss.source_files = 'YHEventReport/YHEventReport/YHEventReport/YH_Core/*.{h,m}'
ss.xcconfig = { "HEADER_SEARCH_PATHS" => [
"${PODS_ROOT}/../YH_Mall/Dependences/PowerfulBannerView",
].join(' ')
}
end
s.subspec "AOP" do |ss|
ss.dependency "YHEventReport/Core"
ss.source_files = 'YHEventReport/YHEventReport/YHEventReport/YH_AOP/*.{h,m}'
end
s.subspec "EventCollector" do |ss|
ss.dependency "YHEventReport/Core"
ss.dependency "YHEventReport/AOP"
ss.source_files = 'YHEventReport/YHEventReport/YHEventReport/YH_EventCollector/*.{h,m}'
end
s.subspec "EventCache" do |ss|
ss.dependency "YHEventReport/Core"
ss.dependency "YHEventReport/AOP"
ss.dependency "YHEventReport/EventCollector"
ss.source_files = 'YHEventReport/YHEventReport/YHEventReport/YH_EventCache/*.{h,m}'
end
s.subspec "EventDataSession" do |ss|
ss.dependency "YHEventReport/Core"
ss.dependency "YHEventReport/AOP"
ss.dependency "YHEventReport/EventCollector"
ss.dependency "YHEventReport/EventCache"
ss.source_files = 'YHEventReport/YHEventReport/YHEventReport/YH_EventDataSession/*.{h,m}'
end
s.subspec "CrashReporter" do |ss|
ss.dependency "YHEventReport/Core"
ss.dependency "YHEventReport/AOP"
ss.dependency "YHEventReport/EventCollector"
ss.dependency "YHEventReport/EventCache"
ss.dependency "YHEventReport/EventDataSession"
ss.source_files = 'YHEventReport/YHEventReport/YHEventReport/YH_CrashReporter/*.{h,m}'
end
s.subspec "LagHunter" do |ss|
ss.dependency "YHEventReport/Core"
ss.dependency "YHEventReport/AOP"
ss.dependency "YHEventReport/EventCollector"
ss.dependency "YHEventReport/EventCache"
ss.dependency "YHEventReport/EventDataSession"
ss.source_files = 'YHEventReport/YHEventReport/YHEventReport/YH_LagHunter/*.{h,m}'
end
end
... ...
... ... @@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
2906173F1FEB8E8B00BD569F /* YHEventReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 2906173E1FEB8E8B00BD569F /* YHEventReport.m */; };
290617431FEB951300BD569F /* YH_LagHunter.m in Sources */ = {isa = PBXBuildFile; fileRef = 290617421FEB951300BD569F /* YH_LagHunter.m */; };
2955040E1F66B4A1006A3F14 /* UIApplication+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 2955040D1F66B4A1006A3F14 /* UIApplication+AutoTrack.m */; };
295504111F67B78F006A3F14 /* UITableViewCell+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 295504101F67B78F006A3F14 /* UITableViewCell+AutoTrack.m */; };
29CDB4AD1F6FA57900AAD350 /* InfiniteScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 29CDB4AA1F6FA57900AAD350 /* InfiniteScrollView.m */; };
... ... @@ -30,7 +32,6 @@
5255C2BE1F5D25F400A8FC5F /* YH_EventUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 5255C2B11F5D25F400A8FC5F /* YH_EventUtil.m */; };
5255C2BF1F5D25F400A8FC5F /* YH_EventDataSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 5255C2B41F5D25F400A8FC5F /* YH_EventDataSession.m */; };
5255C2C01F5D25F400A8FC5F /* YH_Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 5255C2B61F5D25F400A8FC5F /* YH_Reachability.m */; };
5255C2C11F5D25F400A8FC5F /* YHEventReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 5255C2B81F5D25F400A8FC5F /* YHEventReport.m */; };
52878BFB1F5D44F7000A1597 /* YH_EventCollector.m in Sources */ = {isa = PBXBuildFile; fileRef = 52878BFA1F5D44F7000A1597 /* YH_EventCollector.m */; };
52878C041F5E8904000A1597 /* YHLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 52878C031F5E8904000A1597 /* YHLog.m */; };
52878C071F5F8D82000A1597 /* UIView+Yoho.m in Sources */ = {isa = PBXBuildFile; fileRef = 52878C061F5F8D82000A1597 /* UIView+Yoho.m */; };
... ... @@ -94,6 +95,10 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
2906173D1FEB8E8B00BD569F /* YHEventReport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YHEventReport.h; sourceTree = "<group>"; };
2906173E1FEB8E8B00BD569F /* YHEventReport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YHEventReport.m; sourceTree = "<group>"; };
290617411FEB951300BD569F /* YH_LagHunter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YH_LagHunter.h; sourceTree = "<group>"; };
290617421FEB951300BD569F /* YH_LagHunter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YH_LagHunter.m; sourceTree = "<group>"; };
2955040C1F66B4A1006A3F14 /* UIApplication+AutoTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIApplication+AutoTrack.h"; sourceTree = "<group>"; };
2955040D1F66B4A1006A3F14 /* UIApplication+AutoTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+AutoTrack.m"; sourceTree = "<group>"; };
2955040F1F67B78F006A3F14 /* UITableViewCell+AutoTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableViewCell+AutoTrack.h"; sourceTree = "<group>"; };
... ... @@ -140,8 +145,6 @@
5255C2B41F5D25F400A8FC5F /* YH_EventDataSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_EventDataSession.m; sourceTree = "<group>"; };
5255C2B51F5D25F400A8FC5F /* YH_Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_Reachability.h; sourceTree = "<group>"; };
5255C2B61F5D25F400A8FC5F /* YH_Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_Reachability.m; sourceTree = "<group>"; };
5255C2B71F5D25F400A8FC5F /* YHEventReport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YHEventReport.h; sourceTree = "<group>"; };
5255C2B81F5D25F400A8FC5F /* YHEventReport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YHEventReport.m; sourceTree = "<group>"; };
5255C2C41F5D402900A8FC5F /* YHEventReportMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YHEventReportMacros.h; sourceTree = "<group>"; };
52878BF91F5D44F7000A1597 /* YH_EventCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_EventCollector.h; sourceTree = "<group>"; };
52878BFA1F5D44F7000A1597 /* YH_EventCollector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_EventCollector.m; sourceTree = "<group>"; };
... ... @@ -275,6 +278,24 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
2906173C1FEB8E8B00BD569F /* YH_Core */ = {
isa = PBXGroup;
children = (
2906173D1FEB8E8B00BD569F /* YHEventReport.h */,
2906173E1FEB8E8B00BD569F /* YHEventReport.m */,
);
path = YH_Core;
sourceTree = "<group>";
};
290617401FEB94FB00BD569F /* YH_LagHunter */ = {
isa = PBXGroup;
children = (
290617411FEB951300BD569F /* YH_LagHunter.h */,
290617421FEB951300BD569F /* YH_LagHunter.m */,
);
path = YH_LagHunter;
sourceTree = "<group>";
};
29CDB4A81F6FA57900AAD350 /* PowerfulBannerView */ = {
isa = PBXGroup;
children = (
... ... @@ -300,8 +321,8 @@
5255C2A31F5D25F400A8FC5F /* YHEventReport */ = {
isa = PBXGroup;
children = (
5255C2B71F5D25F400A8FC5F /* YHEventReport.h */,
5255C2B81F5D25F400A8FC5F /* YHEventReport.m */,
290617401FEB94FB00BD569F /* YH_LagHunter */,
2906173C1FEB8E8B00BD569F /* YH_Core */,
5255C2A41F5D25F400A8FC5F /* YH_AOP */,
5223D9CE1F8F50FF00EB698F /* YH_CrashReporter */,
5255C2C21F5D265000A8FC5F /* YH_EventCollector */,
... ... @@ -744,10 +765,12 @@
52D204EB1F61331900CB7F1A /* UIAlertView+AutoTrack.m in Sources */,
B1B6C3A21F74AD3100627DF3 /* UITableView+YHExposure.m in Sources */,
B1D7749F1F62A37E00BA89C3 /* Aspects.m in Sources */,
290617431FEB951300BD569F /* YH_LagHunter.m in Sources */,
B1C419011F616187005E0729 /* JTSHardwareInfo.m in Sources */,
B1B6C3A31F74AD3100627DF3 /* UIView+YHExposure.m in Sources */,
5255C2BD1F5D25F400A8FC5F /* YH_EventCacheManager.m in Sources */,
5255C2B91F5D25F400A8FC5F /* UICollectionView+AutoTrack.m in Sources */,
2906173F1FEB8E8B00BD569F /* YHEventReport.m in Sources */,
29D3B97C1F73A81E00B07F47 /* YH_EventCollector+UIActionSheet.m in Sources */,
529A004E1F564E8500A83F63 /* AppDelegate.m in Sources */,
B1B6C3A11F74AD3100627DF3 /* UIScrollView+YHExposure.m in Sources */,
... ... @@ -765,7 +788,6 @@
B1D774A21F62A37E00BA89C3 /* SDImageCache.m in Sources */,
B1C418CD1F5FFBAA005E0729 /* YH_PerformanceAppInfo.m in Sources */,
5255C2BC1F5D25F400A8FC5F /* YH_EventCacheFile.m in Sources */,
5255C2C11F5D25F400A8FC5F /* YHEventReport.m in Sources */,
529A004B1F564E8500A83F63 /* main.m in Sources */,
B1C419021F616187005E0729 /* OpenUDID.m in Sources */,
B1D774A51F62A37E00BA89C3 /* SDWebImageDownloader.m in Sources */,
... ...
... ... @@ -18,7 +18,7 @@
- (void)timeEventStartWithViewController:(UIViewController *)viewController;
- (void)timeEventEndWithViewController:(UIViewController *)viewController;
- (void)timeEventStartWithWebView:(UIWebView *)webView;
//- (void)timeEventStartWithWebView:(UIWebView *)webView;
- (void)timeEventEndWithWebView:(UIWebView *)webView status:(YHEventLoadStatus)status;
- (void)timeEventStartWithWebImageDownloadURL:(NSString *)imageURL;
... ... @@ -39,14 +39,6 @@
- (void)timeEventStartWithView:(id)targetView collectionView:(UICollectionView*)collectionView indexPath:(NSIndexPath*)indexPath;
- (void)timeEventEndWithView:(id)targetView collectionView:(UICollectionView*)collectionView indexPath:(NSIndexPath*)indexPath;
+ (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
... ...
//
// YH_LagHunter.h
// YHEventReport
//
// Created by 于良 on 2017/12/21.
// Copyright © 2017年 YOHO. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface YH_LagHunter : NSObject
+ (instancetype)sharedInstance;
- (void)startMonitor;
- (void)stopMonitor;
@end
... ...
//
// YH_LagHunter.m
// YHEventReport
//
// Created by 于良 on 2017/12/21.
// Copyright © 2017年 YOHO. All rights reserved.
//
#import "YH_LagHunter.h"
@interface YH_LagHunter()
@property (assign, nonatomic) NSInteger timeoutCount;
@property (assign, nonatomic) CFRunLoopObserverRef observer;
@property (strong, nonatomic) dispatch_semaphore_t semaphore;
@property (assign, nonatomic) CFRunLoopActivity activity;
@end
@implementation YH_LagHunter
+ (instancetype)sharedInstance
{
static id instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
static void runLoopObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info)
{
YH_LagHunter *moniotr = (__bridge YH_LagHunter*)info;
moniotr.activity = activity;
dispatch_semaphore_t semaphore = moniotr.semaphore;
dispatch_semaphore_signal(semaphore);
}
- (void)stopMonitor
{
if (!_observer)
return;
CFRunLoopRemoveObserver(CFRunLoopGetMain(), _observer, kCFRunLoopCommonModes);
CFRelease(_observer);
_observer = NULL;
}
- (void)startMonitor
{
if (_observer)
return;
// 信号,Dispatch Semaphore保证同步
_semaphore = dispatch_semaphore_create(0);
// 注册RunLoop状态观察
CFRunLoopObserverContext context = {0,(__bridge void*)self,NULL,NULL};
_observer = CFRunLoopObserverCreate(kCFAllocatorDefault,
kCFRunLoopAllActivities,
YES,
0,
&runLoopObserverCallBack,
&context);
//将观察者添加到主线程runloop的common模式下的观察中
CFRunLoopAddObserver(CFRunLoopGetMain(), _observer, kCFRunLoopCommonModes);
// 在子线程监控时长 开启一个持续的loop用来进行监控
dispatch_async(dispatch_get_global_queue(0, 0), ^{
while (YES)
{
//假定连续5次超时50ms认为卡顿(当然也包含了单次超时250ms)
long st = dispatch_semaphore_wait(_semaphore, dispatch_time(DISPATCH_TIME_NOW, 50*NSEC_PER_MSEC));
if (st != 0)
{
if (!_observer)
{
_timeoutCount = 0;
_semaphore = 0;
_activity = 0;
return;
}
//两个runloop的状态,BeforeSources和AfterWaiting这两个状态区间时间能够检测到是否卡顿
if (_activity==kCFRunLoopBeforeSources || _activity==kCFRunLoopAfterWaiting)
{
if (++_timeoutCount < 5)
continue;
// PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:PLCrashReporterSignalHandlerTypeBSD
// symbolicationStrategy:PLCrashReporterSymbolicationStrategyAll];
// PLCrashReporter *crashReporter = [[PLCrashReporter alloc] initWithConfiguration:config];
// NSData *data = [crashReporter generateLiveReport];
// PLCrashReport *reporter = [[PLCrashReport alloc] initWithData:data error:NULL];
// NSString *report = [PLCrashReportTextFormatter stringValueForCrashReport:reporter
// withTextFormat:PLCrashReportTextFormatiOS];
// //上传服务器
// NSLog(@"此处发生卡顿:---%@", report);
NSLog(@"此处发生卡顿:-----------");
}//end activity
}// end semaphore wait
_timeoutCount = 0;
}// end while
});
}
@end
... ...