Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
getsentry-bot committed Jul 6, 2022
1 parent d83ab35 commit 60c3074
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
import ObjectiveC
import XCTest

class SDKPerformanceBenchmarkTests: XCTestCase {

Expand Down
43 changes: 28 additions & 15 deletions Samples/iOS-Swift/PerformanceBenchmarks/SentryDynamicTest.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <objc/runtime.h>
#import <XCTest/XCTest.h>
#import <objc/runtime.h>

// To get around the 15 minute timeout per test case on Sauce Labs.
static NSUInteger SentrySDKPerformanceBenchmarkTestCases = 4;
Expand All @@ -19,7 +19,8 @@ + (BOOL)addInstanceMethodWithSelectorName:(NSString *)selectorName block:(void (

@implementation SentrySDKPerformanceBenchmarkTests

+ (BOOL)addInstanceMethodWithSelectorName:(NSString *)selectorName block:(void (^)(id))block {
+ (BOOL)addInstanceMethodWithSelectorName:(NSString *)selectorName block:(void (^)(id))block
{
NSParameterAssert(selectorName);
NSParameterAssert(block);

Expand All @@ -31,17 +32,24 @@ + (BOOL)addInstanceMethodWithSelectorName:(NSString *)selectorName block:(void (
return class_addMethod(self, selector, myIMP, "v@:");
}

+ (void)initialize {
+ (void)initialize
{
allResults = [NSMutableArray array];
for (NSUInteger i = 0; i < SentrySDKPerformanceBenchmarkTestCases; i++) {
[self addInstanceMethodWithSelectorName:[NSString stringWithFormat:@"testCPUBenchmark%lu", (unsigned long)i] block:^(XCTestCase *testCase) {
[allResults addObjectsFromArray:[self _testCPUBenchmark]];
}];
[self addInstanceMethodWithSelectorName:[NSString stringWithFormat:@"testCPUBenchmark%lu",
(unsigned long)i]
block:^(XCTestCase *testCase) {
[allResults
addObjectsFromArray:[self _testCPUBenchmark]];
}];
}
}

- (void)tearDown {
if (allResults.count == SentrySDKPerformanceBenchmarkTestCases * SentrySDKPerformanceBenchmarkIterationsPerTestCase) {
- (void)tearDown
{
if (allResults.count
== SentrySDKPerformanceBenchmarkTestCases
* SentrySDKPerformanceBenchmarkIterationsPerTestCase) {
NSLog(@"All results begin");
NSLog(@"%@", allResults);
NSLog(@"All results end");
Expand All @@ -50,8 +58,9 @@ - (void)tearDown {
[super tearDown];
}

+ (BOOL)isSimulator {
NSOperatingSystemVersion ios9 = {9, 0, 0};
+ (BOOL)isSimulator
{
NSOperatingSystemVersion ios9 = { 9, 0, 0 };
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
if ([processInfo isOperatingSystemAtLeastVersion:ios9]) {
NSDictionary<NSString *, NSString *> *environment = [processInfo environment];
Expand All @@ -63,13 +72,15 @@ + (BOOL)isSimulator {
}
}

+ (NSArray<NSNumber *> *)_testCPUBenchmark {
// XCTSkipIf([self isSimulator]);
+ (NSArray<NSNumber *> *)_testCPUBenchmark
{
// XCTSkipIf([self isSimulator]);

NSMutableArray *results = [NSMutableArray array];
for (NSUInteger j = 0; j < SentrySDKPerformanceBenchmarkIterationsPerTestCase; j++) {
XCUIApplication *app = [[XCUIApplication alloc] init];
app.launchArguments = [app.launchArguments arrayByAddingObject:@"--io.sentry.test.benchmarking"];
app.launchArguments =
[app.launchArguments arrayByAddingObject:@"--io.sentry.test.benchmarking"];
[app launch];
[app.buttons[@"Performance scenarios"] tap];

Expand Down Expand Up @@ -98,8 +109,10 @@ + (BOOL)isSimulator {
}
double usagePercentage = benchmarkValueString.doubleValue;

// SentryBenchmarking.retrieveBenchmarks returns -1 if there aren't at least 2 samples to use for calculating deltas
XCTAssert(usagePercentage > 0, @"Failure to record enough CPU samples to calculate benchmark.");
// SentryBenchmarking.retrieveBenchmarks returns -1 if there aren't at least 2 samples to
// use for calculating deltas
XCTAssert(
usagePercentage > 0, @"Failure to record enough CPU samples to calculate benchmark.");
[results addObject:@(usagePercentage)];
}

Expand Down

0 comments on commit 60c3074

Please sign in to comment.