Skip to content

Commit d26c417

Browse files
authored
chore: debug logging (#4266)
1 parent d8cc6ae commit d26c417

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@
125125
# if SENTRY_HAS_UIKIT
126126
profiler.screenFrameData =
127127
[SentryDependencyContainer.sharedInstance.framesTracker.currentFrames copy];
128+
SENTRY_LOG_DEBUG(
129+
@"Grabbing copy of frames tracker screen frames data to attach to profiler: %@.",
130+
profiler.screenFrameData);
128131
if (_gProfilersToTracers.count == 0) {
129132
[SentryDependencyContainer.sharedInstance.framesTracker resetProfilingTimestamps];
130133
}

Sources/Sentry/Profiling/SentryProfilerState.mm

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "SentryProfilerState.h"
22
#if SENTRY_TARGET_PROFILING_SUPPORTED
3+
# import "SentryAsyncSafeLog.h"
34
# import "SentryBacktrace.hpp"
45
# import "SentryDependencyContainer.h"
56
# import "SentryDispatchQueueWrapper.h"
@@ -121,7 +122,8 @@ - (void)appendBacktrace:(const Backtrace &)backtrace
121122
const auto symbols
122123
= backtrace_symbols(reinterpret_cast<void *const *>(backtrace.addresses.data()),
123124
static_cast<int>(backtrace.addresses.size()));
124-
# endif
125+
const auto *backtraceFunctionNames = [NSMutableArray<NSString *> array];
126+
# endif // defined(DEBUG)
125127

126128
const auto stack = [NSMutableArray<NSNumber *> array];
127129
for (std::vector<uintptr_t>::size_type backtraceAddressIdx = 0;
@@ -133,8 +135,10 @@ - (void)appendBacktrace:(const Backtrace &)backtrace
133135
const auto frame = [NSMutableDictionary<NSString *, id> dictionary];
134136
frame[@"instruction_addr"] = instructionAddress;
135137
# if defined(DEBUG)
136-
frame[@"function"]
138+
const auto functionName
137139
= parseBacktraceSymbolsFunctionName(symbols[backtraceAddressIdx]);
140+
frame[@"function"] = functionName;
141+
[backtraceFunctionNames addObject:functionName];
138142
# endif
139143
const auto newFrameIndex = @(state.frames.count);
140144
[stack addObject:newFrameIndex];
@@ -146,7 +150,7 @@ - (void)appendBacktrace:(const Backtrace &)backtrace
146150
}
147151
# if defined(DEBUG)
148152
free(symbols);
149-
# endif
153+
# endif // defined(DEBUG)
150154

151155
const auto sample = [[SentrySample alloc] init];
152156
sample.absoluteTimestamp = backtrace.absoluteTimestamp;
@@ -165,6 +169,14 @@ - (void)appendBacktrace:(const Backtrace &)backtrace
165169
[state.stacks addObject:stack];
166170
}
167171

172+
# if defined(DEBUG)
173+
if (backtraceFunctionNames.count > 0) {
174+
SENTRY_ASYNC_SAFE_LOG_DEBUG("Recorded backtrace for thread %s at %llu: %s",
175+
threadID.UTF8String, sample.absoluteTimestamp,
176+
backtraceFunctionNames.description.UTF8String);
177+
}
178+
# endif // defined(DEBUG)
179+
168180
[state.samples addObject:sample];
169181
}];
170182
}

Sources/Sentry/SentryFramesTracker.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ - (void)resetProfilingTimestamps
135135

136136
- (void)resetProfilingTimestampsInternal
137137
{
138+
SENTRY_LOG_DEBUG(@"Resetting profiling GPU timeseries data.");
138139
self.frozenFrameTimestamps = [SentryMutableFrameInfoTimeSeries array];
139140
self.slowFrameTimestamps = [SentryMutableFrameInfoTimeSeries array];
140141
self.frameRateTimestamps = [SentryMutableFrameInfoTimeSeries array];

Sources/Sentry/SentryHttpTransport.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,14 @@ - (void)sendAllCachedEnvelopes
290290

291291
SentryEnvelope *envelope = [SentrySerialization envelopeWithData:envelopeFileContents.contents];
292292
if (nil == envelope) {
293+
SENTRY_LOG_DEBUG(@"Envelope contained no deserializable data.");
293294
[self deleteEnvelopeAndSendNext:envelopeFileContents.path];
294295
return;
295296
}
296297

297298
SentryEnvelope *rateLimitedEnvelope = [self.envelopeRateLimit removeRateLimitedItems:envelope];
298299
if (rateLimitedEnvelope.items.count == 0) {
300+
SENTRY_LOG_DEBUG(@"Envelope had no rate-limited items, nothing to send.");
299301
[self deleteEnvelopeAndSendNext:envelopeFileContents.path];
300302
return;
301303
}
@@ -309,6 +311,7 @@ - (void)sendAllCachedEnvelopes
309311
didFailWithError:&requestError];
310312

311313
if (nil != requestError) {
314+
SENTRY_LOG_DEBUG(@"Failed to build request: %@.", requestError);
312315
[self recordLostEventFor:rateLimitedEnvelope.items];
313316
[self deleteEnvelopeAndSendNext:envelopeFileContents.path];
314317
return;
@@ -350,12 +353,13 @@ - (void)sendEnvelope:(SentryEnvelope *)envelope
350353
return;
351354
}
352355

353-
// If the response is not nil we had an internet connection.
354356
if (error && response.statusCode != 429) {
357+
SENTRY_LOG_DEBUG(@"Request error other than rate limit: %@", error);
355358
[weakSelf recordLostEventFor:envelope.items];
356359
}
357360

358361
if (nil != response) {
362+
SENTRY_LOG_DEBUG(@"Envelope sent successfully!");
359363
[weakSelf.rateLimits update:response];
360364
[weakSelf deleteEnvelopeAndSendNext:envelopePath];
361365
} else {
@@ -367,7 +371,6 @@ - (void)sendEnvelope:(SentryEnvelope *)envelope
367371

368372
- (void)finishedSending
369373
{
370-
SENTRY_LOG_DEBUG(@"Finished sending.");
371374
@synchronized(self) {
372375
self.isSending = NO;
373376
if (self.isFlushing) {

Sources/Sentry/SentryNSURLRequest.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ - (instancetype)initEnvelopeRequestWithURL:(NSURL *)url
9595
forHTTPHeaderField:@"User-Agent"];
9696
[self setValue:@"gzip" forHTTPHeaderField:@"Content-Encoding"];
9797
self.HTTPBody = sentry_gzippedWithCompressionLevel(data, -1, error);
98+
99+
SENTRY_LOG_DEBUG(@"Constructed request: %@", self);
98100
}
99101

100102
return self;

Sources/Sentry/SentryScreenFrames.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ - (nonnull id)copyWithZone:(nullable NSZone *)zone
7878

7979
# endif // SENTRY_TARGET_PROFILING_SUPPORTED
8080

81+
- (NSString *)description
82+
{
83+
NSMutableString *result = [NSMutableString
84+
stringWithFormat:@"Total frames: %lu; slow frames: %lu; frozen frames: %lu",
85+
(unsigned long)_total, (unsigned long)_slow, (unsigned long)_frozen];
86+
# if SENTRY_TARGET_PROFILING_SUPPORTED
87+
[result appendFormat:
88+
@"\nslowFrameTimestamps: %@\nfrozenFrameTimestamps: %@\nframeRateTimestamps: %@",
89+
_slowFrameTimestamps, _frozenFrameTimestamps, _frameRateTimestamps];
90+
# endif // SENTRY_TARGET_PROFILING_SUPPORTED
91+
return result;
92+
}
93+
8194
@end
8295

8396
#endif // SENTRY_UIKIT_AVAILABLE

0 commit comments

Comments
 (0)