Skip to content

Commit

Permalink
wip integration test for launch profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Jan 3, 2024
1 parent 65f31c9 commit 655b9d3
Show file tree
Hide file tree
Showing 10 changed files with 407 additions and 186 deletions.
4 changes: 0 additions & 4 deletions Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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 */; };
846B99712B2936EA00A8C36B /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846B99702B2936EA00A8C36B /* Helpers.swift */; };
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 @@ -302,7 +301,6 @@
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>"; };
846B99702B2936EA00A8C36B /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; 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 @@ -478,7 +476,6 @@
63F93AA9245AC91600A500DB /* iOS-Swift.entitlements */,
637AFDA9243B02760034958B /* AppDelegate.swift */,
637AFDAD243B02760034958B /* TransactionsViewController.swift */,
846B99702B2936EA00A8C36B /* Helpers.swift */,
84AB90782A50031B0054C99A /* Profiling */,
D80D021229EE93630084393D /* ErrorsViewController.swift */,
D80D021929EE936F0084393D /* ExtraViewController.swift */,
Expand Down Expand Up @@ -932,7 +929,6 @@
D8F3D05F274E6A8B00B56F8C /* AssertView.swift in Sources */,
D890CD3F26CEE31B001246CF /* NibViewController.swift in Sources */,
D845F35B27BAD4CC00A4D7A2 /* SentryData.xcdatamodeld in Sources */,
846B99712B2936EA00A8C36B /* Helpers.swift in Sources */,
D8444E4C275E38090042F4DE /* UIViewControllerExtension.swift in Sources */,
637AFDAE243B02760034958B /* TransactionsViewController.swift in Sources */,
D8832B132AF4F7FE00C522B0 /* TopViewControllerInspector.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,28 @@
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable
key = "--io.sentry.tracesSampleRate"
value = ""
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "--io.sentry.profilesSampleRate"
value = ""
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "--io.sentry.tracesSamplerValue"
value = ""
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "--io.sentry.profilesSamplerValue"
value = ""
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
80 changes: 62 additions & 18 deletions Samples/iOS-Swift/iOS-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return event
}
options.debug = true

if #available(iOS 15.0, *) {
options.enableMetricKit = true
}
// Sampling 100% - In Production you probably want to adjust this
let tracesSampleRateOverride = ProcessInfo.processInfo.environment["--io.sentry.test.tracesSampleRate"]
options.tracesSampleRate = NSNumber(value: (tracesSampleRateOverride as? NSString)?.integerValue ?? 1)
let profilesSampleRateOverride = ProcessInfo.processInfo.environment["--io.sentry.test.profilesSampleRate"]
options.profilesSampleRate = NSNumber(value: (profilesSampleRateOverride as? NSString)?.integerValue ?? 1)
options.profileAppLaunches = ProcessInfo.processInfo.arguments.contains("io.sentry.test.profilesAppLaunches")

let args = ProcessInfo.processInfo.arguments
let env = ProcessInfo.processInfo.environment

var tracesSampleRate: NSNumber = 1
if let tracesSampleRateOverride = env["--io.sentry.tracesSampleRate"] {
tracesSampleRate = NSNumber(value: (tracesSampleRateOverride as NSString).integerValue)
}
options.tracesSampleRate = tracesSampleRate

if let tracesSamplerValue = env["--io.sentry.tracersSamplerValue"] {
options.tracesSampler = { _ in
return NSNumber(value: (tracesSamplerValue as NSString).integerValue)
}
}

var profilesSampleRate: NSNumber = 1
if let profilesSampleRateOverride = env["--io.sentry.profilesSampleRate"] {
profilesSampleRate = NSNumber(value: (profilesSampleRateOverride as NSString).integerValue)
}
options.profilesSampleRate = profilesSampleRate

if let profilesSamplerValue = env["--io.sentry.profilesSamplerValue"] {
options.profilesSampler = { _ in
return NSNumber(value: (profilesSamplerValue as NSString).integerValue)
}
}

options.profileAppLaunches = args.contains("--io.sentry.test.profilesAppLaunches")

options.sessionTrackingIntervalMillis = 5_000
options.attachScreenshot = true
options.attachViewHierarchy = true
Expand All @@ -37,24 +62,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

options.add(inAppInclude: "iOS_External")

let isBenchmarking = ProcessInfo.processInfo.arguments.contains("--io.sentry.test.benchmarking")
let isBenchmarking = args.contains("--io.sentry.test.benchmarking")

// the benchmark test starts and stops a custom transaction using a UIButton, and automatic user interaction tracing stops the transaction that begins with that button press after the idle timeout elapses, stopping the profiler (only one profiler runs regardless of the number of concurrent transactions)
options.enableUserInteractionTracing = !isBenchmarking && !ProcessInfo.processInfo.arguments.contains("--disable-ui-tracing")
options.enableAutoPerformanceTracing = !isBenchmarking && !ProcessInfo.processInfo.arguments.contains("--disable-auto-performance-tracing")
options.enableUserInteractionTracing = !isBenchmarking && !args.contains("--disable-ui-tracing")
options.enableAutoPerformanceTracing = !isBenchmarking && !args.contains("--disable-auto-performance-tracing")
options.enablePreWarmedAppStartTracing = !isBenchmarking

options.enableFileIOTracing = !ProcessInfo.processInfo.arguments.contains("--disable-file-io-tracing")
options.enableAutoBreadcrumbTracking = !ProcessInfo.processInfo.arguments.contains("--disable-automatic-breadcrumbs")
options.enableUIViewControllerTracing = !ProcessInfo.processInfo.arguments.contains("--disable-uiviewcontroller-tracing")
options.enableNetworkTracking = !ProcessInfo.processInfo.arguments.contains("--disable-network-tracking")
options.enableCoreDataTracing = !ProcessInfo.processInfo.arguments.contains("--disable-core-data-tracing")
options.enableNetworkBreadcrumbs = !ProcessInfo.processInfo.arguments.contains("--disable-network-breadcrumbs")
options.enableSwizzling = !ProcessInfo.processInfo.arguments.contains("--disable-swizzling")
options.enableCrashHandler = !ProcessInfo.processInfo.arguments.contains("--disable-crash-handler")
options.enableFileIOTracing = !args.contains("--disable-file-io-tracing")
options.enableAutoBreadcrumbTracking = !args.contains("--disable-automatic-breadcrumbs")
options.enableUIViewControllerTracing = !args.contains("--disable-uiviewcontroller-tracing")
options.enableNetworkTracking = !args.contains("--disable-network-tracking")
options.enableCoreDataTracing = !args.contains("--disable-core-data-tracing")
options.enableNetworkBreadcrumbs = !args.contains("--disable-network-breadcrumbs")
options.enableSwizzling = !args.contains("--disable-swizzling")
options.enableCrashHandler = !args.contains("--disable-crash-handler")

// because we run CPU for 15 seconds at full throttle, we trigger ANR issues being sent. disable such during benchmarks.
options.enableAppHangTracking = !isBenchmarking && !ProcessInfo.processInfo.arguments.contains("--disable-anr-tracking")
options.enableAppHangTracking = !isBenchmarking && !args.contains("--disable-anr-tracking")
options.appHangTimeoutInterval = 2
options.enableCaptureFailedRequests = true
let httpStatusCodeRange = HttpStatusCodeRange(min: 400, max: 599)
Expand Down Expand Up @@ -88,6 +113,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

print("[iOS-Swift] launch arguments: \(ProcessInfo.processInfo.arguments)")
print("[iOS-Swift] environment: \(ProcessInfo.processInfo.environment)")

maybeWipeData()
AppDelegate.startSentry()

if #available(iOS 15.0, *) {
Expand Down Expand Up @@ -117,3 +146,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// swiftlint:enable force_cast
}
}

private extension AppDelegate {
func maybeWipeData() {
if ProcessInfo.processInfo.arguments.contains("--io.sentry.wipe-data") {
print("[iOS-Swift] removing app data")
let appSupport = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!
let cache = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!
for path in [appSupport, cache] {
for item in FileManager.default.enumerator(atPath: path)! {
try! FileManager.default.removeItem(atPath: (path as NSString).appendingPathComponent((item as! String)))
}
}
}
}
}
32 changes: 28 additions & 4 deletions Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="jya-5z-xKN">
<rect key="frame" x="0.0" y="64" width="320" height="140"/>
<rect key="frame" x="0.0" y="64" width="320" height="190"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="DOu-47-e6X">
<rect key="frame" x="93" y="0.0" width="134" height="28"/>
Expand Down Expand Up @@ -250,16 +250,38 @@
<action selector="deleteLastProfile:" destination="NZr-bH-g9o" eventType="touchUpInside" id="HDR-II-RdE"/>
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="LIr-jM-FSX">
<rect key="frame" x="19" y="140" width="282" height="50"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="UI test data marshalling:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Uhg-B3-Rao" userLabel="UI test data marshaling:">
<rect key="frame" x="0.0" y="15" width="184" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="5zI-Ix-rMJ">
<rect key="frame" x="192" y="8" width="32" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2LR-W8-mNE" userLabel="Profiling UI Test Data Marshaling status">
<rect key="frame" x="232" y="0.0" width="50" height="50"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<textField hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="uTM-T7-Gv6">
<rect key="frame" x="0.0" y="140" width="320" height="0.0"/>
<rect key="frame" x="0.0" y="190" width="320" height="0.0"/>
<accessibility key="accessibilityConfiguration" identifier="io.sentry.benchmark.value-marshaling-text-field"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="hFG-bX-qLp">
<rect key="frame" x="10" y="258" width="300" height="159.5"/>
<rect key="frame" x="10" y="308" width="300" height="159.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Work threads:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="t2C-jL-6qO">
<rect key="frame" x="97" y="0.0" width="106.5" height="20.5"/>
Expand Down Expand Up @@ -373,6 +395,8 @@
<outlet property="maxWorkIntensityTextField" destination="rJh-QS-fAl" id="u9q-Sj-6SY"/>
<outlet property="minThreadsTextField" destination="sCM-tI-skI" id="D0Z-yT-LbU"/>
<outlet property="minWorkIntensityTextField" destination="CuN-wx-fvQ" id="Eik-Z2-7M7"/>
<outlet property="profilingUITestDataMarshalingStatus" destination="2LR-W8-mNE" id="S4k-Yg-EsB"/>
<outlet property="profilingUITestDataMarshalingTextField" destination="5zI-Ix-rMJ" id="2o6-Cc-NMl"/>
<outlet property="valueTextField" destination="uTM-T7-Gv6" id="M59-lx-juE"/>
<outlet property="workIntensityFactorLabel" destination="cAO-gr-3HC" id="BvB-NZ-TXI"/>
<outlet property="workIntervalSlider" destination="N8m-ny-upJ" id="3MU-ZK-5qD"/>
Expand Down Expand Up @@ -587,7 +611,7 @@
<objects>
<navigationController id="5CD-RQ-aBU" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="SjT-Zj-cMF">
<rect key="frame" x="0.0" y="20" width="320" height="44"/>
<rect key="frame" x="0.0" y="20" width="320" height="50"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand Down
13 changes: 0 additions & 13 deletions Samples/iOS-Swift/iOS-Swift/Helpers.swift

This file was deleted.

Loading

0 comments on commit 655b9d3

Please sign in to comment.