Skip to content

Commit

Permalink
Added a bool to duration metric and extended logging timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mbruin-NR committed Dec 16, 2024
1 parent 1ef1da5 commit b9f4cd1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions Agent/NRMAStartTimer/NRMAStartTimer.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ - (void)start {
#endif
}

- (void)createDurationMetric {
- (BOOL)createDurationMetric {

// Based on whether or not we've saved a boot timestamp and whether or not the app has been launched this boot we can determine whether or not this is a warm start.
NSDate *previousBootTime = [[NSUserDefaults standardUserDefaults] objectForKey:systemBootTimestampKey];
Expand All @@ -114,16 +114,16 @@ - (void)createDurationMetric {
if ([self isPrewarmAvailable] && isPrewarmLaunch) {
NRLOG_AGENT_INFO(@"New Relic: Skipping App Start Time because iOS prewarmed this launch.");

return;
return false;
}
if (self.isWarmLaunch) {
NRLOG_AGENT_INFO(@"New Relic: Skipping App Start Time because matching boot times.");
return;
return false;
}

// If the app was running in the background. Skip recording this launch.
if (self.wasInBackground) {
return;
return false;
}

// App Launch Time: Cold is time between now and when process started.
Expand All @@ -132,10 +132,11 @@ - (void)createDurationMetric {
// Skip recording obviously wrong extra long app launch durations.
if (calculatedAppLaunchDuration >= maxAppLaunchDuration) {
NRLOG_AGENT_INFO(@"New Relic: Skipping app start time metric since %f > allowed.", calculatedAppLaunchDuration);
return;
return false;
}

self.appLaunchDuration = calculatedAppLaunchDuration;
return true;
}

- (BOOL)isPrewarmAvailable {
Expand Down
1 change: 1 addition & 0 deletions Agent/Public/NRMATaskQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
+ (void) stop;

+ (void) synchronousDequeue;
+ (void) synchronousDequeueWithCompletion:(void (^)(BOOL))completion;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ - (void) testRemoteLogLevels {
@"additionalAttribute2": @"attribute2"
}];

[self waitForExpectationsWithTimeout:5 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];

NSError* error;
NSData* logData = [NRLogger logFileData:&error];
Expand Down Expand Up @@ -290,7 +290,7 @@ - (void) testLocalLogLevels {
@"additionalAttribute2": @"attribute2"
}];

[self waitForExpectationsWithTimeout:5 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];

NSError* error;
NSData* logData = [NRLogger logFileData:&error];
Expand Down Expand Up @@ -365,7 +365,7 @@ - (void) testAutoCollectedLogs {
os_log_error(customLog, "This is an error os_log message.\n");
os_log_fault(customLog, "This is a fault os_log message.\n");

[self waitForExpectationsWithTimeout:5 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];

[NRAutoLogCollector restoreStandardOutputAndError];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ + (void) clear;
@end

@interface NRMAStartTimer ()
- (void)createDurationMetric;
- (BOOL)createDurationMetric;
@end

@implementation NRMAStartTimerTests
Expand All @@ -46,14 +46,13 @@ - (void) tearDown {
-(void)test {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"systemBootTimestamp"];

[[NRMAStartTimer sharedInstance] createDurationMetric];

BOOL success = [[NRMAStartTimer sharedInstance] createDurationMetric];
XCTSkipIf(!success, @"Failed to create duration metric");

[NRMASupportMetricHelper processDeferredMetrics];

[NRMATaskQueue synchronousDequeue];

sleep(1);

NRMANamedValueMeasurement* measurement = ((NRMANamedValueMeasurement*)helper.result);

XCTAssertTrue([measurement.name isEqualToString:NRMA_METRIC_APP_LAUNCH_COLD], @"%@ does not equal AppLaunch/Cold", measurement.name);
Expand Down

0 comments on commit b9f4cd1

Please sign in to comment.