Skip to content

Commit

Permalink
Merge 588bf1d into ea2a263
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Jan 2, 2024
2 parents ea2a263 + 588bf1d commit aead7e8
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 66 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Check for NULL in binary image cache (#3469)
- Threading issues in binary image cache (#3468)
- Finish transaction for external view controllers (#3440)
- Missing transactions when not calling `reportFullyDisplayed` (#3477)

## 8.17.0

Expand Down
23 changes: 13 additions & 10 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
@property (nonatomic) BOOL wasFinishCalled;
@property (nonatomic, nullable, strong) NSTimer *deadlineTimer;
@property (nonnull, strong) SentryTracerConfiguration *configuration;
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueue;

#if SENTRY_TARGET_PROFILING_SUPPORTED
@property (nonatomic) BOOL isProfiling;
Expand Down Expand Up @@ -132,6 +133,7 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti

_startSystemTime = SentryDependencyContainer.sharedInstance.dateProvider.systemTime;
_configuration = configuration;
_dispatchQueue = SentryDependencyContainer.sharedInstance.dispatchQueueWrapper;

self.transactionContext = transactionContext;
_children = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -198,10 +200,10 @@ - (void)dispatchIdleTimeout
{
@synchronized(_idleTimeoutLock) {
if (_idleTimeoutBlock != NULL) {
[_configuration.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock];
[_dispatchQueue dispatchCancel:_idleTimeoutBlock];
}
__weak SentryTracer *weakSelf = self;
_idleTimeoutBlock = [_configuration.dispatchQueueWrapper createDispatchBlock:^{
_idleTimeoutBlock = [_dispatchQueue createDispatchBlock:^{
if (weakSelf == nil) {
SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not doing anything.");
return;
Expand All @@ -215,15 +217,14 @@ - (void)dispatchIdleTimeout
// If the transaction has no children, the SDK will discard it.
[self finishInternal];
} else {
[_configuration.dispatchQueueWrapper dispatchAfter:_configuration.idleTimeout
block:_idleTimeoutBlock];
[_dispatchQueue dispatchAfter:_configuration.idleTimeout block:_idleTimeoutBlock];
}
}
}

- (BOOL)hasIdleTimeout
{
return _configuration.idleTimeout > 0 && _configuration.dispatchQueueWrapper != nil;
return _configuration.idleTimeout > 0;
}

- (BOOL)isAutoGeneratedTransaction
Expand All @@ -235,15 +236,16 @@ - (void)cancelIdleTimeout
{
@synchronized(_idleTimeoutLock) {
if ([self hasIdleTimeout]) {
[_configuration.dispatchQueueWrapper dispatchCancel:_idleTimeoutBlock];
[SentryDependencyContainer.sharedInstance.dispatchQueueWrapper
dispatchCancel:_idleTimeoutBlock];
}
}
}

- (void)startDeadlineTimer
{
__weak SentryTracer *weakSelf = self;
[_configuration.dispatchQueueWrapper dispatchOnMainQueue:^{
[_dispatchQueue dispatchOnMainQueue:^{
weakSelf.deadlineTimer = [weakSelf.configuration.timerFactory
scheduledTimerWithTimeInterval:SENTRY_AUTO_TRANSACTION_DEADLINE
repeats:NO
Expand Down Expand Up @@ -285,7 +287,7 @@ - (void)cancelDeadlineTimer

// The timer must be invalidated from the thread on which the timer was installed, see
// https://developer.apple.com/documentation/foundation/nstimer/1415405-invalidate#1770468
[_configuration.dispatchQueueWrapper dispatchOnMainQueue:^{
[_dispatchQueue dispatchOnMainQueue:^{
if (weakSelf == nil) {
SENTRY_LOG_DEBUG(@"WeakSelf is nil. Not invalidating deadlineTimer.");
return;
Expand Down Expand Up @@ -454,8 +456,9 @@ - (void)canBeFinished
}

if (!self.wasFinishCalled || hasUnfinishedChildSpansToWaitFor) {
SENTRY_LOG_DEBUG(@"Span with id %@ has children but isn't waiting for them right now.",
self.spanId.sentrySpanIdString);
SENTRY_LOG_DEBUG(@"Span with id %@ has children but hasn't finished yet so isn't waiting "
@"for them right now.",
self.spanId.sentrySpanIdString);
return;
}
}
Expand Down
6 changes: 1 addition & 5 deletions Sources/Sentry/SentryUIEventTrackerTransactionMode.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
@interface
SentryUIEventTrackerTransactionMode ()

@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueueWrapper;
@property (nonatomic, assign) NSTimeInterval idleTimeout;
@property (nullable, nonatomic, strong) NSMutableArray<SentryTracer *> *activeTransactions;

@end

@implementation SentryUIEventTrackerTransactionMode

- (instancetype)initWithDispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
idleTimeout:(NSTimeInterval)idleTimeout
- (instancetype)initWithIdleTimeout:(NSTimeInterval)idleTimeout
{
if (self = [super init]) {
self.dispatchQueueWrapper = dispatchQueueWrapper;
self.idleTimeout = idleTimeout;
self.activeTransactions = [NSMutableArray new];
}
Expand Down Expand Up @@ -91,7 +88,6 @@ - (void)handleUIEvent:(NSString *)action
SentryTracerConfiguration *config) {
config.idleTimeout = self.idleTimeout;
config.waitForChildren = YES;
config.dispatchQueueWrapper = self.dispatchQueueWrapper;
}]];

SENTRY_LOG_DEBUG(@"Automatically started a new transaction with name: "
Expand Down
7 changes: 2 additions & 5 deletions Sources/Sentry/SentryUIEventTrackingIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#if SENTRY_HAS_UIKIT

# import <SentryDependencyContainer.h>
# import <SentryLog.h>
# import <SentryNSDataSwizzling.h>
# import <SentryOptions+Private.h>
Expand All @@ -25,10 +24,8 @@ - (BOOL)installWithOptions:(SentryOptions *)options
return NO;
}

SentryDependencyContainer *dependencies = [SentryDependencyContainer sharedInstance];
SentryUIEventTrackerTransactionMode *mode = [[SentryUIEventTrackerTransactionMode alloc]
initWithDispatchQueueWrapper:dependencies.dispatchQueueWrapper
idleTimeout:options.idleTimeout];
SentryUIEventTrackerTransactionMode *mode =
[[SentryUIEventTrackerTransactionMode alloc] initWithIdleTimeout:options.idleTimeout];

self.uiEventTracker = [[SentryUIEventTracker alloc] initWithMode:mode];

Expand Down
5 changes: 0 additions & 5 deletions Sources/Sentry/include/SentryTracerConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic) BOOL waitForChildren;

/**
* A dispatch queue wrapper to intermediate between the tracer and dispatch calls.
*/
@property (nonatomic, strong, nullable) SentryDispatchQueueWrapper *dispatchQueueWrapper;

#if SENTRY_TARGET_PROFILING_SUPPORTED
/**
* Whether to sample a profile corresponding to this transaction
Expand Down
5 changes: 1 addition & 4 deletions Sources/Sentry/include/SentryUIEventTrackerTransactionMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

#if SENTRY_HAS_UIKIT

@class SentryDispatchQueueWrapper;

NS_ASSUME_NONNULL_BEGIN

@interface SentryUIEventTrackerTransactionMode : NSObject <SentryUIEventTrackerMode>
SENTRY_NO_INIT

- (instancetype)initWithDispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
idleTimeout:(NSTimeInterval)idleTimeout;
- (instancetype)initWithIdleTimeout:(NSTimeInterval)idleTimeout;

@end

Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class SentryProfilerSwiftTests: XCTestCase {
}
SentryDependencyContainer.sharedInstance().dispatchFactory = dispatchFactory
SentryDependencyContainer.sharedInstance().timerFactory = timeoutTimerFactory
SentryDependencyContainer.sharedInstance().dispatchQueueWrapper = dispatchQueueWrapper

systemWrapper.overrides.cpuUsage = NSNumber(value: mockCPUUsage)
systemWrapper.overrides.memoryFootprintBytes = mockMemoryFootprint
Expand All @@ -76,7 +77,6 @@ class SentryProfilerSwiftTests: XCTestCase {
if let idleTimeout = idleTimeout {
$0.idleTimeout = idleTimeout
}
$0.dispatchQueueWrapper = self.dispatchQueueWrapper
$0.waitForChildren = true
$0.timerFactory = self.timeoutTimerFactory
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class SentryUIEventTrackerTests: XCTestCase {
init () {
dispatchQueue.blockBeforeMainBlock = { false }
SentryDependencyContainer.sharedInstance().swizzleWrapper = swizzleWrapper
uiEventTrackerMode = SentryUIEventTrackerTransactionMode(dispatchQueueWrapper: dispatchQueue, idleTimeout: 3.0)
SentryDependencyContainer.sharedInstance().dispatchQueueWrapper = dispatchQueue
uiEventTrackerMode = SentryUIEventTrackerTransactionMode(idleTimeout: 3.0)
}

func getSut() -> SentryUIEventTracker {
Expand Down

0 comments on commit aead7e8

Please sign in to comment.