diff --git a/Sources/Sentry/SentryEvent.m b/Sources/Sentry/SentryEvent.m index 4ff889d031a..60b24517897 100644 --- a/Sources/Sentry/SentryEvent.m +++ b/Sources/Sentry/SentryEvent.m @@ -10,8 +10,8 @@ #import "SentryMessage.h" #import "SentryMeta.h" #import "SentryStacktrace.h" -#import "SentryTime.h" #import "SentryThread.h" +#import "SentryTime.h" #import "SentryUser.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index af40e36fb2b..3c6ccf84586 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -60,11 +60,16 @@ return [symbolNSStr substringWithRange:[match rangeAtIndex:1]]; } -NSString *profilerStopReasonName(SentryProfilerStopReason reason) { +NSString * +profilerStopReasonName(SentryProfilerStopReason reason) +{ switch (reason) { - case SentryProfilerStopReasonNormal: return @"normal"; - case SentryProfilerStopReasonAppMovedToBackground: return @"backgrounded"; - case SentryProfilerStopReasonTimeout: return @"timeout"; + case SentryProfilerStopReasonNormal: + return @"normal"; + case SentryProfilerStopReasonAppMovedToBackground: + return @"backgrounded"; + case SentryProfilerStopReasonTimeout: + return @"timeout"; } } @@ -156,7 +161,10 @@ - (void)start _profile[@"sampled_profile"] = sampledProfile; _startTimestamp = getAbsoluteTime(); - [SentryLog logWithMessage:[NSString stringWithFormat:@"Starting profiler at system time %llu.", _startTimestamp] andLevel:kSentryLevelDebug]; + [SentryLog + logWithMessage:[NSString stringWithFormat:@"Starting profiler at system time %llu.", + _startTimestamp] + andLevel:kSentryLevelDebug]; __weak const auto weakSelf = self; _profiler = std::make_shared( @@ -230,7 +238,10 @@ - (void)stop if (_profiler != nullptr) { _profiler->stopSampling(); _endTimestamp = getAbsoluteTime(); - [SentryLog logWithMessage:[NSString stringWithFormat:@"Stopped profiler at system time: %llu.", _endTimestamp] andLevel:kSentryLevelDebug]; + [SentryLog + logWithMessage:[NSString stringWithFormat:@"Stopped profiler at system time: %llu.", + _endTimestamp] + andLevel:kSentryLevelDebug]; } } } @@ -238,7 +249,7 @@ - (void)stop - (SentryEnvelope *)buildEnvelopeItemForTransactions:(NSArray *)transactions hub:(SentryHub *)hub frameInfo:(SentryScreenFrames *)frameInfo -stopReason:(SentryProfilerStopReason)stopReason + stopReason:(SentryProfilerStopReason)stopReason { NSParameterAssert(transactions.count > 0); NSMutableDictionary *profile = nil; diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 2d94725565d..362104d222c 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -27,7 +27,9 @@ - (instancetype)initWithTransaction:(SentryTracer *)transaction context:(SentryS _context = context; self.startTimestamp = [SentryCurrentDate date]; self.systemStartTime = getAbsoluteTime(); - [SentryLog logWithMessage:[NSString stringWithFormat:@"Starting span at system time %llu", self.systemStartTime] andLevel:kSentryLevelDebug]; + [SentryLog logWithMessage:[NSString stringWithFormat:@"Starting span at system time %llu", + self.systemStartTime] + andLevel:kSentryLevelDebug]; _data = [[NSMutableDictionary alloc] init]; _tags = [[NSMutableDictionary alloc] init]; _isFinished = NO; @@ -120,7 +122,11 @@ - (void)finishWithStatus:(SentrySpanStatus)status if (self.transaction != nil) { [self.transaction spanFinished:self]; } - [SentryLog logWithMessage:[NSString stringWithFormat:@"Finishing span with status: %@ at system time %llu", spanStatusName(status), self.systemEndTime] andLevel:kSentryLevelDebug]; + [SentryLog + logWithMessage:[NSString + stringWithFormat:@"Finishing span with status: %@ at system time %llu", + spanStatusName(status), self.systemEndTime] + andLevel:kSentryLevelDebug]; } - (SentryTraceHeader *)toTraceHeader diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 80d0220fa11..6b8bdab7564 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -192,9 +192,10 @@ - (instancetype)initWithTransactionContext:(SentryTransactionContext *)transacti [framesTracker resetProfilingTimestamps]; # endif // SENTRY_HAS_UIKIT [profiler start]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 30), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 30), dispatch_get_main_queue(), + ^ { - }); + }); } if (_gProfiledTracers == nil) { _gProfiledTracers = [NSMutableArray array]; @@ -464,17 +465,24 @@ - (BOOL)hasChildrenToWaitFor } /** - * Stop the profiler immediately for an abnormal reason, or in the normal case, if all concurrent transactions have completed. + * Stop the profiler immediately for an abnormal reason, or in the normal case, if all concurrent + * transactions have completed. */ -- (void)maybeStopProfilerWithReason:(SentryProfilerStopReason)reason { +- (void)maybeStopProfilerWithReason:(SentryProfilerStopReason)reason +{ #if SENTRY_TARGET_PROFILING_SUPPORTED if (_profilesSamplerDecision.decision == kSentrySampleDecisionYes) { [profilerLock lock]; [_gProfiledTracers removeObject:self]; - BOOL shouldStopNormally = reason == SentryProfilerStopReasonNormal && _gProfiledTracers.count == 0; - BOOL shouldStopAbnormally = reason == SentryProfilerStopReasonTimeout || reason == SentryProfilerStopReasonAppMovedToBackground; + BOOL shouldStopNormally + = reason == SentryProfilerStopReasonNormal && _gProfiledTracers.count == 0; + BOOL shouldStopAbnormally = reason == SentryProfilerStopReasonTimeout + || reason == SentryProfilerStopReasonAppMovedToBackground; if (shouldStopNormally || shouldStopAbnormally) { - [SentryLog logWithMessage:[NSString stringWithFormat:@"Stopping profiler due to reason: %@.", profilerStopReasonName(reason)] andLevel:kSentryLevelDebug]; + [SentryLog + logWithMessage:[NSString stringWithFormat:@"Stopping profiler due to reason: %@.", + profilerStopReasonName(reason)] + andLevel:kSentryLevelDebug]; [profiler stop]; _gProfilerStopReason = reason; # if SENTRY_HAS_UIKIT @@ -491,15 +499,17 @@ - (void)maybeStopProfilerWithReason:(SentryProfilerStopReason)reason { /** * If the profiler has completed, capture an envelope with the information it has gathered. */ -- (void)captureProfilingEnvelopeIfFinished { +- (void)captureProfilingEnvelopeIfFinished +{ #if SENTRY_TARGET_PROFILING_SUPPORTED if (_profilesSamplerDecision.decision == kSentrySampleDecisionYes) { [profilerLock lock]; if (profiler != nil && !profiler.isRunning) { - [_hub.client captureEnvelope:[profiler buildEnvelopeItemForTransactions:_gProfiledTransactions - hub:_hub - frameInfo:_gProfilerFrameInfo - stopReason:_gProfilerStopReason]]; + [_hub.client + captureEnvelope:[profiler buildEnvelopeItemForTransactions:_gProfiledTransactions + hub:_hub + frameInfo:_gProfilerFrameInfo + stopReason:_gProfilerStopReason]]; profiler = nil; } [profilerLock unlock]; @@ -557,7 +567,11 @@ - (void)finishInternal if (_gProfiledTransactions == nil) { _gProfiledTransactions = [NSMutableArray array]; } - [SentryLog logWithMessage:[NSString stringWithFormat:@"Adding transaction %@ to list of profiled transactions.", transaction] andLevel:kSentryLevelDebug]; + [SentryLog + logWithMessage: + [NSString stringWithFormat:@"Adding transaction %@ to list of profiled transactions.", + transaction] + andLevel:kSentryLevelDebug]; [_gProfiledTransactions addObject:transaction]; [self captureProfilingEnvelopeIfFinished]; diff --git a/Sources/Sentry/include/SentryProfiler.h b/Sources/Sentry/include/SentryProfiler.h index 9b16d634891..eaea150506e 100644 --- a/Sources/Sentry/include/SentryProfiler.h +++ b/Sources/Sentry/include/SentryProfiler.h @@ -55,7 +55,7 @@ SENTRY_EXTERN_C_END buildEnvelopeItemForTransactions:(NSArray *)transactions hub:(SentryHub *)hub frameInfo:(nullable SentryScreenFrames *)frameInfo -stopReason:(SentryProfilerStopReason)stopReason; + stopReason:(SentryProfilerStopReason)stopReason; @end diff --git a/Tests/SentryTests/Profiling/SentryProfilerSwiftTests.swift b/Tests/SentryTests/Profiling/SentryProfilerSwiftTests.swift index cc3e5d5a8f1..3d571e6fc8d 100644 --- a/Tests/SentryTests/Profiling/SentryProfilerSwiftTests.swift +++ b/Tests/SentryTests/Profiling/SentryProfilerSwiftTests.swift @@ -1,5 +1,5 @@ -import XCTest import Sentry +import XCTest #if os(iOS) || os(macOS) || targetEnvironment(macCatalyst) class SentryProfilerSwiftTests: XCTestCase {