-
-
Notifications
You must be signed in to change notification settings - Fork 372
perf: gather profiler metrics gathering on a low-pri queue #2956
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
Changes from 3 commits
95a84b1
9e2110e
4355b03
b9e160e
763b65d
7fdce6d
5a8ae1f
c195a4e
adef4bc
b4014ee
a544511
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| } | ||
| } |
| 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?() | ||
| } | ||
| } |
| 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 |
| 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 | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: sentry-cocoa/Sources/Sentry/SentryDispatchQueueWrapper.m Lines 16 to 17 in d257eb9
This is now exposed as a property in the public interface so it can be accessed when setting up a new |
||||||
| @implementation SentryDispatchQueueWrapper | ||||||
|
|
||||||
| - (instancetype)init | ||||||
| { | ||||||
|
|
@@ -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(); | ||||||
| } | ||||||
|
|
@@ -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(); | ||||||
| } | ||||||
|
|
||||||
| 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 |
| 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])) { | ||
armcknight marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.