Skip to content

Commit 4ed50a9

Browse files
authored
Not suspend threads for on-demand fatal thread recording (#14391)
1 parent df8d2f7 commit 4ed50a9

10 files changed

+48
-14
lines changed

Crashlytics/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [fixed] Made on-demand fatal recording thread suspension configurable through setting to imrpove performance and avoid audio glitch on Unity. Change is for framework only.
3+
14
# 11.7.0
25
- [fixed] Updated `upload-symbols` to version 3.20, wait for `debug.dylib` DWARF content getting generated when build with `--build-phase` option. Added `debug.dylib` DWARF content to run script input file list for user who enabled user script sandboxing (#14054).
36
- [fixed] Updated all memory allocation from `malloc()` to `calloc()` (#14209).

Crashlytics/Crashlytics/Handlers/FIRCLSException.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ void FIRCLSExceptionRaiseTestCppException(void) __attribute((noreturn));
6363
void FIRCLSExceptionRecordModel(FIRExceptionModel* exceptionModel, NSString* rolloutsInfoJSON);
6464
NSString* FIRCLSExceptionRecordOnDemandModel(FIRExceptionModel* exceptionModel,
6565
int previousRecordedOnDemandExceptions,
66-
int previousDroppedOnDemandExceptions);
66+
int previousDroppedOnDemandExceptions,
67+
BOOL shouldSuspendThread);
6768
void FIRCLSExceptionRecordNSException(NSException* exception);
6869
void FIRCLSExceptionRecord(FIRCLSExceptionType type,
6970
const char* name,
@@ -76,7 +77,8 @@ NSString* FIRCLSExceptionRecordOnDemand(FIRCLSExceptionType type,
7677
NSArray<FIRStackFrame*>* frames,
7778
BOOL fatal,
7879
int previousRecordedOnDemandExceptions,
79-
int previousDroppedOnDemandExceptions);
80+
int previousDroppedOnDemandExceptions,
81+
BOOL shouldSuspendThread);
8082
#endif
8183

8284
__END_DECLS

Crashlytics/Crashlytics/Handlers/FIRCLSException.mm

+8-5
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ void FIRCLSExceptionRecordModel(FIRExceptionModel *exceptionModel, NSString *rol
9191

9292
NSString *FIRCLSExceptionRecordOnDemandModel(FIRExceptionModel *exceptionModel,
9393
int previousRecordedOnDemandExceptions,
94-
int previousDroppedOnDemandExceptions) {
94+
int previousDroppedOnDemandExceptions,
95+
BOOL shouldSuspendThread) {
9596
const char *name = [[exceptionModel.name copy] UTF8String];
9697
const char *reason = [[exceptionModel.reason copy] UTF8String] ?: "";
9798

9899
return FIRCLSExceptionRecordOnDemand(FIRCLSExceptionTypeCustom, name, reason,
99100
[exceptionModel.stackTrace copy], exceptionModel.isFatal,
100101
previousRecordedOnDemandExceptions,
101-
previousDroppedOnDemandExceptions);
102+
previousDroppedOnDemandExceptions, shouldSuspendThread);
102103
}
103104

104105
void FIRCLSExceptionRecordNSException(NSException *exception) {
@@ -235,7 +236,7 @@ void FIRCLSExceptionRecord(FIRCLSExceptionType type,
235236
FIRCLSExceptionWrite(&file, type, name, reason, frames, nil);
236237

237238
// We only want to do this work if we have the expectation that we'll actually crash
238-
FIRCLSHandler(&file, mach_thread_self(), NULL);
239+
FIRCLSHandler(&file, mach_thread_self(), NULL, YES);
239240

240241
FIRCLSFileClose(&file);
241242
});
@@ -258,7 +259,8 @@ void FIRCLSExceptionRecord(FIRCLSExceptionType type,
258259
NSArray<FIRStackFrame *> *frames,
259260
BOOL fatal,
260261
int previousRecordedOnDemandExceptions,
261-
int previousDroppedOnDemandExceptions) {
262+
int previousDroppedOnDemandExceptions,
263+
BOOL shouldSuspendThread) {
262264
if (!FIRCLSContextIsInitialized()) {
263265
return nil;
264266
}
@@ -353,7 +355,8 @@ void FIRCLSExceptionRecord(FIRCLSExceptionType type,
353355
return nil;
354356
}
355357
FIRCLSExceptionWrite(&file, type, name, reason, frames, nil);
356-
FIRCLSHandler(&file, mach_thread_self(), NULL);
358+
359+
FIRCLSHandler(&file, mach_thread_self(), NULL, shouldSuspendThread);
357360
FIRCLSFileClose(&file);
358361

359362
// Return the path to the new report.

Crashlytics/Crashlytics/Handlers/FIRCLSHandler.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
__BEGIN_DECLS
2222

23-
void FIRCLSHandler(FIRCLSFile* file, thread_t crashedThread, void* uapVoid);
23+
void FIRCLSHandler(FIRCLSFile* file,
24+
thread_t crashedThread,
25+
void* uapVoid,
26+
bool shouldSuspendThread);
2427

2528
__END_DECLS

Crashlytics/Crashlytics/Handlers/FIRCLSHandler.m

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222

2323
#import "Crashlytics/Crashlytics/Controllers/FIRCLSReportManager_Private.h"
2424

25-
void FIRCLSHandler(FIRCLSFile* file, thread_t crashedThread, void* uapVoid) {
25+
void FIRCLSHandler(FIRCLSFile* file,
26+
thread_t crashedThread,
27+
void* uapVoid,
28+
bool shouldSuspendThread) {
2629
FIRCLSProcess process;
2730

2831
FIRCLSProcessInit(&process, crashedThread, uapVoid);
2932

30-
FIRCLSProcessSuspendAllOtherThreads(&process);
33+
if (shouldSuspendThread) {
34+
FIRCLSProcessSuspendAllOtherThreads(&process);
35+
}
3136

3237
FIRCLSProcessRecordAllThreads(&process, file);
3338

@@ -45,5 +50,7 @@ void FIRCLSHandler(FIRCLSFile* file, thread_t crashedThread, void* uapVoid) {
4550
// Store a crash file marker to indicate that a crash has occurred
4651
FIRCLSCreateCrashedMarkerFile();
4752

48-
FIRCLSProcessResumeAllOtherThreads(&process);
53+
if (shouldSuspendThread) {
54+
FIRCLSProcessResumeAllOtherThreads(&process);
55+
}
4956
}

Crashlytics/Crashlytics/Handlers/FIRCLSMachException.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static bool FIRCLSMachExceptionRecord(FIRCLSMachExceptionReadContext* context,
520520

521521
FIRCLSFileWriteSectionEnd(&file);
522522

523-
FIRCLSHandler(&file, message->thread.name, NULL);
523+
FIRCLSHandler(&file, message->thread.name, NULL, true);
524524

525525
FIRCLSFileClose(&file);
526526

Crashlytics/Crashlytics/Handlers/FIRCLSSignal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static void FIRCLSSignalRecordSignal(int savedErrno, siginfo_t *info, void *uapV
286286

287287
FIRCLSFileWriteSectionEnd(&file);
288288

289-
FIRCLSHandler(&file, mach_thread_self(), uapVoid);
289+
FIRCLSHandler(&file, mach_thread_self(), uapVoid, true);
290290

291291
FIRCLSFileClose(&file);
292292
}

Crashlytics/Crashlytics/Models/FIRCLSOnDemandModel.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ - (void)implementOnDemandUploadDelay:(int)delay {
178178
}
179179

180180
- (NSString *)recordOnDemandExceptionWithModel:(FIRExceptionModel *)exceptionModel {
181+
BOOL shouldSuspendThread = self.settings.onDemandThreadSuspensionEnabled;
181182
return FIRCLSExceptionRecordOnDemandModel(exceptionModel, self.recordedOnDemandExceptionCount,
182-
self.droppedOnDemandExceptionCount);
183+
self.droppedOnDemandExceptionCount,
184+
shouldSuspendThread);
183185
}
184186

185187
- (int)droppedOnDemandExceptionCount {

Crashlytics/Crashlytics/Models/FIRCLSSettings.h

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ NS_ASSUME_NONNULL_BEGIN
121121
*/
122122
@property(nonatomic, readonly) uint32_t onDemandBackoffStepDuration;
123123

124+
/**
125+
* When this is true, Crashlytics will suspend all threads to do on-demand fatal recording.
126+
*/
127+
@property(nonatomic, readonly) BOOL onDemandThreadSuspensionEnabled;
128+
124129
@end
125130

126131
NS_ASSUME_NONNULL_END

Crashlytics/Crashlytics/Models/FIRCLSSettings.m

+9
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,13 @@ - (uint32_t)onDemandBackoffStepDuration {
357357
return 6; // step duration for exponential backoff
358358
}
359359

360+
- (BOOL)onDemandThreadSuspensionEnabled {
361+
NSNumber *value = self.settingsDictionary[@"on_demand_thread_recording_suspension_enabled"];
362+
363+
if (value != nil) {
364+
return value.boolValue;
365+
}
366+
367+
return YES;
368+
}
360369
@end

0 commit comments

Comments
 (0)