Skip to content

Commit

Permalink
refactor: Add file IO tracker to dependency injection container
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime committed Feb 18, 2025
1 parent c5207e7 commit f17d69e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
16 changes: 16 additions & 0 deletions Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "SentryDispatchQueueWrapper.h"
#import "SentryDisplayLinkWrapper.h"
#import "SentryExtraContextProvider.h"
#import "SentryFileIOTracker.h"
#import "SentryFileManager.h"
#import "SentryInternalCDefines.h"
#import "SentryLog.h"
Expand Down Expand Up @@ -186,6 +187,21 @@ - (SentryThreadInspector *)threadInspector SENTRY_DISABLE_THREAD_SANITIZER(
return _threadInspector;
}

- (SentryFileIOTracker *)fileIOTracker SENTRY_DISABLE_THREAD_SANITIZER(
"double-checked lock produce false alarms")
{
if (_fileIOTracker == nil) {
@synchronized(sentryDependencyContainerLock) {
if (_fileIOTracker == nil) {
_fileIOTracker =
[[SentryFileIOTracker alloc] initWithThreadInspector:[self threadInspector]
processInfoWrapper:[self processInfoWrapper]];
}
}
}
return _fileIOTracker;
}

- (SentryDebugImageProvider *)debugImageProvider
{
@synchronized(sentryDependencyContainerLock) {
Expand Down
9 changes: 7 additions & 2 deletions Sources/Sentry/SentryFileIOTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#import "SentryThreadInspector.h"
#import "SentryTracer.h"

const NSString *SENTRY_TRACKING_COUNTER_KEY = @"SENTRY_TRACKING_COUNTER_KEY";

@interface SentryFileIOTracker ()

@property (nonatomic, assign) BOOL isEnabled;
Expand All @@ -32,6 +30,13 @@ @interface SentryFileIOTracker ()

@implementation SentryFileIOTracker

NSString *const SENTRY_TRACKING_COUNTER_KEY = @"SENTRY_TRACKING_COUNTER_KEY";

+ (instancetype)sharedInstance
{
return SentryDependencyContainer.sharedInstance.fileIOTracker;
}

- (instancetype)initWithThreadInspector:(SentryThreadInspector *)threadInspector
processInfoWrapper:(SentryNSProcessInfoWrapper *)processInfoWrapper
{
Expand Down
4 changes: 1 addition & 3 deletions Sources/Sentry/SentryFileIOTrackingIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ - (BOOL)installWithOptions:(SentryOptions *)options
return NO;
}

self.tracker = [[SentryFileIOTracker alloc]
initWithThreadInspector:[[SentryThreadInspector alloc] initWithOptions:options]
processInfoWrapper:[SentryDependencyContainer.sharedInstance processInfoWrapper]];
self.tracker = [[SentryDependencyContainer sharedInstance] fileIOTracker];
[self.tracker enable];

[SentryNSDataSwizzling.shared startWithOptions:options tracker:self.tracker];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@class SentrySystemWrapper;
@class SentryThreadWrapper;
@class SentryThreadInspector;
@class SentryFileIOTracker;
@protocol SentryRandom;
@protocol SentryCurrentDateProvider;
@protocol SentryRateLimits;
Expand Down Expand Up @@ -77,6 +78,7 @@ SENTRY_NO_INIT
@property (nonatomic, strong) SentrySysctl *sysctlWrapper;
@property (nonatomic, strong) SentryThreadInspector *threadInspector;
@property (nonatomic, strong) id<SentryRateLimits> rateLimits;
@property (nonatomic, strong) SentryFileIOTracker *fileIOTracker;

#if SENTRY_UIKIT_AVAILABLE
@property (nonatomic, strong) SentryFramesTracker *framesTracker;
Expand Down
9 changes: 9 additions & 0 deletions Sources/Sentry/include/SentryFileIOTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ NS_ASSUME_NONNULL_BEGIN
@interface SentryFileIOTracker : NSObject
SENTRY_NO_INIT

/**
* Convenience accessor to the shared instance of the tracker in the dependency container.
*
* @note Can be used from Swift without import the entire dependency container.
*
* @return The shared instance of the tracker.
*/
+ (instancetype)sharedInstance;

- (instancetype)initWithThreadInspector:(SentryThreadInspector *)threadInspector
processInfoWrapper:(SentryNSProcessInfoWrapper *)processInfoWrapper;

Expand Down
1 change: 1 addition & 0 deletions Sources/Sentry/include/SentryPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "SentryDateUtil.h"
#import "SentryDateUtils.h"
#import "SentryDisplayLinkWrapper.h"
#import "SentryFileIOTracker.h"
#import "SentryLevelHelper.h"
#import "SentryLogC.h"
#import "SentryMeta.h"
Expand Down

0 comments on commit f17d69e

Please sign in to comment.