Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Ensure the current GPU frame rate is always reported for concurrent transaction profiling metrics (#2929)
- Possible crash in Core Data tracking (#2865)
- Move profiler metric collection to a background queue (#2956)

## 8.5.0

Expand Down
24 changes: 24 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,12 @@
84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8891A28DBD28900C51DFD /* SentryDevice.h */; };
84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8891B28DBD28900C51DFD /* SentryDevice.mm */; };
84A8892128DBD8D600C51DFD /* SentryDeviceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */; };
84AC61D229F7541E009EEF61 /* SentryDispatchSourceWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 84AC61D029F7541E009EEF61 /* SentryDispatchSourceWrapper.h */; };
84AC61D329F7541E009EEF61 /* SentryDispatchSourceWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 84AC61D129F7541E009EEF61 /* SentryDispatchSourceWrapper.m */; };
84AC61D629F75A98009EEF61 /* SentryDispatchFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 84AC61D429F75A98009EEF61 /* SentryDispatchFactory.h */; };
84AC61D729F75A98009EEF61 /* SentryDispatchFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 84AC61D529F75A98009EEF61 /* SentryDispatchFactory.m */; };
84AC61D929F7643B009EEF61 /* TestDispatchFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AC61D829F7643B009EEF61 /* TestDispatchFactory.swift */; };
84AC61DB29F7654A009EEF61 /* TestDispatchSourceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */; };
84AF45A629A7FFA500FBB177 /* SentryTracerConcurrency.h in Headers */ = {isa = PBXBuildFile; fileRef = 84AF45A429A7FFA500FBB177 /* SentryTracerConcurrency.h */; };
84AF45A729A7FFA500FBB177 /* SentryTracerConcurrency.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84AF45A529A7FFA500FBB177 /* SentryTracerConcurrency.mm */; };
84B7FA3529B285FC00AD93B1 /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63AA759B1EB8AEF500D153DE /* Sentry.framework */; };
Expand Down Expand Up @@ -1549,6 +1555,12 @@
84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = include/SentryDevice.h; sourceTree = "<group>"; };
84A8891B28DBD28900C51DFD /* SentryDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDevice.mm; sourceTree = "<group>"; };
84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDeviceTests.mm; sourceTree = "<group>"; };
84AC61D029F7541E009EEF61 /* SentryDispatchSourceWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryDispatchSourceWrapper.h; sourceTree = "<group>"; };
84AC61D129F7541E009EEF61 /* SentryDispatchSourceWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDispatchSourceWrapper.m; sourceTree = "<group>"; };
84AC61D429F75A98009EEF61 /* SentryDispatchFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryDispatchFactory.h; sourceTree = "<group>"; };
84AC61D529F75A98009EEF61 /* SentryDispatchFactory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDispatchFactory.m; sourceTree = "<group>"; };
84AC61D829F7643B009EEF61 /* TestDispatchFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDispatchFactory.swift; sourceTree = "<group>"; };
84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDispatchSourceWrapper.swift; sourceTree = "<group>"; };
84AF45A429A7FFA500FBB177 /* SentryTracerConcurrency.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTracerConcurrency.h; path = include/SentryTracerConcurrency.h; sourceTree = "<group>"; };
84AF45A529A7FFA500FBB177 /* SentryTracerConcurrency.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryTracerConcurrency.mm; sourceTree = "<group>"; };
84B7FA3B29B2866200AD93B1 /* SentryTestUtils-ObjC-BridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryTestUtils-ObjC-BridgingHeader.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1829,6 +1841,10 @@
638DC99F1EBC6B6400A66E41 /* SentryRequestOperation.m */,
7BDB03B6251364F800BAE198 /* SentryDispatchQueueWrapper.h */,
7BDB03BA2513652900BAE198 /* SentryDispatchQueueWrapper.m */,
84AC61D029F7541E009EEF61 /* SentryDispatchSourceWrapper.h */,
84AC61D429F75A98009EEF61 /* SentryDispatchFactory.h */,
84AC61D529F75A98009EEF61 /* SentryDispatchFactory.m */,
84AC61D129F7541E009EEF61 /* SentryDispatchSourceWrapper.m */,
0AAE202028ED9BCC00D0CD80 /* SentryReachability.h */,
0AAE201D28ED9B9400D0CD80 /* SentryReachability.m */,
);
Expand Down Expand Up @@ -3096,6 +3112,8 @@
isa = PBXGroup;
children = (
7BD47B4C268F0B080076A663 /* ClearTestState.swift */,
84AC61D829F7643B009EEF61 /* TestDispatchFactory.swift */,
84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */,
84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */,
7B30B68126527C55006B2752 /* TestDisplayLinkWrapper.swift */,
8E25C97425F8511A00DC215B /* TestRandom.swift */,
Expand Down Expand Up @@ -3351,6 +3369,7 @@
7B82D54524E2A05500EE670F /* SentryId.h in Headers */,
D867063D27C3BC2400048851 /* SentryCoreDataTrackingIntegration.h in Headers */,
0A2D8D5D289815EB008720F6 /* SentryBaseIntegration.h in Headers */,
84AC61D629F75A98009EEF61 /* SentryDispatchFactory.h in Headers */,
63FE716520DA4C1100CDBAE8 /* SentryCrashMemory.h in Headers */,
63FE713F20DA4C1100CDBAE8 /* SentryCrashStackCursor_SelfThread.h in Headers */,
639FCFA41EBC809A00778193 /* SentryStacktrace.h in Headers */,
Expand Down Expand Up @@ -3474,6 +3493,7 @@
632331F9240506DF008D91D6 /* SentryScope+Private.h in Headers */,
D8603DD8284F894C000E1227 /* SentryBaggage.h in Headers */,
03F84D2127DD414C008FE43F /* SentrySamplingProfiler.hpp in Headers */,
84AC61D229F7541E009EEF61 /* SentryDispatchSourceWrapper.h in Headers */,
63FE712B20DA4C1100CDBAE8 /* SentryCrashStackCursor.h in Headers */,
D8C67E9C28000E24007E326E /* SentryScreenshot.h in Headers */,
7BA61CBF247CEA8100C130A8 /* SentryHexAddressFormatter.h in Headers */,
Expand Down Expand Up @@ -3883,6 +3903,7 @@
63FE712920DA4C1000CDBAE8 /* SentryCrashCPU_arm.c in Sources */,
03F84D3427DD4191008FE43F /* SentryThreadMetadataCache.cpp in Sources */,
7B88F30024BC5A7D00ADF90A /* SentrySdkInfo.m in Sources */,
84AC61D729F75A98009EEF61 /* SentryDispatchFactory.m in Sources */,
15360CD62432832400112302 /* SentryAutoSessionTrackingIntegration.m in Sources */,
7B63459F280EBA7200CFA05A /* SentryUIEventTracker.m in Sources */,
7BF9EF782722B35D00B5BBEF /* SentrySubClassFinder.m in Sources */,
Expand Down Expand Up @@ -3999,6 +4020,7 @@
7BB65501253DC1B500887E87 /* SentryUserFeedback.m in Sources */,
7D5C441A237C2E1F00DAB0A3 /* SentrySDK.m in Sources */,
7D65260E237F649E00113EA2 /* SentryScope.m in Sources */,
84AC61D329F7541E009EEF61 /* SentryDispatchSourceWrapper.m in Sources */,
63FE712D20DA4C1100CDBAE8 /* SentryCrashJSONCodecObjC.m in Sources */,
7BBD18932449BEDD00427C76 /* SentryDefaultRateLimits.m in Sources */,
7BD729982463E93500EA3610 /* SentryDateUtil.m in Sources */,
Expand Down Expand Up @@ -4329,6 +4351,7 @@
84B7FA4229B28CDE00AD93B1 /* TestCurrentDateProvider.swift in Sources */,
84B7FA3F29B28BAD00AD93B1 /* TestTransport.swift in Sources */,
84A5D75B29D5170700388BFA /* TimeInterval+Sentry.swift in Sources */,
84AC61D929F7643B009EEF61 /* TestDispatchFactory.swift in Sources */,
8431F01929B2852D00D8DC56 /* Invocation.swift in Sources */,
84B7FA4629B2935F00AD93B1 /* ClearTestState.swift in Sources */,
8431F01529B2851500D8DC56 /* TestSentryNSTimerWrapper.swift in Sources */,
Expand All @@ -4340,6 +4363,7 @@
8431F01B29B2852D00D8DC56 /* Logger.swift in Sources */,
8431F01829B2852D00D8DC56 /* TypeMapping.swift in Sources */,
84B7FA4529B2926900AD93B1 /* TestDisplayLinkWrapper.swift in Sources */,
84AC61DB29F7654A009EEF61 /* TestDispatchSourceWrapper.swift in Sources */,
8431F01729B2851500D8DC56 /* TestSentrySystemWrapper.swift in Sources */,
84B7FA4129B28CD200AD93B1 /* TestSentryDispatchQueueWrapper.swift in Sources */,
84B7FA3E29B28ADD00AD93B1 /* TestClient.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#import "SentryCurrentDateProvider.h"
#import "SentryDefines.h"
#import "SentryDependencyContainer.h"
#import "SentryDispatchFactory.h"
#import "SentryDispatchQueueWrapper.h"
#import "SentryDispatchSourceWrapper.h"
#import "SentryDisplayLinkWrapper.h"
#import "SentryEnvelope.h"
#import "SentryFileManager.h"
Expand Down
25 changes: 25 additions & 0 deletions SentryTestUtils/TestDispatchFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation
import Sentry

public class TestDispatchFactory: SentryDispatchFactory {
public var vendedSourceHandler: ((TestDispatchSourceWrapper) -> Void)?
public var vendedQueueHandler: ((TestSentryDispatchQueueWrapper) -> Void)?

public override func queue(withName name: UnsafePointer<CChar>, attributes: __OS_dispatch_queue_attr) -> SentryDispatchQueueWrapper {
let queue = TestSentryDispatchQueueWrapper(name: name, attributes: attributes)
vendedQueueHandler?(queue)
return queue
}

public override func source(withInterval interval: UInt64, leeway: UInt64, queue queueWrapper: SentryDispatchQueueWrapper, eventHandler: @escaping () -> Void) -> SentryDispatchSourceWrapper {
let source = TestDispatchSourceWrapper(eventHandler: eventHandler)
vendedSourceHandler?(source)
return source
}

public override func source(withInterval interval: UInt64, leeway: UInt64, queueName: UnsafePointer<CChar>, attributes: __OS_dispatch_queue_attr, eventHandler: @escaping () -> Void) -> SentryDispatchSourceWrapper {
let source = TestDispatchSourceWrapper(eventHandler: eventHandler)
vendedSourceHandler?(source)
return source
}
}
22 changes: 22 additions & 0 deletions SentryTestUtils/TestDispatchSourceWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Foundation
import Sentry

public class TestDispatchSourceWrapper: SentryDispatchSourceWrapper {
public struct Override {
public var eventHandler: (() -> Void)?
}
public var overrides = Override()

public init(eventHandler: @escaping () -> Void) {
self.overrides.eventHandler = eventHandler
super.init()
}

public override func cancel() {
// no-op
}

public func fire() {
self.overrides.eventHandler?()
}
}
40 changes: 40 additions & 0 deletions Sources/Sentry/SentryDispatchFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#import <Foundation/Foundation.h>

@class SentryDispatchQueueWrapper;
@class SentryDispatchSourceWrapper;

NS_ASSUME_NONNULL_BEGIN

/**
* A type of object that vends wrappers for dispatch queues and sources, which can be subclassed to
* vend their mocked test subclasses.
*/
@interface SentryDispatchFactory : NSObject

/**
* Generate a new @c SentryDispatchQueueWrapper .
*/
- (SentryDispatchQueueWrapper *)queueWithName:(const char *)name
attributes:(dispatch_queue_attr_t)attributes;

/**
* Generate a @c dispatch_source_t using the provided @c SentryDispatchQueueWrapper .
*/
- (SentryDispatchSourceWrapper *)sourceWithInterval:(uint64_t)interval
leeway:(uint64_t)leeway
queue:(SentryDispatchQueueWrapper *)queueWrapper
eventHandler:(void (^)(void))eventHandler;

/**
* Generate a @c dispatch_source_t by internally vending the required @c SentryDispatchQueueWrapper
* .
*/
- (SentryDispatchSourceWrapper *)sourceWithInterval:(uint64_t)interval
leeway:(uint64_t)leeway
queueName:(const char *)queueName
attributes:(dispatch_queue_attr_t)attributes
eventHandler:(void (^)(void))eventHandler;

@end

NS_ASSUME_NONNULL_END
36 changes: 36 additions & 0 deletions Sources/Sentry/SentryDispatchFactory.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#import "SentryDispatchFactory.h"
#import "SentryDispatchQueueWrapper.h"
#import "SentryDispatchSourceWrapper.h"

@implementation SentryDispatchFactory

- (SentryDispatchQueueWrapper *)queueWithName:(const char *)name
attributes:(dispatch_queue_attr_t)attributes
{
return [[SentryDispatchQueueWrapper alloc] initWithName:name attributes:attributes];
}

- (SentryDispatchSourceWrapper *)sourceWithInterval:(uint64_t)interval
leeway:(uint64_t)leeway
queue:(SentryDispatchQueueWrapper *)queueWrapper
eventHandler:(void (^)(void))eventHandler
{
return [[SentryDispatchSourceWrapper alloc] initTimerWithInterval:interval
leeway:leeway
queue:queueWrapper
eventHandler:eventHandler];
}

- (SentryDispatchSourceWrapper *)sourceWithInterval:(uint64_t)interval
leeway:(uint64_t)leeway
queueName:(const char *)queueName
attributes:(dispatch_queue_attr_t)attributes
eventHandler:(void (^)(void))eventHandler
{
return [self sourceWithInterval:interval
leeway:leeway
queue:[self queueWithName:queueName attributes:attributes]
eventHandler:eventHandler];
}

@end
14 changes: 4 additions & 10 deletions Sources/Sentry/SentryDispatchQueueWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@

NS_ASSUME_NONNULL_BEGIN

@implementation SentryDispatchQueueWrapper {
// Don't use a normal property because on RN a user got a warning "Property with 'retain (or
// strong)' attribute must be of object type". A dispatch queue is since iOS 6.0 an NSObject so
// it should work with strong, but nevertheless, we use an instance variable to fix this
// warning.
dispatch_queue_t queue;
}
Comment on lines -6 to -12
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer true since we bumped our min supported version. I believe we can also change this:

// DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL is requires iOS 10. Since we are targeting
// iOS 9 we need to manually add the autoreleasepool.

This is now exposed as a property in the public interface so it can be accessed when setting up a new dispatch_source_t in SentryDispatchSourceWrapper[

@implementation SentryDispatchQueueWrapper

- (instancetype)init
{
Expand All @@ -24,14 +18,14 @@ - (instancetype)init
- (instancetype)initWithName:(const char *)name attributes:(dispatch_queue_attr_t)attributes;
{
if (self = [super init]) {
queue = dispatch_queue_create(name, attributes);
_queue = dispatch_queue_create(name, attributes);
}
return self;
}

- (void)dispatchAsyncWithBlock:(void (^)(void))block
{
dispatch_async(queue, ^{
dispatch_async(_queue, ^{
@autoreleasepool {
block();
}
Expand Down Expand Up @@ -60,7 +54,7 @@ - (void)dispatchAfter:(NSTimeInterval)interval block:(dispatch_block_t)block
{
dispatch_time_t delta = (int64_t)(interval * NSEC_PER_SEC);
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, delta);
dispatch_after(when, queue, ^{
dispatch_after(when, _queue, ^{
@autoreleasepool {
block();
}
Expand Down
21 changes: 21 additions & 0 deletions Sources/Sentry/SentryDispatchSourceWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#import <Foundation/Foundation.h>

@class SentryDispatchQueueWrapper;

NS_ASSUME_NONNULL_BEGIN

/**
* A wrapper around a @c dispatch_source_t that can be subclassed for mocking in tests.
*/
@interface SentryDispatchSourceWrapper : NSObject

- (instancetype)initTimerWithInterval:(uint64_t)interval
leeway:(uint64_t)leeway
queue:(SentryDispatchQueueWrapper *)queueWrapper
eventHandler:(void (^)(void))eventHandler;

- (void)cancel;

@end

NS_ASSUME_NONNULL_END
32 changes: 32 additions & 0 deletions Sources/Sentry/SentryDispatchSourceWrapper.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#import "SentryDispatchSourceWrapper.h"
#import "SentryDispatchQueueWrapper.h"

@implementation SentryDispatchSourceWrapper {
SentryDispatchQueueWrapper *_queueWrapper;
dispatch_source_t _source;
}

- (instancetype)initTimerWithInterval:(uint64_t)interval
leeway:(uint64_t)leeway
queue:(SentryDispatchQueueWrapper *)queueWrapper
eventHandler:(void (^)(void))eventHandler
{
if (!(self = [super init])) {
return nil;
}

_queueWrapper = queueWrapper;
_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queueWrapper.queue);
dispatch_source_set_event_handler(_source, eventHandler);
dispatch_source_set_timer(
_source, dispatch_time(DISPATCH_TIME_NOW, interval), interval, leeway);
dispatch_resume(_source);
return self;
}

- (void)cancel
{
dispatch_cancel(_source);
}

@end
Loading