Skip to content

Commit

Permalink
feat(profiling): add API to start/stop a continuous session (getsentr…
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored and Threema committed May 21, 2024
1 parent f34ea30 commit 192c140
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@
8454CF8D293EAF9A006AC140 /* SentryMetricProfiler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8454CF8B293EAF9A006AC140 /* SentryMetricProfiler.mm */; };
845C16D52A622A5B00EC9519 /* SentryTracer+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 845C16D42A622A5B00EC9519 /* SentryTracer+Private.h */; };
8489B8882A5F7905009A055A /* SentryThreadWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8489B8872A5F7905009A055A /* SentryThreadWrapperTests.swift */; };
848A45192BBF8D33006AAAEC /* SentryContinuousProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 848A45182BBF8D33006AAAEC /* SentryContinuousProfiler.m */; };
848A451A2BBF8D33006AAAEC /* SentryContinuousProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 848A45172BBF8D33006AAAEC /* SentryContinuousProfiler.h */; };
849AC40029E0C1FF00889C16 /* SentryFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849AC3FF29E0C1FF00889C16 /* SentryFormatterTests.swift */; };
84A5D75B29D5170700388BFA /* TimeInterval+Sentry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */; };
84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8891A28DBD28900C51DFD /* SentryDevice.h */; };
Expand Down Expand Up @@ -1681,6 +1683,8 @@
8454CF8B293EAF9A006AC140 /* SentryMetricProfiler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryMetricProfiler.mm; path = Sources/Sentry/SentryMetricProfiler.mm; sourceTree = SOURCE_ROOT; };
845C16D42A622A5B00EC9519 /* SentryTracer+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryTracer+Private.h"; path = "include/SentryTracer+Private.h"; sourceTree = "<group>"; };
8489B8872A5F7905009A055A /* SentryThreadWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SentryThreadWrapperTests.swift; path = Helper/SentryThreadWrapperTests.swift; sourceTree = "<group>"; };
848A45172BBF8D33006AAAEC /* SentryContinuousProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryContinuousProfiler.h; path = ../include/SentryContinuousProfiler.h; sourceTree = "<group>"; };
848A45182BBF8D33006AAAEC /* SentryContinuousProfiler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryContinuousProfiler.m; sourceTree = "<group>"; };
849472802971C107002603DE /* SentrySystemWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySystemWrapperTests.swift; sourceTree = "<group>"; };
849472822971C2CD002603DE /* SentryNSProcessInfoWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSProcessInfoWrapperTests.swift; sourceTree = "<group>"; };
849472842971C41A002603DE /* SentryNSTimerFactoryTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSTimerFactoryTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3314,6 +3318,8 @@
84AF45A529A7FFA500FBB177 /* SentryProfiledTracerConcurrency.mm */,
840B7EF22BBF83DF008B8120 /* SentryProfiler+Private.h */,
03F84D2B27DD4191008FE43F /* SentryProfiler.mm */,
848A45172BBF8D33006AAAEC /* SentryContinuousProfiler.h */,
848A45182BBF8D33006AAAEC /* SentryContinuousProfiler.m */,
0354A22A2A134D9C003C3A04 /* SentryProfilerState.h */,
84281C422A578E5600EE88F2 /* SentryProfilerState.mm */,
84281C642A57D36100EE88F2 /* SentryProfilerState+ObjCpp.h */,
Expand Down Expand Up @@ -3765,6 +3771,7 @@
92672BB629C9A2A9006B021C /* SentryBreadcrumb+Private.h in Headers */,
03BCC38E27E2A377003232C7 /* SentryProfilingConditionals.h in Headers */,
0ADC33EE28D9BB890078D980 /* SentryUIDeviceWrapper.h in Headers */,
848A451A2BBF8D33006AAAEC /* SentryContinuousProfiler.h in Headers */,
8E133FA625E72EB400ABD0BF /* SentrySamplingContext.h in Headers */,
0A9BF4E428A114B50068D266 /* SentryViewHierarchyIntegration.h in Headers */,
D8BBD32728FD9FC00011F850 /* SentrySwift.h in Headers */,
Expand Down Expand Up @@ -4430,6 +4437,7 @@
7BBD188B244841FB00427C76 /* SentryHttpDateParser.m in Sources */,
840A11122B61E27500650D02 /* SentrySamplerDecision.m in Sources */,
8E4E7C8225DAB2A5006AB9E2 /* SentryTracer.m in Sources */,
848A45192BBF8D33006AAAEC /* SentryContinuousProfiler.m in Sources */,
15E0A8E5240C457D00F044E3 /* SentryEnvelope.m in Sources */,
03F84D3627DD4191008FE43F /* SentryProfilingLogging.mm in Sources */,
8EC3AE7A25CA23B600E7591A /* SentrySpan.m in Sources */,
Expand Down
20 changes: 20 additions & 0 deletions Sources/Sentry/Profiling/SentryContinuousProfiler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#import "SentryContinuousProfiler.h"
#import "SentryInternalDefines.h"

@implementation SentryContinuousProfiler

#pragma mark - Public

+ (void)start
{
// TODO: start a continuous profiling session
SENTRY_GRACEFUL_FATAL(@"TODO: start a continuous profiling session");
}

+ (void)stop
{
// TODO: stop the continuous profiling session
SENTRY_GRACEFUL_FATAL(@"TODO: stop the continuous profiling session");
}

@end
7 changes: 3 additions & 4 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#if SENTRY_TARGET_PROFILING_SUPPORTED
# import "SentryAppStartMeasurement.h"
# import "SentryClient+Private.h"
# import "SentryContinuousProfiler.h"
# import "SentryDateUtils.h"
# import "SentryDebugImageProvider.h"
# import "SentryDebugMeta.h"
Expand Down Expand Up @@ -288,6 +289,8 @@ @implementation SentryProfiler {
NSTimer *_timeoutTimer;
}

# pragma mark - Private

- (instancetype)init
{
if (!(self = [super init])) {
Expand Down Expand Up @@ -341,8 +344,6 @@ - (void)scheduleTimeoutTimer
}];
}

# pragma mark - Public

+ (BOOL)startWithTracer:(SentryId *)traceId
{
std::lock_guard<std::mutex> l(_gProfilerLock);
Expand Down Expand Up @@ -479,8 +480,6 @@ + (nullable SentryEnvelopeItem *)createEnvelopeItemForProfilePayload:
return payload;
}

# pragma mark - Private

+ (void)updateProfilePayload:(NSMutableDictionary<NSString *, id> *)payload
forTransaction:(SentryTransaction *)transaction
startTimestamp:(NSDate *)startTimestamp
Expand Down
25 changes: 25 additions & 0 deletions Sources/Sentry/SentrySDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#endif // SENTRY_HAS_UIKIT

#if SENTRY_TARGET_PROFILING_SUPPORTED
# import "SentryContinuousProfiler.h"
# import "SentryLaunchProfiling.h"
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

Expand Down Expand Up @@ -521,6 +522,30 @@ + (void)crash
}
#endif

#if SENTRY_TARGET_PROFILING_SUPPORTED
+ (void)startProfiler
{
if (!SENTRY_ASSERT_RETURN(currentHub.client.options.enableContinuousProfiling,
@"You must set SentryOptions.enableContinuousProfiling to true before starting a "
@"continuous profiler.")) {
return;
}

[SentryContinuousProfiler start];
}

+ (void)stopProfiler
{
if (!SENTRY_ASSERT_RETURN(currentHub.client.options.enableContinuousProfiling,
@"You must set SentryOptions.enableContinuousProfiling to true before using continuous "
@"profiling API.")) {
return;
}

[SentryContinuousProfiler stop];
}
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

@end

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "SentryNSDictionarySanitize.h"
#import "SentryNSTimerFactory.h"
#import "SentryNoOpSpan.h"
#import "SentryOptions+Private.h"
#import "SentryProfilingConditionals.h"
#import "SentryRandom.h"
#import "SentrySDK+Private.h"
Expand Down
18 changes: 18 additions & 0 deletions Sources/Sentry/include/SentryContinuousProfiler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
* An interface to the new continuous profiling implementation.
*/
@interface SentryContinuousProfiler : NSObject

/** Start a continuous profiling session if one doesn't already exist. */
+ (void)start;

/** Stop a continuous profiling session if there is one ongoing. */
+ (void)stop;

@end

NS_ASSUME_NONNULL_END
15 changes: 15 additions & 0 deletions Sources/Sentry/include/SentrySDK+Private.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "SentryProfilingConditionals.h"
#import "SentrySDK.h"

@class SentryHub, SentryId, SentryAppStartMeasurement, SentryEnvelope;
Expand Down Expand Up @@ -42,6 +43,20 @@ SentrySDK ()
*/
+ (void)captureEnvelope:(SentryEnvelope *)envelope;

#if SENTRY_TARGET_PROFILING_SUPPORTED
/**
* Start a new continuous profiling session if one is not already running.
* @seealso https://docs.sentry.io/platforms/apple/profiling/
*/
+ (void)startProfiler;

/**
* Stop a continuous profiling session if there is one ongoing.
* @seealso https://docs.sentry.io/platforms/apple/profiling/
*/
+ (void)stopProfiler;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

@end

NS_ASSUME_NONNULL_END

0 comments on commit 192c140

Please sign in to comment.