Skip to content

Commit

Permalink
Merge 14f9505 into 97e82fe
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Jun 5, 2024
2 parents 97e82fe + 14f9505 commit 73665c4
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 142 deletions.
2 changes: 1 addition & 1 deletion Samples/iOS-Swift/iOS-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
options.enableTimeToFullDisplayTracing = true
options.enablePerformanceV2 = true
options.enableMetrics = true
options.enableContinuousProfiling = ProcessInfo.processInfo.arguments.contains("--io.sentry.enable-continuous-profiling")
options.profilesSampleRate = ProcessInfo.processInfo.arguments.contains("--io.sentry.enable-continuous-profiling") ? nil : 1

options.add(inAppInclude: "iOS_External")

Expand Down
8 changes: 4 additions & 4 deletions Sources/Sentry/Profiling/SentryLaunchProfiling.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
SentryLaunchProfileConfig
sentry_shouldProfileNextLaunch(SentryOptions *options)
{
if (options.enableAppLaunchProfiling && options.enableContinuousProfiling) {
if (options.enableAppLaunchProfiling && [options isContinuousProfilingEnabled]) {
return (SentryLaunchProfileConfig) { YES, nil, nil };
}

Expand Down Expand Up @@ -174,14 +174,14 @@

NSMutableDictionary<NSString *, NSNumber *> *configDict =
[NSMutableDictionary<NSString *, NSNumber *> dictionary];
if (options.enableContinuousProfiling) {
if ([options isContinuousProfilingEnabled]) {
configDict[kSentryLaunchProfileConfigKeyContinuousProfiling] = @YES;
} else {
configDict[kSentryLaunchProfileConfigKeyTracesSampleRate]
= config.tracesDecision.sampleRate;
configDict[kSentryLaunchProfileConfigKeyProfilesSampleRate]
= config.profilesDecision.sampleRate;
}
configDict[kSentryLaunchProfileConfigKeyProfilesSampleRate]
= config.profilesDecision.sampleRate;
writeAppLaunchProfilingConfigFile(configDict);
}];
}
Expand Down
19 changes: 16 additions & 3 deletions Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,17 @@ NS_SWIFT_NAME(Options)
* the SDK sets it to the default of @c 0.
* This property is dependent on @c tracesSampleRate -- if @c tracesSampleRate is @c 0 (default),
* no profiles will be collected no matter what this property is set to. This property is
* used to undersample profiles *relative to* @c tracesSampleRate
* used to undersample profiles *relative to* @c tracesSampleRate .
* @note Setting this value to @c nil enables an experimental new profiling mode, called continuous
* profiling. This allows you to start and stop a profiler any time with @c SentrySDK.startProfiler
* and @c SentrySDK.stopProfiler, which can run with no time limit, periodically uploading profiling
* data. You can also set @c SentryOptions.enableAppLaunchProfiling to have the profiler start on
* app launch; there is no automatic stop, you must stop it manually at some later time if you
* choose to do so. Sampling rates do not apply to continuous profiles, including those
* automatically started for app launches. If you wish to sample them, you must do so at the
* callsites where you use the API or configure launch profiling. Continuous profiling is not
* automatically started for performance transactions as was the previous version of profiling.
* @warning The new continuous profiling mode is experimental and may still contain bugs.
*/
@property (nullable, nonatomic, strong) NSNumber *profilesSampleRate;

Expand All @@ -474,8 +484,11 @@ NS_SWIFT_NAME(Options)
/**
* If profiling should be enabled or not.
* @note Profiling is not supported on watchOS or tvOS.
* @returns @c YES if either a profilesSampleRate > @c 0 and \<= @c 1 or a profilesSampler is set,
* otherwise @c NO.
* @note This only returns whether or not trace-based profiling is enabled. If it is not, then
* continuous profiling is effectively enabled, and calling SentrySDK.startProfiler will
* successfully start a continuous profile.
* @returns @c YES if either @c profilesSampleRate > @c 0 and \<= @c 1 , or @c profilesSampler is
* set, otherwise @c NO.
*/
@property (nonatomic, assign, readonly) BOOL isProfilingEnabled;

Expand Down
19 changes: 13 additions & 6 deletions Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ - (instancetype)init
self.tracesSampleRate = nil;
#if SENTRY_TARGET_PROFILING_SUPPORTED
_enableProfiling = NO;
self.profilesSampleRate = nil;
_enableContinuousProfiling = NO;
self.profilesSampleRate = SENTRY_DEFAULT_PROFILES_SAMPLE_RATE;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
self.enableCoreDataTracing = YES;
_enableSwizzling = YES;
Expand Down Expand Up @@ -495,9 +494,6 @@ - (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options

[self setBool:options[NSStringFromSelector(@selector(enableAppLaunchProfiling))]
block:^(BOOL value) { self->_enableAppLaunchProfiling = value; }];

[self setBool:options[@"enableContinuousProfiling"]
block:^(BOOL value) { self->_enableContinuousProfiling = value; }];
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

[self setBool:options[@"sendClientReports"]
Expand Down Expand Up @@ -647,18 +643,29 @@ - (BOOL)isProfilingEnabled
|| _profilesSampler != nil || _enableProfiling;
}

- (BOOL)isContinuousProfilingEnabled
{
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
return _profilesSampleRate.doubleValue == 0 && _profilesSampler == nil && !self.enableProfiling;
# pragma clang diagnostic pop
}

- (void)setEnableProfiling_DEPRECATED_TEST_ONLY:(BOOL)enableProfiling_DEPRECATED_TEST_ONLY
{
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
self.enableProfiling = enableProfiling_DEPRECATED_TEST_ONLY;
# pragma clang diagnostic pop
}

- (BOOL)enableProfiling_DEPRECATED_TEST_ONLY
{
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
return self.enableProfiling;
}
# pragma clang diagnostic pop
}
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

/**
Expand Down
8 changes: 7 additions & 1 deletion Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
sentry_manageTraceProfilerOnStartSDK(SentryOptions *options, SentryHub *hub)
{
[SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchAsyncWithBlock:^{
BOOL shouldStopAndTransmitLaunchProfile = !options.enableContinuousProfiling;
BOOL shouldStopAndTransmitLaunchProfile = options.profilesSampleRate != nil;
# if SENTRY_HAS_UIKIT
if (SentryUIViewControllerPerformanceTracker.shared.enableWaitForFullDisplay) {
shouldStopAndTransmitLaunchProfile = NO;
Expand All @@ -61,6 +61,12 @@ @implementation SentryProfiler {

+ (void)load
{
# if !defined(TEST) && !defined(TESTCI)
// we want to allow starting a launch profile from here for UI tests, but not unit tests
if (NSProcessInfo.processInfo.environment[@"io.sentry.ui-test.test-name"] == nil) {
return;
}
# endif // !defined(TEST) && !defined(TESTCI)
sentry_startLaunchProfile();
}

Expand Down
14 changes: 8 additions & 6 deletions Sources/Sentry/SentrySDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,10 @@ + (void)crash
#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.")) {
if (![currentHub.client.options isContinuousProfilingEnabled]) {
SENTRY_LOG_WARN(
@"You must disable trace profiling by setting SentryOptions.profilesSampleRate to nil "
@"or 0 before using continuous profiling features.");
return;
}

Expand All @@ -539,9 +540,10 @@ + (void)startProfiler

+ (void)stopProfiler
{
if (!SENTRY_ASSERT_RETURN(currentHub.client.options.enableContinuousProfiling,
@"You must set SentryOptions.enableContinuousProfiling to true before using continuous "
@"profiling API.")) {
if (![currentHub.client.options isContinuousProfilingEnabled]) {
SENTRY_LOG_WARN(
@"You must disable trace profiling by setting SentryOptions.profilesSampleRate to nil "
@"or 0 before using continuous profiling features.");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ - (instancetype)initWithContext:(SentrySpanContext *)context
_origin = context.origin;

#if SENTRY_TARGET_PROFILING_SUPPORTED
_isContinuousProfiling = SentrySDK.options.enableContinuousProfiling;
_isContinuousProfiling = [SentrySDK.options isContinuousProfilingEnabled];
if (_isContinuousProfiling) {
_profileSessionID = SentryContinuousProfiler.currentProfilerID.sentryIdString;
if (_profileSessionID == nil) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryTimeToDisplayTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ - (void)framesTrackerHasNewFrame:(NSDate *)newFrameDate
if (!_waitForFullDisplay) {
[SentryDependencyContainer.sharedInstance.framesTracker removeListener:self];
# if SENTRY_TARGET_PROFILING_SUPPORTED
if (!SentrySDK.options.enableContinuousProfiling) {
if (SentrySDK.options.profilesSampleRate != nil) {
sentry_stopAndDiscardLaunchProfileTracer();
}
# endif // SENTRY_TARGET_PROFILING_SUPPORTED
Expand All @@ -154,7 +154,7 @@ - (void)framesTrackerHasNewFrame:(NSDate *)newFrameDate
self.fullDisplaySpan.timestamp = newFrameDate;
[self.fullDisplaySpan finish];
# if SENTRY_TARGET_PROFILING_SUPPORTED
if (!SentrySDK.options.enableContinuousProfiling) {
if (SentrySDK.options.profilesSampleRate != nil) {
sentry_stopAndDiscardLaunchProfileTracer();
}
# endif // SENTRY_TARGET_PROFILING_SUPPORTED
Expand Down
8 changes: 5 additions & 3 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti
#endif // SENTRY_HAS_UIKIT

#if SENTRY_TARGET_PROFILING_SUPPORTED
if (!hub.client.options.enableContinuousProfiling
&& (_configuration.profilesSamplerDecision.decision == kSentrySampleDecisionYes
|| sentry_isTracingAppLaunch)) {
BOOL profileShouldBeSampled
= _configuration.profilesSamplerDecision.decision == kSentrySampleDecisionYes;
BOOL isContinuousProfiling = [hub.client.options isContinuousProfilingEnabled];
BOOL shouldStartNormalTraceProfile = !isContinuousProfiling && profileShouldBeSampled;
if (sentry_isTracingAppLaunch || shouldStartNormalTraceProfile) {
_internalID = [[SentryId alloc] init];
if ((_isProfiling = [SentryTraceProfiler startWithTracer:_internalID])) {
SENTRY_LOG_DEBUG(@"Started profiler for trace %@ with internal id %@",
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryOptions+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ FOUNDATION_EXPORT NSString *const kSentryDefaultEnvironment;
SentryOptions ()
#if SENTRY_TARGET_PROFILING_SUPPORTED
@property (nonatomic, assign) BOOL enableProfiling_DEPRECATED_TEST_ONLY;
@property (nonatomic, assign) BOOL enableContinuousProfiling;
- (BOOL)isContinuousProfilingEnabled;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

SENTRY_EXTERN BOOL sentry_isValidSampleRate(NSNumber *sampleRate);
Expand Down
Loading

0 comments on commit 73665c4

Please sign in to comment.