Skip to content

Commit

Permalink
test: move the slow load test from SDK to sample app code (#3777)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Mar 21, 2024
1 parent fa409fe commit 742d4b6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 30 deletions.
12 changes: 10 additions & 2 deletions Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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, ); }; };
Expand Down Expand Up @@ -294,6 +295,8 @@
7B64386C26A6C544000D0F65 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7B79000329028C7300A7F467 /* MetricKitManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricKitManager.swift; sourceTree = "<group>"; };
7BFC8B0526D4D24B000D3504 /* LoremIpsum.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LoremIpsum.txt; sourceTree = "<group>"; };
8476702E2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSObject+SentryAppSetup.h"; sourceTree = "<group>"; };
8476702F2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSObject+SentryAppSetup.m"; sourceTree = "<group>"; };
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 = "<group>"; };
84A5D72529D2705000388BFA /* ProfilingUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilingUITests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -515,6 +518,8 @@
isa = PBXGroup;
children = (
84AB90702A5001000054C99A /* ProfilingViewController.swift */,
8476702E2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.h */,
8476702F2BAA4AFA001A4E31 /* NSObject+SentryAppSetup.m */,
84ACC4422A73CD0700932A18 /* ProfilingCPUWork.swift */,
84ACC43B2A73CB5900932A18 /* ProfilingNetworkScanner.swift */,
);
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions Samples/iOS-Swift/iOS-Swift/Profiling/NSObject+SentryAppSetup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import <Foundation/Foundation.h>

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
18 changes: 18 additions & 0 deletions Samples/iOS-Swift/iOS-Swift/Profiling/NSObject+SentryAppSetup.m
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Samples/iOS-Swift/iOS-SwiftUITests/ProfilingUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
27 changes: 0 additions & 27 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 742d4b6

Please sign in to comment.