Skip to content

Commit

Permalink
[Crashlytics] Remove mach_absolute_time usages (#12664)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Cooke <[email protected]>
  • Loading branch information
paulb777 and ncooke3 authored Apr 1, 2024
1 parent 88d2b5c commit 385bfdc
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 104 deletions.
1 change: 1 addition & 0 deletions Crashlytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased
- [fixed] Fix `'FirebaseCrashlytics/FirebaseCrashlytics-Swift.h' file not found`
errors (#12611).
- [changed] Remove usages of `mach_absolute_time` to reduce required reason impact.

# 10.23.0
- [added] Updated upload-symbols to 13.7 with VisionPro build phase support. (#12306)
Expand Down
1 change: 0 additions & 1 deletion Crashlytics/Crashlytics/Components/FIRCLSProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
#include "Crashlytics/Crashlytics/Helpers/FIRCLSFeatures.h"
#include "Crashlytics/Crashlytics/Components/FIRCLSGlobals.h"
#include "Crashlytics/Crashlytics/Helpers/FIRCLSProfiling.h"
#include "Crashlytics/Crashlytics/Helpers/FIRCLSThreadState.h"
#include "Crashlytics/Crashlytics/Unwind/FIRCLSUnwind.h"
#include "Crashlytics/Crashlytics/Helpers/FIRCLSUtility.h"
Expand Down
4 changes: 1 addition & 3 deletions Crashlytics/Crashlytics/Controllers/FIRCLSReportManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#import "Crashlytics/Crashlytics/Public/FirebaseCrashlytics/FIRCrashlytics.h"

#import "Crashlytics/Crashlytics/Helpers/FIRCLSProfiling.h"

@class FBLPromise<T>;
@class FIRCLSExistingReportManager;
@class FIRCLSAnalyticsManager;
Expand All @@ -35,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

- (FBLPromise<NSNumber *> *)startWithProfilingMark:(FIRCLSProfileMark)mark;
- (FBLPromise<NSNumber *> *)startWithProfiling;

- (FBLPromise<FIRCrashlyticsReport *> *)checkForUnsentReports;
- (FBLPromise *)sendUnsentReports;
Expand Down
23 changes: 10 additions & 13 deletions Crashlytics/Crashlytics/Controllers/FIRCLSReportManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ - (FBLPromise *)deleteUnsentReports {
return _unsentReportsHandled;
}

- (FBLPromise<NSNumber *> *)startWithProfilingMark:(FIRCLSProfileMark)mark {
- (FBLPromise<NSNumber *> *)startWithProfiling {
NSString *executionIdentifier = self.executionIDModel.executionID;

// This needs to be called before the new report is created for
Expand All @@ -294,7 +294,7 @@ - (FBLPromise *)deleteUnsentReports {
FIRCLSErrorLog(@"Unable to setup a new report");
}

if (![self startCrashReporterWithProfilingMark:mark report:report]) {
if (![self startCrashReporterWithProfilingReport:report]) {
FIRCLSErrorLog(@"Unable to start crash reporter");
report = nil;
}
Expand Down Expand Up @@ -361,11 +361,9 @@ - (FBLPromise *)deleteUnsentReports {
}

if (report != nil) {
// capture the start-up time here, but record it asynchronously
double endMark = FIRCLSProfileEnd(mark);

// empty for disabled start-up time
dispatch_async(FIRCLSGetLoggingQueue(), ^{
FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSStartTimeKey, [@(endMark) description]);
FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSStartTimeKey, @"");
});
}

Expand Down Expand Up @@ -414,8 +412,7 @@ - (void)beginReportUploadsWithToken:(FIRCLSDataCollectionToken *)token
}
}

- (BOOL)startCrashReporterWithProfilingMark:(FIRCLSProfileMark)mark
report:(FIRCLSInternalReport *)report {
- (BOOL)startCrashReporterWithProfilingReport:(FIRCLSInternalReport *)report {
if (!report) {
return NO;
}
Expand All @@ -430,12 +427,12 @@ - (BOOL)startCrashReporterWithProfilingMark:(FIRCLSProfileMark)mark

[self.analyticsManager registerAnalyticsListener];

[self crashReportingSetupCompleted:mark];
[self crashReportingSetupCompleted];

return YES;
}

- (void)crashReportingSetupCompleted:(FIRCLSProfileMark)mark {
- (void)crashReportingSetupCompleted {
// check our handlers
FIRCLSDispatchAfter(2.0, dispatch_get_main_queue(), ^{
FIRCLSExceptionCheckHandlers((__bridge void *)(self));
Expand All @@ -447,12 +444,12 @@ - (void)crashReportingSetupCompleted:(FIRCLSProfileMark)mark {
#endif
});

// remove the launch failure marker and record the startup time
// remove the launch failure marker and records and empty string since
// we're avoiding mach_absolute_time calls.
dispatch_async(dispatch_get_main_queue(), ^{
[self.launchMarker removeLaunchFailureMarker];
dispatch_async(FIRCLSGetLoggingQueue(), ^{
FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSFirstRunloopTurnTimeKey,
[@(FIRCLSProfileEnd(mark)) description]);
FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSFirstRunloopTurnTimeKey, @"");
});
});
}
Expand Down
5 changes: 1 addition & 4 deletions Crashlytics/Crashlytics/FIRCrashlytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#import "Crashlytics/Crashlytics/FIRCLSUserDefaults/FIRCLSUserDefaults.h"
#include "Crashlytics/Crashlytics/Handlers/FIRCLSException.h"
#import "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
#include "Crashlytics/Crashlytics/Helpers/FIRCLSProfiling.h"
#include "Crashlytics/Crashlytics/Helpers/FIRCLSUtility.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSExecutionIdentifierModel.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
Expand Down Expand Up @@ -133,8 +132,6 @@ - (instancetype)initWithApp:(FIRApp *)app
return nil;
}

FIRCLSProfileMark mark = FIRCLSProfilingStart();

NSLog(@"[Firebase/Crashlytics] Version %@", FIRCLSSDKVersion());

FIRCLSDeveloperLog("Crashlytics", @"Running on %@, %@ (%@)", FIRCLSHostModelInfo(),
Expand Down Expand Up @@ -200,7 +197,7 @@ - (instancetype)initWithApp:(FIRApp *)app
});
}

[[[_reportManager startWithProfilingMark:mark] then:^id _Nullable(NSNumber *_Nullable value) {
[[[_reportManager startWithProfiling] then:^id _Nullable(NSNumber *_Nullable value) {
if (![value boolValue]) {
FIRCLSErrorLog(@"Crash reporting could not be initialized");
}
Expand Down
47 changes: 0 additions & 47 deletions Crashlytics/Crashlytics/Helpers/FIRCLSProfiling.c

This file was deleted.

29 changes: 0 additions & 29 deletions Crashlytics/Crashlytics/Helpers/FIRCLSProfiling.h

This file was deleted.

4 changes: 2 additions & 2 deletions Crashlytics/UnitTests/FIRCLSReportManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ - (NSArray *)uploadReportArray {

#pragma mark - File/Directory Handling
- (void)testCreatesNewReportOnStart {
FBLPromise<NSNumber *> *promise = [self->_reportManager startWithProfilingMark:0];
FBLPromise<NSNumber *> *promise = [self->_reportManager startWithProfiling];

XCTestExpectation *expectation =
[[XCTestExpectation alloc] initWithDescription:@"waiting on promise"];
Expand Down Expand Up @@ -244,7 +244,7 @@ - (void)startReportManager {

- (FBLPromise<NSNumber *> *)startReportManagerWithDataCollectionEnabled:(BOOL)enabled {
[self.dataArbiter setCrashlyticsCollectionEnabled:enabled];
return [self.reportManager startWithProfilingMark:0];
return [self.reportManager startWithProfiling];
}

- (void)processReports:(BOOL)send andExpectReports:(BOOL)reportsExpected {
Expand Down
6 changes: 3 additions & 3 deletions Crashlytics/UnitTests/FIRCLSReportUploaderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ - (void)testUrgentUploadPackagedReportWithPath {
[self runUploadPackagedReportWithUrgency:YES];
}

- (void)testUrgentWaitUntillUpload {
- (void)testUrgentWaitUntilUpload {
self.mockDataTransport.async = YES;

[self runUploadPackagedReportWithUrgency:YES];

XCTAssertNotNil(self.mockDataTransport.sendDataEvent_event);
}

- (void)testUrgentWaitUntillUploadWithError {
- (void)testUrgentWaitUntilUploadWithError {
self.mockDataTransport.async = YES;
self.mockDataTransport.sendDataEvent_error = [[NSError alloc] initWithDomain:@"domain"
code:1
Expand All @@ -234,7 +234,7 @@ - (void)testUrgentWaitUntillUploadWithError {
XCTAssertNotNil(self.mockDataTransport.sendDataEvent_event);
}

- (void)testUrgentWaitUntillUploadWithWritingError {
- (void)testUrgentWaitUntilUploadWithWritingError {
self.mockDataTransport.async = YES;
self.mockDataTransport.sendDataEvent_wasWritten = NO;

Expand Down
3 changes: 1 addition & 2 deletions Crashlytics/UnitTests/Mocks/FIRCLSMockReportManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

@implementation FIRCLSMockReportManager

- (BOOL)startCrashReporterWithProfilingMark:(FIRCLSProfileMark)mark
report:(FIRCLSInternalReport *)report {
- (BOOL)startCrashReporterWithProfilingReport:(FIRCLSInternalReport *)report {
NSLog(@"Crash Reporting system disabled for testing");

return YES;
Expand Down

0 comments on commit 385bfdc

Please sign in to comment.