Skip to content

Commit

Permalink
fixup! wip: profiling concurrent transactions
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
armcknight committed Aug 31, 2022
1 parent caf471b commit 061086e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
12 changes: 8 additions & 4 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ - (void)stop
}
}

- (SentryEnvelopeItem *)buildEnvelopeItemForTransactions:
- (SentryEnvelope *)buildEnvelopeItemForTransactions:
(NSArray<SentryTransaction *> *)transactions
frameInfo:(SentryScreenFrames *)frameInfo
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
12 changes: 4 additions & 8 deletions Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -524,27 +524,23 @@ - (void)finishInternal
return;
}

NSMutableArray<SentryEnvelopeItem *> *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];
}
#endif

[_hub captureTransaction:transaction
withScope:_hub.scope
additionalEnvelopeItems:additionalEnvelopeItems];
withScope:_hub.scope];
[_hub.client captureEnvelope:profileEnvelope];
}

- (void)trimEndTimestamp
Expand Down
5 changes: 3 additions & 2 deletions Sources/Sentry/include/SentryProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ NSString *parseBacktraceSymbolsFunctionName(const char *symbol);

SENTRY_EXTERN_C_END

@class SentryEnvelopeItem, SentryTransaction;
@class SentryEnvelope;
@class SentryTransaction;

@interface SentryProfiler : NSObject

Expand All @@ -41,7 +42,7 @@ SENTRY_EXTERN_C_END
/**
* Builds an envelope item using the currently accumulated profile data.
*/
- (nullable SentryEnvelopeItem *)
- (nullable SentryEnvelope *)
buildEnvelopeItemForTransactions:(NSArray<SentryTransaction *> *)transactions
frameInfo:(nullable SentryScreenFrames *)frameInfo;

Expand Down

0 comments on commit 061086e

Please sign in to comment.