From b35ccd01c17ade5cdac56961edf84abcd7566d69 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 5 Apr 2024 06:25:20 -0700 Subject: [PATCH] feat(profiling): add private feature flag for continuous mode (#3831) --- Sources/Sentry/SentryOptions.m | 4 ++++ .../Sentry/include/SentryOptions+Private.h | 1 + Tests/SentryTests/SentryOptionsTest.m | 21 ++++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Sources/Sentry/SentryOptions.m b/Sources/Sentry/SentryOptions.m index 635eb27f4b8..24640b20046 100644 --- a/Sources/Sentry/SentryOptions.m +++ b/Sources/Sentry/SentryOptions.m @@ -125,6 +125,7 @@ - (instancetype)init #if SENTRY_TARGET_PROFILING_SUPPORTED _enableProfiling = NO; self.profilesSampleRate = nil; + _enableContinuousProfiling = NO; #endif // SENTRY_TARGET_PROFILING_SUPPORTED self.enableCoreDataTracing = YES; _enableSwizzling = YES; @@ -472,6 +473,9 @@ - (BOOL)validateOptions:(NSDictionary *)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"] diff --git a/Sources/Sentry/include/SentryOptions+Private.h b/Sources/Sentry/include/SentryOptions+Private.h index ac3a47abef7..dc066d44e02 100644 --- a/Sources/Sentry/include/SentryOptions+Private.h +++ b/Sources/Sentry/include/SentryOptions+Private.h @@ -8,6 +8,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; #endif // SENTRY_TARGET_PROFILING_SUPPORTED SENTRY_EXTERN BOOL isValidSampleRate(NSNumber *sampleRate); diff --git a/Tests/SentryTests/SentryOptionsTest.m b/Tests/SentryTests/SentryOptionsTest.m index 98e57364ade..693a84ad9c8 100644 --- a/Tests/SentryTests/SentryOptionsTest.m +++ b/Tests/SentryTests/SentryOptionsTest.m @@ -647,6 +647,7 @@ - (void)assertDefaultValues:(SentryOptions *)options # pragma clang diagnostic pop XCTAssertNil(options.profilesSampleRate); XCTAssertNil(options.profilesSampler); + XCTAssertFalse(options.enableContinuousProfiling); #endif XCTAssertTrue([options.spotlightUrl isEqualToString:@"http://localhost:8969/stream"]); @@ -1005,17 +1006,20 @@ - (void)testEnableProfiling [self testBooleanField:@"enableProfiling" defaultValue:NO]; } +- (void)testEnableContinuousProfiling +{ + [self testBooleanField:@"enableContinuousProfiling" defaultValue:NO]; +} + - (void)testProfilesSampleRate { SentryOptions *options = [self getValidOptions:@{ @"profilesSampleRate" : @0.1 }]; - XCTAssertEqual(options.profilesSampleRate.doubleValue, 0.1); } - (void)testDefaultProfilesSampleRate { SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertEqual(options.profilesSampleRate.doubleValue, 0); } @@ -1063,6 +1067,7 @@ - (void)testIsProfilingEnabled_NothingSet_IsDisabled { SentryOptions *options = [[SentryOptions alloc] init]; XCTAssertFalse(options.isProfilingEnabled); + XCTAssertFalse(options.enableContinuousProfiling); } - (void)testIsProfilingEnabled_ProfilesSampleRateSetToZero_IsDisabled @@ -1070,6 +1075,7 @@ - (void)testIsProfilingEnabled_ProfilesSampleRateSetToZero_IsDisabled SentryOptions *options = [[SentryOptions alloc] init]; options.profilesSampleRate = @0.00; XCTAssertFalse(options.isProfilingEnabled); + XCTAssertFalse(options.enableContinuousProfiling); } - (void)testIsProfilingEnabled_ProfilesSampleRateSet_IsEnabled @@ -1077,6 +1083,7 @@ - (void)testIsProfilingEnabled_ProfilesSampleRateSet_IsEnabled SentryOptions *options = [[SentryOptions alloc] init]; options.profilesSampleRate = @0.01; XCTAssertTrue(options.isProfilingEnabled); + XCTAssertFalse(options.enableContinuousProfiling); } - (void)testIsProfilingEnabled_ProfilesSamplerSet_IsEnabled @@ -1087,6 +1094,7 @@ - (void)testIsProfilingEnabled_ProfilesSamplerSet_IsEnabled return @0.0; }; XCTAssertTrue(options.isProfilingEnabled); + XCTAssertFalse(options.enableContinuousProfiling); } - (void)testIsProfilingEnabled_EnableProfilingSet_IsEnabled @@ -1097,11 +1105,7 @@ - (void)testIsProfilingEnabled_EnableProfilingSet_IsEnabled options.enableProfiling = YES; # pragma clang diagnostic pop XCTAssertTrue(options.isProfilingEnabled); -} - -- (double)profilesSamplerCallback:(NSDictionary *)context -{ - return 0.1; + XCTAssertFalse(options.enableContinuousProfiling); } - (void)testProfilesSampler @@ -1115,6 +1119,7 @@ - (void)testProfilesSampler SentrySamplingContext *context = [[SentrySamplingContext alloc] init]; XCTAssertEqual(options.profilesSampler(context), @1.0); + XCTAssertFalse(options.enableContinuousProfiling); } - (void)testDefaultProfilesSampler @@ -1129,7 +1134,7 @@ - (void)testGarbageProfilesSampler_ReturnsNil XCTAssertNil(options.profilesSampler); } -#endif +#endif // SENTRY_TARGET_PROFILING_SUPPORTED - (void)testInAppIncludes {