Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
getsentry-bot committed Sep 7, 2022
1 parent 693bd04 commit c0fc528
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

Expand Down Expand Up @@ -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<SamplingProfiler>(
Expand Down Expand Up @@ -230,15 +238,18 @@ - (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];
}
}
}

- (SentryEnvelope *)buildEnvelopeItemForTransactions:(NSArray<SentryTransaction *> *)transactions
hub:(SentryHub *)hub
frameInfo:(SentryScreenFrames *)frameInfo
stopReason:(SentryProfilerStopReason)stopReason
stopReason:(SentryProfilerStopReason)stopReason
{
NSParameterAssert(transactions.count > 0);
NSMutableDictionary<NSString *, id> *profile = nil;
Expand Down
10 changes: 8 additions & 2 deletions Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
40 changes: 27 additions & 13 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<SentryTracer *> array];
Expand Down Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -557,7 +567,11 @@ - (void)finishInternal
if (_gProfiledTransactions == nil) {
_gProfiledTransactions = [NSMutableArray<SentryTransaction *> 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];
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ SENTRY_EXTERN_C_END
buildEnvelopeItemForTransactions:(NSArray<SentryTransaction *> *)transactions
hub:(SentryHub *)hub
frameInfo:(nullable SentryScreenFrames *)frameInfo
stopReason:(SentryProfilerStopReason)stopReason;
stopReason:(SentryProfilerStopReason)stopReason;

@end

Expand Down
2 changes: 1 addition & 1 deletion Tests/SentryTests/Profiling/SentryProfilerSwiftTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import XCTest
import Sentry
import XCTest

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
class SentryProfilerSwiftTests: XCTestCase {
Expand Down

0 comments on commit c0fc528

Please sign in to comment.