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

refactor: Add file IO tracker to dependency injection container #4861

Merged
merged 1 commit into from
Feb 20, 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
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 @@

@implementation SentryFileIOTracker

NSString *const SENTRY_TRACKING_COUNTER_KEY = @"SENTRY_TRACKING_COUNTER_KEY";

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

Check warning on line 38 in Sources/Sentry/SentryFileIOTracker.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryFileIOTracker.m#L37-L38

Added lines #L37 - L38 were not covered by tests

- (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
Loading