Skip to content

Commit fcf88c3

Browse files
authored
Merge 4355b03 into d257eb9
2 parents d257eb9 + 4355b03 commit fcf88c3

17 files changed

+257
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

1011
## 8.5.0
1112

Sentry.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,12 @@
635635
84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8891A28DBD28900C51DFD /* SentryDevice.h */; };
636636
84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8891B28DBD28900C51DFD /* SentryDevice.mm */; };
637637
84A8892128DBD8D600C51DFD /* SentryDeviceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */; };
638+
84AC61D229F7541E009EEF61 /* SentryDispatchSourceWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 84AC61D029F7541E009EEF61 /* SentryDispatchSourceWrapper.h */; };
639+
84AC61D329F7541E009EEF61 /* SentryDispatchSourceWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 84AC61D129F7541E009EEF61 /* SentryDispatchSourceWrapper.m */; };
640+
84AC61D629F75A98009EEF61 /* SentryDispatchFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 84AC61D429F75A98009EEF61 /* SentryDispatchFactory.h */; };
641+
84AC61D729F75A98009EEF61 /* SentryDispatchFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 84AC61D529F75A98009EEF61 /* SentryDispatchFactory.m */; };
642+
84AC61D929F7643B009EEF61 /* TestDispatchFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AC61D829F7643B009EEF61 /* TestDispatchFactory.swift */; };
643+
84AC61DB29F7654A009EEF61 /* TestDispatchSourceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */; };
638644
84AF45A629A7FFA500FBB177 /* SentryTracerConcurrency.h in Headers */ = {isa = PBXBuildFile; fileRef = 84AF45A429A7FFA500FBB177 /* SentryTracerConcurrency.h */; };
639645
84AF45A729A7FFA500FBB177 /* SentryTracerConcurrency.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84AF45A529A7FFA500FBB177 /* SentryTracerConcurrency.mm */; };
640646
84B7FA3529B285FC00AD93B1 /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63AA759B1EB8AEF500D153DE /* Sentry.framework */; };
@@ -1549,6 +1555,12 @@
15491555
84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = include/SentryDevice.h; sourceTree = "<group>"; };
15501556
84A8891B28DBD28900C51DFD /* SentryDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDevice.mm; sourceTree = "<group>"; };
15511557
84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDeviceTests.mm; sourceTree = "<group>"; };
1558+
84AC61D029F7541E009EEF61 /* SentryDispatchSourceWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryDispatchSourceWrapper.h; sourceTree = "<group>"; };
1559+
84AC61D129F7541E009EEF61 /* SentryDispatchSourceWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDispatchSourceWrapper.m; sourceTree = "<group>"; };
1560+
84AC61D429F75A98009EEF61 /* SentryDispatchFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryDispatchFactory.h; sourceTree = "<group>"; };
1561+
84AC61D529F75A98009EEF61 /* SentryDispatchFactory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDispatchFactory.m; sourceTree = "<group>"; };
1562+
84AC61D829F7643B009EEF61 /* TestDispatchFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDispatchFactory.swift; sourceTree = "<group>"; };
1563+
84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDispatchSourceWrapper.swift; sourceTree = "<group>"; };
15521564
84AF45A429A7FFA500FBB177 /* SentryTracerConcurrency.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTracerConcurrency.h; path = include/SentryTracerConcurrency.h; sourceTree = "<group>"; };
15531565
84AF45A529A7FFA500FBB177 /* SentryTracerConcurrency.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryTracerConcurrency.mm; sourceTree = "<group>"; };
15541566
84B7FA3B29B2866200AD93B1 /* SentryTestUtils-ObjC-BridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryTestUtils-ObjC-BridgingHeader.h"; sourceTree = "<group>"; };
@@ -1829,6 +1841,10 @@
18291841
638DC99F1EBC6B6400A66E41 /* SentryRequestOperation.m */,
18301842
7BDB03B6251364F800BAE198 /* SentryDispatchQueueWrapper.h */,
18311843
7BDB03BA2513652900BAE198 /* SentryDispatchQueueWrapper.m */,
1844+
84AC61D029F7541E009EEF61 /* SentryDispatchSourceWrapper.h */,
1845+
84AC61D429F75A98009EEF61 /* SentryDispatchFactory.h */,
1846+
84AC61D529F75A98009EEF61 /* SentryDispatchFactory.m */,
1847+
84AC61D129F7541E009EEF61 /* SentryDispatchSourceWrapper.m */,
18321848
0AAE202028ED9BCC00D0CD80 /* SentryReachability.h */,
18331849
0AAE201D28ED9B9400D0CD80 /* SentryReachability.m */,
18341850
);
@@ -3096,6 +3112,8 @@
30963112
isa = PBXGroup;
30973113
children = (
30983114
7BD47B4C268F0B080076A663 /* ClearTestState.swift */,
3115+
84AC61D829F7643B009EEF61 /* TestDispatchFactory.swift */,
3116+
84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */,
30993117
84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */,
31003118
7B30B68126527C55006B2752 /* TestDisplayLinkWrapper.swift */,
31013119
8E25C97425F8511A00DC215B /* TestRandom.swift */,
@@ -3351,6 +3369,7 @@
33513369
7B82D54524E2A05500EE670F /* SentryId.h in Headers */,
33523370
D867063D27C3BC2400048851 /* SentryCoreDataTrackingIntegration.h in Headers */,
33533371
0A2D8D5D289815EB008720F6 /* SentryBaseIntegration.h in Headers */,
3372+
84AC61D629F75A98009EEF61 /* SentryDispatchFactory.h in Headers */,
33543373
63FE716520DA4C1100CDBAE8 /* SentryCrashMemory.h in Headers */,
33553374
63FE713F20DA4C1100CDBAE8 /* SentryCrashStackCursor_SelfThread.h in Headers */,
33563375
639FCFA41EBC809A00778193 /* SentryStacktrace.h in Headers */,
@@ -3474,6 +3493,7 @@
34743493
632331F9240506DF008D91D6 /* SentryScope+Private.h in Headers */,
34753494
D8603DD8284F894C000E1227 /* SentryBaggage.h in Headers */,
34763495
03F84D2127DD414C008FE43F /* SentrySamplingProfiler.hpp in Headers */,
3496+
84AC61D229F7541E009EEF61 /* SentryDispatchSourceWrapper.h in Headers */,
34773497
63FE712B20DA4C1100CDBAE8 /* SentryCrashStackCursor.h in Headers */,
34783498
D8C67E9C28000E24007E326E /* SentryScreenshot.h in Headers */,
34793499
7BA61CBF247CEA8100C130A8 /* SentryHexAddressFormatter.h in Headers */,
@@ -3883,6 +3903,7 @@
38833903
63FE712920DA4C1000CDBAE8 /* SentryCrashCPU_arm.c in Sources */,
38843904
03F84D3427DD4191008FE43F /* SentryThreadMetadataCache.cpp in Sources */,
38853905
7B88F30024BC5A7D00ADF90A /* SentrySdkInfo.m in Sources */,
3906+
84AC61D729F75A98009EEF61 /* SentryDispatchFactory.m in Sources */,
38863907
15360CD62432832400112302 /* SentryAutoSessionTrackingIntegration.m in Sources */,
38873908
7B63459F280EBA7200CFA05A /* SentryUIEventTracker.m in Sources */,
38883909
7BF9EF782722B35D00B5BBEF /* SentrySubClassFinder.m in Sources */,
@@ -3999,6 +4020,7 @@
39994020
7BB65501253DC1B500887E87 /* SentryUserFeedback.m in Sources */,
40004021
7D5C441A237C2E1F00DAB0A3 /* SentrySDK.m in Sources */,
40014022
7D65260E237F649E00113EA2 /* SentryScope.m in Sources */,
4023+
84AC61D329F7541E009EEF61 /* SentryDispatchSourceWrapper.m in Sources */,
40024024
63FE712D20DA4C1100CDBAE8 /* SentryCrashJSONCodecObjC.m in Sources */,
40034025
7BBD18932449BEDD00427C76 /* SentryDefaultRateLimits.m in Sources */,
40044026
7BD729982463E93500EA3610 /* SentryDateUtil.m in Sources */,
@@ -4329,6 +4351,7 @@
43294351
84B7FA4229B28CDE00AD93B1 /* TestCurrentDateProvider.swift in Sources */,
43304352
84B7FA3F29B28BAD00AD93B1 /* TestTransport.swift in Sources */,
43314353
84A5D75B29D5170700388BFA /* TimeInterval+Sentry.swift in Sources */,
4354+
84AC61D929F7643B009EEF61 /* TestDispatchFactory.swift in Sources */,
43324355
8431F01929B2852D00D8DC56 /* Invocation.swift in Sources */,
43334356
84B7FA4629B2935F00AD93B1 /* ClearTestState.swift in Sources */,
43344357
8431F01529B2851500D8DC56 /* TestSentryNSTimerWrapper.swift in Sources */,
@@ -4340,6 +4363,7 @@
43404363
8431F01B29B2852D00D8DC56 /* Logger.swift in Sources */,
43414364
8431F01829B2852D00D8DC56 /* TypeMapping.swift in Sources */,
43424365
84B7FA4529B2926900AD93B1 /* TestDisplayLinkWrapper.swift in Sources */,
4366+
84AC61DB29F7654A009EEF61 /* TestDispatchSourceWrapper.swift in Sources */,
43434367
8431F01729B2851500D8DC56 /* TestSentrySystemWrapper.swift in Sources */,
43444368
84B7FA4129B28CD200AD93B1 /* TestSentryDispatchQueueWrapper.swift in Sources */,
43454369
84B7FA3E29B28ADD00AD93B1 /* TestClient.swift in Sources */,

SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#import "SentryCurrentDateProvider.h"
99
#import "SentryDefines.h"
1010
#import "SentryDependencyContainer.h"
11+
#import "SentryDispatchFactory.h"
1112
#import "SentryDispatchQueueWrapper.h"
13+
#import "SentryDispatchSourceWrapper.h"
1214
#import "SentryDisplayLinkWrapper.h"
1315
#import "SentryEnvelope.h"
1416
#import "SentryFileManager.h"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Foundation
2+
import Sentry
3+
4+
public class TestDispatchFactory: SentryDispatchFactory {
5+
public var vendedSourceHandler: ((TestDispatchSourceWrapper) -> Void)?
6+
public var vendedQueueHandler: ((TestSentryDispatchQueueWrapper) -> Void)?
7+
8+
public override func queue(withName name: UnsafePointer<CChar>, attributes: __OS_dispatch_queue_attr) -> SentryDispatchQueueWrapper {
9+
let queue = TestSentryDispatchQueueWrapper(name: name, attributes: attributes)
10+
vendedQueueHandler?(queue)
11+
return queue
12+
}
13+
14+
public override func source(withInterval interval: UInt64, leeway: UInt64, queue queueWrapper: SentryDispatchQueueWrapper, eventHandler: @escaping () -> Void) -> SentryDispatchSourceWrapper {
15+
let source = TestDispatchSourceWrapper(eventHandler: eventHandler)
16+
vendedSourceHandler?(source)
17+
return source
18+
}
19+
20+
public override func source(withInterval interval: UInt64, leeway: UInt64, queueName: UnsafePointer<CChar>, attributes: __OS_dispatch_queue_attr, eventHandler: @escaping () -> Void) -> SentryDispatchSourceWrapper {
21+
let source = TestDispatchSourceWrapper(eventHandler: eventHandler)
22+
vendedSourceHandler?(source)
23+
return source
24+
}
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
import Sentry
3+
4+
public class TestDispatchSourceWrapper: SentryDispatchSourceWrapper {
5+
public struct Override {
6+
public var eventHandler: (() -> Void)?
7+
}
8+
public var overrides = Override()
9+
10+
public init(eventHandler: @escaping () -> Void) {
11+
self.overrides.eventHandler = eventHandler
12+
super.init()
13+
}
14+
15+
public override func cancel() {
16+
// no-op
17+
}
18+
19+
public func fire() {
20+
self.overrides.eventHandler?()
21+
}
22+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@class SentryDispatchQueueWrapper;
4+
@class SentryDispatchSourceWrapper;
5+
6+
NS_ASSUME_NONNULL_BEGIN
7+
8+
/**
9+
* A type of object that vends wrappers for dispatch queues and sources, which can be subclassed to
10+
* vend their mocked test subclasses.
11+
*/
12+
@interface SentryDispatchFactory : NSObject
13+
14+
/**
15+
* Generate a new @c SentryDispatchQueueWrapper .
16+
*/
17+
- (SentryDispatchQueueWrapper *)queueWithName:(const char *)name
18+
attributes:(dispatch_queue_attr_t)attributes;
19+
20+
/**
21+
* Generate a @c dispatch_source_t using the provided @c SentryDispatchQueueWrapper .
22+
*/
23+
- (SentryDispatchSourceWrapper *)sourceWithInterval:(uint64_t)interval
24+
leeway:(uint64_t)leeway
25+
queue:(SentryDispatchQueueWrapper *)queueWrapper
26+
eventHandler:(void (^)(void))eventHandler;
27+
28+
/**
29+
* Generate a @c dispatch_source_t by internally vending the required @c SentryDispatchQueueWrapper
30+
* .
31+
*/
32+
- (SentryDispatchSourceWrapper *)sourceWithInterval:(uint64_t)interval
33+
leeway:(uint64_t)leeway
34+
queueName:(const char *)queueName
35+
attributes:(dispatch_queue_attr_t)attributes
36+
eventHandler:(void (^)(void))eventHandler;
37+
38+
@end
39+
40+
NS_ASSUME_NONNULL_END
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#import "SentryDispatchFactory.h"
2+
#import "SentryDispatchQueueWrapper.h"
3+
#import "SentryDispatchSourceWrapper.h"
4+
5+
@implementation SentryDispatchFactory
6+
7+
- (SentryDispatchQueueWrapper *)queueWithName:(const char *)name
8+
attributes:(dispatch_queue_attr_t)attributes
9+
{
10+
return [[SentryDispatchQueueWrapper alloc] initWithName:name attributes:attributes];
11+
}
12+
13+
- (SentryDispatchSourceWrapper *)sourceWithInterval:(uint64_t)interval
14+
leeway:(uint64_t)leeway
15+
queue:(SentryDispatchQueueWrapper *)queueWrapper
16+
eventHandler:(void (^)(void))eventHandler
17+
{
18+
return [[SentryDispatchSourceWrapper alloc] initTimerWithInterval:interval
19+
leeway:leeway
20+
queue:queueWrapper
21+
eventHandler:eventHandler];
22+
}
23+
24+
- (SentryDispatchSourceWrapper *)sourceWithInterval:(uint64_t)interval
25+
leeway:(uint64_t)leeway
26+
queueName:(const char *)queueName
27+
attributes:(dispatch_queue_attr_t)attributes
28+
eventHandler:(void (^)(void))eventHandler
29+
{
30+
return [self sourceWithInterval:interval
31+
leeway:leeway
32+
queue:[self queueWithName:queueName attributes:attributes]
33+
eventHandler:eventHandler];
34+
}
35+
36+
@end

Sources/Sentry/SentryDispatchQueueWrapper.m

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33

44
NS_ASSUME_NONNULL_BEGIN
55

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

148
- (instancetype)init
159
{
@@ -24,14 +18,14 @@ - (instancetype)init
2418
- (instancetype)initWithName:(const char *)name attributes:(dispatch_queue_attr_t)attributes;
2519
{
2620
if (self = [super init]) {
27-
queue = dispatch_queue_create(name, attributes);
21+
_queue = dispatch_queue_create(name, attributes);
2822
}
2923
return self;
3024
}
3125

3226
- (void)dispatchAsyncWithBlock:(void (^)(void))block
3327
{
34-
dispatch_async(queue, ^{
28+
dispatch_async(_queue, ^{
3529
@autoreleasepool {
3630
block();
3731
}
@@ -60,7 +54,7 @@ - (void)dispatchAfter:(NSTimeInterval)interval block:(dispatch_block_t)block
6054
{
6155
dispatch_time_t delta = (int64_t)(interval * NSEC_PER_SEC);
6256
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, delta);
63-
dispatch_after(when, queue, ^{
57+
dispatch_after(when, _queue, ^{
6458
@autoreleasepool {
6559
block();
6660
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@class SentryDispatchQueueWrapper;
4+
5+
NS_ASSUME_NONNULL_BEGIN
6+
7+
/**
8+
* A wrapper around a @c dispatch_source_t that can be subclassed for mocking in tests.
9+
*/
10+
@interface SentryDispatchSourceWrapper : NSObject
11+
12+
- (instancetype)initTimerWithInterval:(uint64_t)interval
13+
leeway:(uint64_t)leeway
14+
queue:(SentryDispatchQueueWrapper *)queueWrapper
15+
eventHandler:(void (^)(void))eventHandler;
16+
17+
- (void)cancel;
18+
19+
@end
20+
21+
NS_ASSUME_NONNULL_END
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#import "SentryDispatchSourceWrapper.h"
2+
#import "SentryDispatchQueueWrapper.h"
3+
4+
@implementation SentryDispatchSourceWrapper {
5+
SentryDispatchQueueWrapper *_queueWrapper;
6+
dispatch_source_t _source;
7+
}
8+
9+
- (instancetype)initTimerWithInterval:(uint64_t)interval
10+
leeway:(uint64_t)leeway
11+
queue:(SentryDispatchQueueWrapper *)queueWrapper
12+
eventHandler:(void (^)(void))eventHandler
13+
{
14+
if (!(self = [super init])) {
15+
return nil;
16+
}
17+
18+
_queueWrapper = queueWrapper;
19+
_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queueWrapper.queue);
20+
dispatch_source_set_event_handler(_source, eventHandler);
21+
dispatch_source_set_timer(
22+
_source, dispatch_time(DISPATCH_TIME_NOW, interval), interval, leeway);
23+
dispatch_resume(_source);
24+
return self;
25+
}
26+
27+
- (void)cancel
28+
{
29+
dispatch_cancel(_source);
30+
}
31+
32+
@end

0 commit comments

Comments
 (0)