Skip to content

Commit

Permalink
only store the count of tracers in bookkeeping, not a set of references
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Jul 17, 2023
1 parent 0f5d163 commit 1467d20
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
# endif // SENTRY_HAS_UIKIT

/**
* a mapping of profilers to the tracers that started them that are still in-flight and will need to
* query them for their profiling data when they finish. this helps resolve the incongruity between
* the different timeout durations between tracers (500s) and profilers (30s), where a transaction
* may start a profiler that then times out, and then a new transaction starts a new profiler, and
* we must keep the aborted one around until its associated transaction finishes.
* a mapping of profilers to the number of tracers that started them that are still in-flight and
* will need to query them for their profiling data when they finish. this helps resolve the
* incongruity between the different timeout durations between tracers (500s) and profilers (30s),
* where a transaction may start a profiler that then times out, and then a new transaction starts a
* new profiler, and we must keep the aborted one around until its associated transaction finishes.
*/
static NSMutableDictionary</* SentryProfiler.profileId */ NSString *,
NSMutableSet<SentryTracer *> *> *_gProfilersToTracers;
/* number of in-flight tracers */ NSNumber *> *_gProfilersToTracers;

/** provided for fast access to a profiler given a tracer */
static NSMutableDictionary</* SentryTracer.tracerId */ NSString *, SentryProfiler *>
Expand All @@ -48,21 +48,14 @@

if (_gProfilersToTracers == nil) {
_gProfilersToTracers = [NSMutableDictionary</* SentryProfiler.profileId */ NSString *,
NSMutableSet<SentryTracer *> *> dictionaryWithObject:[NSMutableSet setWithObject:tracer]
forKey:profilerKey];
/* number of in-flight tracers */ NSNumber *>
dictionary];
_gTracersToProfilers =
[NSMutableDictionary</* SentryTracer.tracerId */ NSString *, SentryProfiler *>
dictionaryWithObject:profiler
forKey:tracerKey];
return;
}

if (_gProfilersToTracers[profilerKey] == nil) {
_gProfilersToTracers[profilerKey] = [NSMutableSet setWithObject:tracer];
} else {
[_gProfilersToTracers[profilerKey] addObject:tracer];
dictionary];
}

_gProfilersToTracers[profilerKey] = @(_gProfilersToTracers[profilerKey].unsignedIntValue + 1);
_gTracersToProfilers[tracerKey] = profiler;
}

Expand All @@ -85,8 +78,8 @@
const auto profilerKey = profiler.profileId.sentryIdString;

[_gTracersToProfilers removeObjectForKey:tracerKey];
[_gProfilersToTracers[profilerKey] removeObject:tracer];
if ([_gProfilersToTracers[profilerKey] count] == 0) {
_gProfilersToTracers[profilerKey] = @(_gProfilersToTracers[profilerKey].unsignedIntValue - 1);
if ([_gProfilersToTracers[profilerKey] unsignedIntValue] == 0) {
[_gProfilersToTracers removeObjectForKey:profilerKey];
if ([profiler isRunning]) {
[profiler stopForReason:SentryProfilerTruncationReasonNormal];
Expand Down Expand Up @@ -118,8 +111,8 @@
const auto profilerKey = profiler.profileId.sentryIdString;

[_gTracersToProfilers removeObjectForKey:tracerKey];
[_gProfilersToTracers[profilerKey] removeObject:tracer];
if ([_gProfilersToTracers[profilerKey] count] == 0) {
_gProfilersToTracers[profilerKey] = @(_gProfilersToTracers[profilerKey].unsignedIntValue - 1);
if ([_gProfilersToTracers[profilerKey] unsignedIntValue] == 0) {
[_gProfilersToTracers removeObjectForKey:profilerKey];
if ([profiler isRunning]) {
[profiler stopForReason:SentryProfilerTruncationReasonNormal];
Expand Down

0 comments on commit 1467d20

Please sign in to comment.