fix: capture before symbolication and close resident app during upgrades
这个提交包含在:
1 父节点
e26a7c68e4
当前提交
d018769558
7 个文件已更改
+130
-7
没有与搜索条件相匹配的文件
@@ -101,6 +101,13 @@ static NSString *sysctlString(const char *key) {
|
||||
NSUserDefaults *prefs=preferences();[prefs registerDefaults:@{@"betaDiagnosticsEnabled":@YES}];gEnabled.store([prefs boolForKey:@"betaDiagnosticsEnabled"]);
|
||||
folder=[[[NSFileManager.defaultManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask].firstObject URLByAppendingPathComponent:@"com.dayu.color/Beta" isDirectory:YES]retain];
|
||||
[NSFileManager.defaultManager createDirectoryAtURL:folder withIntermediateDirectories:YES attributes:@{NSFilePosixPermissions:@0700} error:nil];
|
||||
// A process can exit while the independent sampler is writing. Only remove our stale samples.
|
||||
if([source isEqual:@"app"])for(NSURL *file in [NSFileManager.defaultManager contentsOfDirectoryAtURL:folder includingPropertiesForKeys:@[NSURLContentModificationDateKey] options:0 error:nil]) {
|
||||
NSString *name=file.lastPathComponent;
|
||||
if(![name hasPrefix:@"sample-"]||![[[NSUUID alloc]initWithUUIDString:[name substringFromIndex:7]]autorelease])continue;
|
||||
NSDate *date=nil;[file getResourceValue:&date forKey:NSURLContentModificationDateKey error:nil];
|
||||
if(date&&date.timeIntervalSinceNow< -300)[NSFileManager.defaultManager removeItemAtURL:file error:nil];
|
||||
}
|
||||
// O_EXCL gives the APP and XPC one random installation ID without hardware UUIDs.
|
||||
NSURL *identity=[folder URLByAppendingPathComponent:@"installation.txt"];
|
||||
NSString *newID=NSUUID.UUID.UUIDString.lowercaseString;
|
||||
@@ -210,11 +217,12 @@ static NSString *sysctlString(const char *key) {
|
||||
dispatch_async(evidenceQueue,^{@autoreleasepool{
|
||||
NSURL *output=[self->folder URLByAppendingPathComponent:[@"sample-" stringByAppendingString:NSUUID.UUID.UUIDString]];
|
||||
NSTask *task=[[[NSTask alloc]init]autorelease];task.executableURL=[NSURL fileURLWithPath:@"/usr/bin/sample"];
|
||||
task.arguments=@[[@(getpid())stringValue],@"1",@"10",@"-mayDie",@"-file",output.path];
|
||||
// Sample first, then symbolize; -mayDie preloads symbols and can miss a short hang.
|
||||
task.arguments=@[[@(getpid())stringValue],@"1",@"10",@"-file",output.path];
|
||||
task.standardOutput=[NSFileHandle fileHandleWithNullDevice];task.standardError=[NSFileHandle fileHandleWithNullDevice];
|
||||
NSString *result=@"unavailable",*frames=@"";NSError *error=nil;
|
||||
if(gEnabled.load()&&[task launchAndReturnError:&error]) {
|
||||
double deadline=NSProcessInfo.processInfo.systemUptime+8;
|
||||
double deadline=NSProcessInfo.processInfo.systemUptime+30;
|
||||
while(task.running&&gEnabled.load()&&NSProcessInfo.processInfo.systemUptime<deadline)[NSThread sleepForTimeInterval:.05];
|
||||
if(task.running){[task terminate];[NSThread sleepForTimeInterval:.1];if(task.running)kill(task.processIdentifier,SIGKILL);result=@"timeout_or_disabled";}
|
||||
else if(task.terminationStatus==0){NSNumber *size=nil;[output getResourceValue:&size forKey:NSURLFileSizeKey error:nil];if(size.unsignedLongLongValue<=4*1024*1024)frames=DYBetaSampleFrames([NSString stringWithContentsOfURL:output encoding:NSUTF8StringEncoding error:nil]);result=frames.length?@"captured":@"no_frames";}
|
||||
|
||||
在新工单中引用
屏蔽一个用户