Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make suspend threads for on-demand fatal thread recording configurable #14391

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Crashlytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [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.

# 11.7.0
- [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).
- [fixed] Updated all memory allocation from `malloc()` to `calloc()` (#14209).
Expand Down
6 changes: 4 additions & 2 deletions Crashlytics/Crashlytics/Handlers/FIRCLSException.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ void FIRCLSExceptionRaiseTestCppException(void) __attribute((noreturn));
void FIRCLSExceptionRecordModel(FIRExceptionModel* exceptionModel, NSString* rolloutsInfoJSON);
NSString* FIRCLSExceptionRecordOnDemandModel(FIRExceptionModel* exceptionModel,
int previousRecordedOnDemandExceptions,
int previousDroppedOnDemandExceptions);
int previousDroppedOnDemandExceptions,
BOOL shouldSuspendThread);
void FIRCLSExceptionRecordNSException(NSException* exception);
void FIRCLSExceptionRecord(FIRCLSExceptionType type,
const char* name,
Expand All @@ -76,7 +77,8 @@ NSString* FIRCLSExceptionRecordOnDemand(FIRCLSExceptionType type,
NSArray<FIRStackFrame*>* frames,
BOOL fatal,
int previousRecordedOnDemandExceptions,
int previousDroppedOnDemandExceptions);
int previousDroppedOnDemandExceptions,
BOOL shouldSuspendThread);
#endif

__END_DECLS
13 changes: 8 additions & 5 deletions Crashlytics/Crashlytics/Handlers/FIRCLSException.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ void FIRCLSExceptionRecordModel(FIRExceptionModel *exceptionModel, NSString *rol

NSString *FIRCLSExceptionRecordOnDemandModel(FIRExceptionModel *exceptionModel,
int previousRecordedOnDemandExceptions,
int previousDroppedOnDemandExceptions) {
int previousDroppedOnDemandExceptions,
BOOL shouldSuspendThread) {
const char *name = [[exceptionModel.name copy] UTF8String];
const char *reason = [[exceptionModel.reason copy] UTF8String] ?: "";

return FIRCLSExceptionRecordOnDemand(FIRCLSExceptionTypeCustom, name, reason,
[exceptionModel.stackTrace copy], exceptionModel.isFatal,
previousRecordedOnDemandExceptions,
previousDroppedOnDemandExceptions);
previousDroppedOnDemandExceptions, shouldSuspendThread);
}

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

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

FIRCLSFileClose(&file);
});
Expand All @@ -258,7 +259,8 @@ void FIRCLSExceptionRecord(FIRCLSExceptionType type,
NSArray<FIRStackFrame *> *frames,
BOOL fatal,
int previousRecordedOnDemandExceptions,
int previousDroppedOnDemandExceptions) {
int previousDroppedOnDemandExceptions,
BOOL shouldSuspendThread) {
if (!FIRCLSContextIsInitialized()) {
return nil;
}
Expand Down Expand Up @@ -353,7 +355,8 @@ void FIRCLSExceptionRecord(FIRCLSExceptionType type,
return nil;
}
FIRCLSExceptionWrite(&file, type, name, reason, frames, nil);
FIRCLSHandler(&file, mach_thread_self(), NULL);

FIRCLSHandler(&file, mach_thread_self(), NULL, shouldSuspendThread);
FIRCLSFileClose(&file);

// Return the path to the new report.
Expand Down
5 changes: 4 additions & 1 deletion Crashlytics/Crashlytics/Handlers/FIRCLSHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

__BEGIN_DECLS

void FIRCLSHandler(FIRCLSFile* file, thread_t crashedThread, void* uapVoid);
void FIRCLSHandler(FIRCLSFile* file,
thread_t crashedThread,
void* uapVoid,
bool shouldSuspendThread);

__END_DECLS
13 changes: 10 additions & 3 deletions Crashlytics/Crashlytics/Handlers/FIRCLSHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@

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

void FIRCLSHandler(FIRCLSFile* file, thread_t crashedThread, void* uapVoid) {
void FIRCLSHandler(FIRCLSFile* file,
thread_t crashedThread,
void* uapVoid,
bool shouldSuspendThread) {
FIRCLSProcess process;

FIRCLSProcessInit(&process, crashedThread, uapVoid);

FIRCLSProcessSuspendAllOtherThreads(&process);
if (shouldSuspendThread) {
FIRCLSProcessSuspendAllOtherThreads(&process);
}

FIRCLSProcessRecordAllThreads(&process, file);

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

FIRCLSProcessResumeAllOtherThreads(&process);
if (shouldSuspendThread) {
FIRCLSProcessResumeAllOtherThreads(&process);
}
}
2 changes: 1 addition & 1 deletion Crashlytics/Crashlytics/Handlers/FIRCLSMachException.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static bool FIRCLSMachExceptionRecord(FIRCLSMachExceptionReadContext* context,

FIRCLSFileWriteSectionEnd(&file);

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

FIRCLSFileClose(&file);

Expand Down
2 changes: 1 addition & 1 deletion Crashlytics/Crashlytics/Handlers/FIRCLSSignal.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static void FIRCLSSignalRecordSignal(int savedErrno, siginfo_t *info, void *uapV

FIRCLSFileWriteSectionEnd(&file);

FIRCLSHandler(&file, mach_thread_self(), uapVoid);
FIRCLSHandler(&file, mach_thread_self(), uapVoid, true);

FIRCLSFileClose(&file);
}
Expand Down
4 changes: 3 additions & 1 deletion Crashlytics/Crashlytics/Models/FIRCLSOnDemandModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ - (void)implementOnDemandUploadDelay:(int)delay {
}

- (NSString *)recordOnDemandExceptionWithModel:(FIRExceptionModel *)exceptionModel {
BOOL shouldSuspendThread = self.settings.onDemandThreadSuspensionEnabled;
return FIRCLSExceptionRecordOnDemandModel(exceptionModel, self.recordedOnDemandExceptionCount,
self.droppedOnDemandExceptionCount);
self.droppedOnDemandExceptionCount,
shouldSuspendThread);
}

- (int)droppedOnDemandExceptionCount {
Expand Down
5 changes: 5 additions & 0 deletions Crashlytics/Crashlytics/Models/FIRCLSSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property(nonatomic, readonly) uint32_t onDemandBackoffStepDuration;

/**
* When this is true, Crashlytics will suspend all threads to do on-demand fatal recording.
*/
@property(nonatomic, readonly) BOOL onDemandThreadSuspensionEnabled;

@end

NS_ASSUME_NONNULL_END
9 changes: 9 additions & 0 deletions Crashlytics/Crashlytics/Models/FIRCLSSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,13 @@ - (uint32_t)onDemandBackoffStepDuration {
return 6; // step duration for exponential backoff
}

- (BOOL)onDemandThreadSuspensionEnabled {
NSNumber *value = self.settingsDictionary[@"on_demand_thread_recording_suspension_enabled"];

if (value != nil) {
return value.boolValue;
}

return YES;
}
@end
Loading