Skip to content

Commit

Permalink
ref: compile out more code from platforms without profiling (#3159)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Jul 18, 2023
1 parent 6604dbb commit 84fb4d9
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Improvements

- Reduced macOS SDK footprint by 2% (#3157)
- Reduced macOS SDK footprint by 2% (#3157) with similar changes for tvOS and watchOS (#3158, #3159, #3161)

### Fixes

Expand Down
2 changes: 1 addition & 1 deletion Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@
035E73CD27D5790A005EEB11 /* SentryThreadMetadataCacheTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryThreadMetadataCacheTests.mm; sourceTree = "<group>"; };
03BCC38927E1BF49003232C7 /* SentryTime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTime.h; path = Sources/Sentry/include/SentryTime.h; sourceTree = SOURCE_ROOT; };
03BCC38B27E1C01A003232C7 /* SentryTime.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = SentryTime.mm; path = Sources/Sentry/SentryTime.mm; sourceTree = SOURCE_ROOT; };
03BCC38D27E2A377003232C7 /* SentryProfilingConditionals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryProfilingConditionals.h; path = Sources/Sentry/Public/SentryProfilingConditionals.h; sourceTree = SOURCE_ROOT; };
03BCC38D27E2A377003232C7 /* SentryProfilingConditionals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryProfilingConditionals.h; path = ../Public/SentryProfilingConditionals.h; sourceTree = "<group>"; };
03F84D1127DD414C008FE43F /* SentryProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryProfiler.h; path = Sources/Sentry/include/SentryProfiler.h; sourceTree = SOURCE_ROOT; };
03F84D1227DD414C008FE43F /* SentryBacktrace.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = SentryBacktrace.hpp; path = Sources/Sentry/include/SentryBacktrace.hpp; sourceTree = SOURCE_ROOT; };
03F84D1327DD414C008FE43F /* SentryAsyncSafeLogging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryAsyncSafeLogging.h; path = Sources/Sentry/include/SentryAsyncSafeLogging.h; sourceTree = SOURCE_ROOT; };
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ NS_SWIFT_NAME(Options)
@property (nonatomic, assign) BOOL enableProfiling DEPRECATED_MSG_ATTRIBUTE(
"Use profilesSampleRate or profilesSampler instead. This property will be removed in a future "
"version of the SDK");
#endif
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

/**
* Whether to send client reports, which contain statistics about discarded events.
Expand Down
14 changes: 11 additions & 3 deletions Sources/Sentry/SentryHub.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "SentryLog.h"
#import "SentryNSTimerFactory.h"
#import "SentryPerformanceTracker.h"
#import "SentryProfilesSampler.h"
#import "SentryProfilingConditionals.h"
#import "SentrySDK+Private.h"
#import "SentrySamplingContext.h"
#import "SentryScope+Private.h"
Expand All @@ -28,6 +28,10 @@
# import "SentryUIViewControllerPerformanceTracker.h"
#endif // SENTRY_HAS_UIKIT

#if SENTRY_TARGET_PROFILING_SUPPORTED
# import "SentryProfilesSampler.h"
#endif // SENTRY_TARGET_PROFILING_SUPPORTED"

NS_ASSUME_NONNULL_BEGIN

@interface
Expand All @@ -38,7 +42,9 @@
@property (nullable, nonatomic, strong) SentryScope *scope;
@property (nonatomic, strong) SentryCrashWrapper *crashWrapper;
@property (nonatomic, strong) SentryTracesSampler *tracesSampler;
#if SENTRY_TARGET_PROFILING_SUPPORTED
@property (nonatomic, strong) SentryProfilesSampler *profilesSampler;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
@property (nonatomic, strong) NSMutableArray<id<SentryIntegrationProtocol>> *installedIntegrations;
@property (nonatomic, strong) NSMutableSet<NSString *> *installedIntegrationNames;
@property (nonatomic) NSUInteger errorsBeforeSession;
Expand Down Expand Up @@ -67,7 +73,7 @@ - (instancetype)initWithClient:(nullable SentryClient *)client
if (client.options.isProfilingEnabled) {
_profilesSampler = [[SentryProfilesSampler alloc] initWithOptions:client.options];
}
#endif
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
}
return self;
}
Expand Down Expand Up @@ -382,10 +388,12 @@ - (SentryTracer *)startTransactionWithContext:(SentryTransactionContext *)transa
withSampled:samplerDecision.decision];
transactionContext.sampleRate = samplerDecision.sampleRate;

#if SENTRY_TARGET_PROFILING_SUPPORTED
SentryProfilesSamplerDecision *profilesSamplerDecision =
[_profilesSampler sample:samplingContext tracesSamplerDecision:samplerDecision];

configuration.profilesSamplerDecision = profilesSamplerDecision;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED"

SentryTracer *tracer = [[SentryTracer alloc] initWithTransactionContext:transactionContext
hub:self
Expand Down Expand Up @@ -660,7 +668,7 @@ - (void)reportFullyDisplayed
} else {
SENTRY_LOG_DEBUG(@"The options `enableTimeToFullDisplay` is disabled.");
}
#endif
#endif // SENTRY_HAS_UIKIT
}

- (void)flush:(NSTimeInterval)timeout
Expand Down
1 change: 0 additions & 1 deletion Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#import "SentryLevelMapper.h"
#import "SentryLog.h"
#import "SentryMeta.h"
#import "SentryMetricKitIntegration.h"
#import "SentryNetworkTrackingIntegration.h"
#import "SentrySDK.h"
#import "SentryScope.h"
Expand Down
13 changes: 8 additions & 5 deletions Sources/Sentry/SentryProfilesSampler.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#import "SentryProfilesSampler.h"
#import "SentryDependencyContainer.h"
#import "SentryOptions+Private.h"
#import "SentryTracesSampler.h"

#if SENTRY_TARGET_PROFILING_SUPPORTED

# import "SentryDependencyContainer.h"
# import "SentryOptions+Private.h"
# import "SentryTracesSampler.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -43,7 +46,6 @@ - (SentryProfilesSamplerDecision *)sample:(SentrySamplingContext *)context
// Profiles are always undersampled with respect to traces. If the trace is not sampled,
// the profile will not be either. If the trace is sampled, we can proceed to checking
// whether the associated profile should be sampled.
#if SENTRY_TARGET_PROFILING_SUPPORTED
if (tracesSamplerDecision.decision == kSentrySampleDecisionYes) {
if (_options.profilesSampler != nil) {
NSNumber *callbackDecision = _options.profilesSampler(context);
Expand All @@ -70,7 +72,6 @@ - (SentryProfilesSamplerDecision *)sample:(SentrySamplingContext *)context
}
# pragma clang diagnostic pop
}
#endif

return [[SentryProfilesSamplerDecision alloc] initWithDecision:kSentrySampleDecisionNo
forSampleRate:nil];
Expand All @@ -88,3 +89,5 @@ - (SentryProfilesSamplerDecision *)calcSample:(double)rate
@end

NS_ASSUME_NONNULL_END

#endif // SENTRY_TARGET_PROFILING_SUPPORTED
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#import "SentryLog.h"
#import "SentryNSTimerFactory.h"
#import "SentryNoOpSpan.h"
#import "SentryProfilesSampler.h"
#import "SentryProfilingConditionals.h"
#import "SentrySDK+Private.h"
#import "SentryScope.h"
Expand All @@ -32,6 +31,7 @@
#if SENTRY_TARGET_PROFILING_SUPPORTED
# import "SentryProfiledTracerConcurrency.h"
# import "SentryProfiler.h"
# import "SentryProfilesSampler.h"
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

#if SENTRY_HAS_UIKIT
Expand Down
12 changes: 9 additions & 3 deletions Sources/Sentry/include/SentryProfilesSampler.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#import "SentryRandom.h"
#import "SentrySampleDecision.h"
#import <Foundation/Foundation.h>
#import "SentryProfilingConditionals.h"

#if SENTRY_TARGET_PROFILING_SUPPORTED

# import "SentryRandom.h"
# import "SentrySampleDecision.h"
# import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -47,3 +51,5 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif // SENTRY_TARGET_PROFILING_SUPPORTED
8 changes: 8 additions & 0 deletions Sources/Sentry/include/SentryTracerConfiguration.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#if __has_include(<Sentry/PrivatesHeader.h>)
# import <Sentry/PrivatesHeader.h>
#else
# import "PrivatesHeader.h"
#endif

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -25,10 +31,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, strong, nullable) SentryDispatchQueueWrapper *dispatchQueueWrapper;

#if SENTRY_TARGET_PROFILING_SUPPORTED
/**
* Whether to sample a profile corresponding to this transaction
*/
@property (nonatomic, strong, nullable) SentryProfilesSamplerDecision *profilesSamplerDecision;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED"

/**
* The idle time to wait until to finish the transaction
Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/SentrySDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ class SentrySDKTests: XCTestCase {
queue1.activate()
queue2.activate()
group.waitWithTimeout(timeout: 100)

let timestamp = SentryDependencyContainer.sharedInstance().dateProvider.date().addingTimeInterval(TimeInterval(amount))
XCTAssertEqual(timestamp, SentrySDK.getAppStartMeasurement()?.appStartTimestamp)
}
Expand Down
1 change: 0 additions & 1 deletion Tests/SentryTests/SentryTests-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#import "SentryConcurrentRateLimitsDictionary.h"
#import "SentryCoreDataSwizzling.h"
#import "SentryCoreDataTracker+Test.h"
#import "SentryCoreDataTracker.h"
#import "SentryCoreDataTrackingIntegration.h"
#import "SentryCrashBinaryImageProvider.h"
#import "SentryCrashC.h"
Expand Down
7 changes: 5 additions & 2 deletions Tests/SentryTests/Transaction/SentryTracerObjCTests.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#import "SentryClient.h"
#import "SentryHub.h"
#import "SentryOptions.h"
#import "SentryProfiler.h"
#import "SentryProfilesSampler.h"
#import "SentryProfilingConditionals.h"
#import "SentrySpan.h"
#import "SentryTests-Swift.h"
#import "SentryTracer.h"
#import "SentryTransactionContext.h"
#import <XCTest/XCTest.h>

#if SENTRY_TARGET_PROFILING_SUPPORTED
# import "SentryProfiler.h"
# import "SentryProfilesSampler.h"
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

@interface SentryTracerObjCTests : XCTestCase

@end
Expand Down

0 comments on commit 84fb4d9

Please sign in to comment.