Skip to content

Commit

Permalink
ref: Add ANRTracker protocol
Browse files Browse the repository at this point in the history
Add a protocol for the ANRTracker in preparation for switching between
V1 and V2. Furthermore, remove the ANRTrackerV2 integration as it would
contain mostly duplicated code from ANTTrackerV1.
  • Loading branch information
philipphofmann committed Sep 23, 2024
1 parent f0be869 commit 2ed6c6b
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 491 deletions.
40 changes: 16 additions & 24 deletions Sentry.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "SentryANRTracker.h"
#import "SentryANRTrackerV1.h"
#import "SentryCrashWrapper.h"
#import "SentryDependencyContainer.h"
#import "SentryDispatchQueueWrapper.h"
Expand All @@ -16,7 +16,7 @@ typedef NS_ENUM(NSInteger, SentryANRTrackerState) {
kSentryANRTrackerStopping
};

@interface SentryANRTracker ()
@interface SentryANRTrackerV1 ()

@property (nonatomic, strong) SentryCrashWrapper *crashWrapper;
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueueWrapper;
Expand All @@ -26,7 +26,7 @@ @interface SentryANRTracker ()

@end

@implementation SentryANRTracker {
@implementation SentryANRTrackerV1 {
NSObject *threadLock;
SentryANRTrackerState state;
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Sentry/SentryANRTrackingIntegration.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#import "SentryANRTrackingIntegration.h"
#import "SentryANRTracker.h"
#import "SentryClient+Private.h"
#import "SentryCrashMachineContext.h"
#import "SentryCrashWrapper.h"
Expand All @@ -12,6 +11,7 @@
#import "SentryMechanism.h"
#import "SentrySDK+Private.h"
#import "SentryStacktrace.h"
#import "SentrySwift.h"
#import "SentryThread.h"
#import "SentryThreadInspector.h"
#import "SentryThreadWrapper.h"
Expand All @@ -26,7 +26,7 @@

@interface SentryANRTrackingIntegration ()

@property (nonatomic, strong) SentryANRTracker *tracker;
@property (nonatomic, strong) id<SentryANRTracker> tracker;
@property (nonatomic, strong) SentryOptions *options;
@property (atomic, assign) BOOL reportAppHangs;

Expand All @@ -41,7 +41,7 @@ - (BOOL)installWithOptions:(SentryOptions *)options
}

self.tracker =
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
[SentryDependencyContainer.sharedInstance getANRTrackerV1:options.appHangTimeoutInterval];

[self.tracker addListener:self];
self.options = options;
Expand Down
130 changes: 0 additions & 130 deletions Sources/Sentry/SentryANRTrackingIntegrationV2.m

This file was deleted.

20 changes: 10 additions & 10 deletions Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "SentryANRTracker.h"
#import "SentryANRTrackerV1.h"
#import "SentryANRTrackerV2.h"
#import "SentryBinaryImageCache.h"
#import "SentryDispatchFactory.h"
Expand Down Expand Up @@ -348,22 +348,22 @@ - (SentrySwizzleWrapper *)swizzleWrapper SENTRY_DISABLE_THREAD_SANITIZER(
}
#endif // SENTRY_UIKIT_AVAILABLE

- (SentryANRTracker *)getANRTracker:(NSTimeInterval)timeout
- (SentryANRTrackerV1 *)getANRTrackerV1:(NSTimeInterval)timeout
SENTRY_DISABLE_THREAD_SANITIZER("double-checked lock produce false alarms")
{
if (_anrTracker == nil) {
if (_anrTrackerV1 == nil) {
@synchronized(sentryDependencyContainerLock) {
if (_anrTracker == nil) {
_anrTracker =
[[SentryANRTracker alloc] initWithTimeoutInterval:timeout
crashWrapper:self.crashWrapper
dispatchQueueWrapper:self.dispatchQueueWrapper
threadWrapper:self.threadWrapper];
if (_anrTrackerV1 == nil) {
_anrTrackerV1 =
[[SentryANRTrackerV1 alloc] initWithTimeoutInterval:timeout
crashWrapper:self.crashWrapper
dispatchQueueWrapper:self.dispatchQueueWrapper
threadWrapper:self.threadWrapper];
}
}
}

return _anrTracker;
return _anrTrackerV1;
}

- (SentryNSProcessInfoWrapper *)processInfoWrapper SENTRY_DISABLE_THREAD_SANITIZER(
Expand Down
1 change: 0 additions & 1 deletion Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#import "SentryANRTracker.h"
#import "SentryANRTrackingIntegration.h"
#import "SentryAutoBreadcrumbTrackingIntegration.h"
#import "SentryAutoSessionTrackingIntegration.h"
Expand Down
6 changes: 4 additions & 2 deletions Sources/Sentry/SentryWatchdogTerminationTrackingIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if SENTRY_HAS_UIKIT

# import "SentryScope+Private.h"
# import <SentryANRTrackerV1.h>
# import <SentryAppState.h>
# import <SentryAppStateManager.h>
# import <SentryClient+Private.h>
Expand All @@ -12,6 +13,7 @@
# import <SentryHub.h>
# import <SentryOptions+Private.h>
# import <SentrySDK+Private.h>
# import <SentrySwift.h>
# import <SentryWatchdogTerminationLogic.h>
# import <SentryWatchdogTerminationScopeObserver.h>
# import <SentryWatchdogTerminationTracker.h>
Expand All @@ -21,7 +23,7 @@
@interface SentryWatchdogTerminationTrackingIntegration ()

@property (nonatomic, strong) SentryWatchdogTerminationTracker *tracker;
@property (nonatomic, strong) SentryANRTracker *anrTracker;
@property (nonatomic, strong) id<SentryANRTracker> anrTracker;
@property (nullable, nonatomic, copy) NSString *testConfigurationFilePath;
@property (nonatomic, strong) SentryAppStateManager *appStateManager;

Expand Down Expand Up @@ -72,7 +74,7 @@ - (BOOL)installWithOptions:(SentryOptions *)options
[self.tracker start];

self.anrTracker =
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
[SentryDependencyContainer.sharedInstance getANRTrackerV1:options.appHangTimeoutInterval];
[self.anrTracker addListener:self];

self.appStateManager = appStateManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "SentryDefines.h"

@class SentryANRTracker;
@class SentryANRTrackerV1;
@class SentryANRTrackerV2;
@class SentryAppStateManager;
@class SentryBinaryImageCache;
Expand Down Expand Up @@ -63,7 +63,7 @@ SENTRY_NO_INIT
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueueWrapper;
@property (nonatomic, strong) SentryNSNotificationCenterWrapper *notificationCenterWrapper;
@property (nonatomic, strong) SentryDebugImageProvider *debugImageProvider;
@property (nonatomic, strong) SentryANRTracker *anrTracker;
@property (nonatomic, strong) SentryANRTrackerV1 *anrTrackerV1;
@property (nonatomic, strong) SentryANRTrackerV2 *anrTrackerV2;
@property (nonatomic, strong) SentryNSProcessInfoWrapper *processInfoWrapper;
@property (nonatomic, strong) SentrySystemWrapper *systemWrapper;
Expand All @@ -90,7 +90,7 @@ SENTRY_NO_INIT
@property (nonatomic, strong) SentryReachability *reachability;
#endif // !TARGET_OS_WATCH

- (SentryANRTracker *)getANRTracker:(NSTimeInterval)timeout;
- (SentryANRTrackerV1 *)getANRTrackerV1:(NSTimeInterval)timeout;
#if SENTRY_UIKIT_AVAILABLE
- (SentryANRTrackerV2 *)getANRTrackerV2:(NSTimeInterval)timeout;
#endif // SENTRY_UIKIT_AVAILABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,14 @@ NS_ASSUME_NONNULL_BEGIN
* seconds, and it executes all events in time. Instead, what matters is how long the main thread
* needs to execute a newly added event to the run loop.
*/
@interface SentryANRTracker : NSObject
@interface SentryANRTrackerV1 : NSObject <SentryANRTracker>
SENTRY_NO_INIT

- (instancetype)initWithTimeoutInterval:(NSTimeInterval)timeoutInterval
crashWrapper:(SentryCrashWrapper *)crashWrapper
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
threadWrapper:(SentryThreadWrapper *)threadWrapper;

- (void)addListener:(id<SentryANRTrackerDelegate>)listener;

- (void)removeListener:(id<SentryANRTrackerDelegate>)listener;

// Function used for tests
- (void)clear;

@end

NS_ASSUME_NONNULL_END
9 changes: 1 addition & 8 deletions Sources/Sentry/include/SentryANRTrackerV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
* seconds, it can still respond to user input to navigate to a different screen, for example. In
* that scenario, the frame delay is around 97%.
*/
@interface SentryANRTrackerV2 : NSObject
@interface SentryANRTrackerV2 : NSObject <SentryANRTracker>
SENTRY_NO_INIT

- (instancetype)initWithTimeoutInterval:(NSTimeInterval)timeoutInterval
Expand All @@ -29,13 +29,6 @@ SENTRY_NO_INIT
threadWrapper:(SentryThreadWrapper *)threadWrapper
framesTracker:(SentryFramesTracker *)framesTracker;

- (void)addListener:(id<SentryANRTrackerDelegate>)listener;

- (void)removeListener:(id<SentryANRTrackerDelegate>)listener;

// Function used for tests
- (void)clear;

@end

NS_ASSUME_NONNULL_END
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryANRTrackingIntegration.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "SentryANRTracker.h"
#import "SentryANRTrackerV1.h"
#import "SentryBaseIntegration.h"
#import "SentrySwift.h"
#import <Foundation/Foundation.h>
Expand Down
23 changes: 0 additions & 23 deletions Sources/Sentry/include/SentryANRTrackingIntegrationV2.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#import "SentryDefines.h"

#if SENTRY_HAS_UIKIT

# import "SentryANRTracker.h"
# import "SentryBaseIntegration.h"
# import "SentrySwift.h"
# import <Foundation/Foundation.h>
Expand Down
12 changes: 12 additions & 0 deletions Sources/Swift/Integrations/ANR/SentryANRTracker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

@objc
protocol SentryANRTracker {
@objc(addListener:)
func add(listener: SentryANRTrackerDelegate)
@objc(removeListener:)
func remove(listener: SentryANRTrackerDelegate)

/// Only used for tests.
func clear()
}
Loading

0 comments on commit 2ed6c6b

Please sign in to comment.