From 061086ece4aef1d22d2976cd81e30fd875f29254 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Tue, 30 Aug 2022 15:46:57 -0800 Subject: [PATCH] fixup! wip: profiling concurrent transactions - send profile payload in separate envelope from transaction. used to be the only corresponding transaction, would've had to choose one with concurrent, likely the last one. this will help keep minimal separate payloads, which will come with benefits in backend components. --- Sources/Sentry/SentryProfiler.mm | 12 ++++++++---- Sources/Sentry/SentryTracer.m | 12 ++++-------- Sources/Sentry/include/SentryProfiler.h | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 6471174961..52b555723a 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -219,7 +219,7 @@ - (void)stop } } -- (SentryEnvelopeItem *)buildEnvelopeItemForTransactions: +- (SentryEnvelope *)buildEnvelopeItemForTransactions: (NSArray *)transactions frameInfo:(SentryScreenFrames *)frameInfo { @@ -256,7 +256,8 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransactions: profile[@"device_is_emulator"] = @(isSimulatorBuild()); profile[@"device_physical_memory_bytes"] = [@(NSProcessInfo.processInfo.physicalMemory) stringValue]; - profile[@"profile_id"] = [[SentryId alloc] init].sentryIdString; + const auto profileID = [[SentryId alloc] init]; + profile[@"profile_id"] = profileID.sentryIdString; profile[@"duration_ns"] = [@(getDurationNs(_startTimestamp, getAbsoluteTime())) stringValue]; const auto bundle = NSBundle.mainBundle; @@ -306,7 +307,7 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransactions: @"trace_id" : transaction.trace.context.traceId.sentryIdString, @"name" : transaction.transaction, @"relative_start_ns" : transaction.startTimestamp, - @"relative_end_ns" : + @"relative_end_ns" : @"" // TODO: how to compute this? transactions use NSDate, we use mach_absolute_time }]; } profile[@"transactions"] = transactionsInfo; @@ -323,7 +324,10 @@ - (SentryEnvelopeItem *)buildEnvelopeItemForTransactions: const auto header = [[SentryEnvelopeItemHeader alloc] initWithType:SentryEnvelopeItemTypeProfile length:JSONData.length]; - return [[SentryEnvelopeItem alloc] initWithHeader:header data:JSONData]; + const auto item = [[SentryEnvelopeItem alloc] initWithHeader:header data:JSONData]; + + const auto envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:profileID]; + return [[SentryEnvelope alloc] initWithHeader:envelopeHeader singleItem:item]; } - (BOOL)isRunning diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 53556852fb..fa3848ed10 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -524,18 +524,14 @@ - (void)finishInternal return; } - NSMutableArray *additionalEnvelopeItems = [NSMutableArray array]; - #if SENTRY_TARGET_PROFILING_SUPPORTED + SentryEnvelope *profileEnvelope; if (_profilesSamplerDecision.decision == kSentrySampleDecisionYes) { [profilerLock lock]; if (profiler != nil) { - SentryEnvelopeItem *profile = + profileEnvelope = [profiler buildEnvelopeItemForTransactions:_gProfiledTransactions frameInfo:frameInfo]; - if (profile != nil) { - [additionalEnvelopeItems addObject:profile]; - } profiler = nil; } [profilerLock unlock]; @@ -543,8 +539,8 @@ - (void)finishInternal #endif [_hub captureTransaction:transaction - withScope:_hub.scope - additionalEnvelopeItems:additionalEnvelopeItems]; + withScope:_hub.scope]; + [_hub.client captureEnvelope:profileEnvelope]; } - (void)trimEndTimestamp diff --git a/Sources/Sentry/include/SentryProfiler.h b/Sources/Sentry/include/SentryProfiler.h index ed6fb68b25..0964da06e1 100644 --- a/Sources/Sentry/include/SentryProfiler.h +++ b/Sources/Sentry/include/SentryProfiler.h @@ -25,7 +25,8 @@ NSString *parseBacktraceSymbolsFunctionName(const char *symbol); SENTRY_EXTERN_C_END -@class SentryEnvelopeItem, SentryTransaction; +@class SentryEnvelope; +@class SentryTransaction; @interface SentryProfiler : NSObject @@ -41,7 +42,7 @@ SENTRY_EXTERN_C_END /** * Builds an envelope item using the currently accumulated profile data. */ -- (nullable SentryEnvelopeItem *) +- (nullable SentryEnvelope *) buildEnvelopeItemForTransactions:(NSArray *)transactions frameInfo:(nullable SentryScreenFrames *)frameInfo;