diff --git a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj index 7aceb4fb41b..a4ccdc65ef4 100644 --- a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj +++ b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ 7BFC8B0626D4D24B000D3504 /* LoremIpsum.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7BFC8B0526D4D24B000D3504 /* LoremIpsum.txt */; }; 844DA821282584C300E6B62E /* CoreDataViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F57BC427BBD787000D09D4 /* CoreDataViewController.swift */; }; 844DA822282584F700E6B62E /* SentryData.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = D845F35927BAD4CC00A4D7A2 /* SentryData.xcdatamodeld */; }; + 847670302BAA4AFA001A4E31 /* NSObject+SentryAppSetup.m in Sources */ = {isa = PBXBuildFile; fileRef = 8476702F2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.m */; }; 848A256B286E3351008A8858 /* Sentry.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 630853322440C44F00DDE4CE /* Sentry.framework */; }; 848A256D286E3351008A8858 /* fatal-error-binary-images-message2.json in Resources */ = {isa = PBXBuildFile; fileRef = D83A30DF279F1F5C00372D0A /* fatal-error-binary-images-message2.json */; }; 848A256F286E3351008A8858 /* Sentry.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 630853322440C44F00DDE4CE /* Sentry.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; @@ -294,6 +295,8 @@ 7B64386C26A6C544000D0F65 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7B79000329028C7300A7F467 /* MetricKitManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricKitManager.swift; sourceTree = ""; }; 7BFC8B0526D4D24B000D3504 /* LoremIpsum.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LoremIpsum.txt; sourceTree = ""; }; + 8476702E2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSObject+SentryAppSetup.h"; sourceTree = ""; }; + 8476702F2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSObject+SentryAppSetup.m"; sourceTree = ""; }; 848A2573286E3351008A8858 /* PerformanceBenchmarks.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PerformanceBenchmarks.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 848A2578286E3490008A8858 /* PerformanceBenchmarks-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PerformanceBenchmarks-Info.plist"; sourceTree = ""; }; 84A5D72529D2705000388BFA /* ProfilingUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilingUITests.swift; sourceTree = ""; }; @@ -515,6 +518,8 @@ isa = PBXGroup; children = ( 84AB90702A5001000054C99A /* ProfilingViewController.swift */, + 8476702E2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.h */, + 8476702F2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.m */, 84ACC4422A73CD0700932A18 /* ProfilingCPUWork.swift */, 84ACC43B2A73CB5900932A18 /* ProfilingNetworkScanner.swift */, ); @@ -931,6 +936,7 @@ 84AB90712A5001000054C99A /* ProfilingViewController.swift in Sources */, 84FB812A284001B800F3A94A /* SentryBenchmarking.mm in Sources */, 84ACC4432A73CD0700932A18 /* ProfilingCPUWork.swift in Sources */, + 847670302BAA4AFA001A4E31 /* NSObject+SentryAppSetup.m in Sources */, D8F3D052274E572F00B56F8C /* DSNStorage.swift in Sources */, D8F3D054274E572F00B56F8C /* RandomErrors.swift in Sources */, D80D021329EE93630084393D /* ErrorsViewController.swift in Sources */, @@ -1417,6 +1423,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = "TEST=1"; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; @@ -1430,7 +1437,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; VALIDATE_PRODUCT = YES; }; name = Test; @@ -1641,6 +1648,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = "TESTCI=1"; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; @@ -1654,7 +1662,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; VALIDATE_PRODUCT = YES; }; name = TestCI; diff --git a/Samples/iOS-Swift/iOS-Swift/Profiling/NSObject+SentryAppSetup.h b/Samples/iOS-Swift/iOS-Swift/Profiling/NSObject+SentryAppSetup.h new file mode 100644 index 00000000000..d6f76c862d4 --- /dev/null +++ b/Samples/iOS-Swift/iOS-Swift/Profiling/NSObject+SentryAppSetup.h @@ -0,0 +1,16 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * A category that overrides its `+[load]` method to deliberately take a long time to run, so we can + * see it show up in profile stack traces. Categories' `+[load]` methods are guaranteed to be called + * after all of a module's normal class' overrides, so we can be confident the ordering will always + * have started the launch profiler by the time this runs. This must be done in Objective-C because + * Swift does not allow implementation of `NSObject.load()`. + */ +@interface +NSObject (SentryAppSetup) +@end + +NS_ASSUME_NONNULL_END diff --git a/Samples/iOS-Swift/iOS-Swift/Profiling/NSObject+SentryAppSetup.m b/Samples/iOS-Swift/iOS-Swift/Profiling/NSObject+SentryAppSetup.m new file mode 100644 index 00000000000..e45734dccc3 --- /dev/null +++ b/Samples/iOS-Swift/iOS-Swift/Profiling/NSObject+SentryAppSetup.m @@ -0,0 +1,18 @@ +#import "NSObject+SentryAppSetup.h" + +@implementation +NSObject (SentryAppSetup) ++ (void)load +{ + NSLog(@"[iOS-Swift] Starting app launch work"); + if ([NSProcessInfo.processInfo.arguments containsObject:@"--io.sentry.slow-load-method"]) { + NSMutableString *a = [NSMutableString string]; + // 1,000,000 iterations takes about 225 milliseconds in the iPhone 15 simulator on an + // M2 macbook pro; we might have to adapt this for CI + for (NSUInteger i = 0; i < 4000000; i++) { + [a appendFormat:@"%d", arc4random() % 12345]; + } + } + NSLog(@"[iOS-Swift] Finishing app launch work"); +} +@end diff --git a/Samples/iOS-Swift/iOS-SwiftUITests/ProfilingUITests.swift b/Samples/iOS-Swift/iOS-SwiftUITests/ProfilingUITests.swift index 052238be9a8..8b5f31bb903 100644 --- a/Samples/iOS-Swift/iOS-SwiftUITests/ProfilingUITests.swift +++ b/Samples/iOS-Swift/iOS-SwiftUITests/ProfilingUITests.swift @@ -135,7 +135,7 @@ extension ProfilingUITests { var stackID: Int? let stack = try XCTUnwrap(stackFunctions.enumerated().first { nextStack in let result = nextStack.element.contains { frame in - let result = (frame as! String).contains("+[SentryProfiler(SlowLoad) load]") + let result = (frame as! String).contains("+[NSObject(SentryAppSetup) load]") if result { stackID = nextStack.offset } diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 419d1f021ea..51f0f1a16e7 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -54,33 +54,6 @@ # import "SentryFileManager.h" # import "SentryInternalDefines.h" # import "SentryLaunchProfiling.h" - -/** - * A category that overrides its `+[load]` method to deliberately take a long time to run, so we can - * see it show up in profile stack traces. Categories' `+[load]` methods are guaranteed to be called - * after all of a module's normal class' overrides, so we can be confident the ordering will always - * have started the launch profiler by the time this runs. - */ -@interface -SentryProfiler (SlowLoad) -@end - -@implementation -SentryProfiler (SlowLoad) -+ (void)load -{ - SENTRY_LOG_DEBUG(@"Starting slow load method"); - if ([NSProcessInfo.processInfo.arguments containsObject:@"--io.sentry.slow-load-method"]) { - NSMutableString *a = [NSMutableString string]; - // 1,000,000 iterations takes about 225 milliseconds in the iPhone 15 simulator on an - // M2 macbook pro; we might have to adapt this for CI - for (NSUInteger i = 0; i < 4000000; i++) { - [a appendFormat:@"%d", arc4random() % 12345]; - } - } - SENTRY_LOG_DEBUG(@"Finishing slow load method"); -} -@end # endif // defined(TEST) || defined(TESTCI) || defined(DEBUG) const int kSentryProfilerFrequencyHz = 101;