Skip to content

Commit

Permalink
Merge d8da8a5 into 1bf8571
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed May 10, 2023
2 parents 1bf8571 + d8da8a5 commit 2ff3f84
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 184 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This change has no impact on grouping of the issues in Sentry.

- Propagate span when copying scope (#2952)
- Remove "/" from crash report file name (#3005)
- Fix race condition in profiling serialization (#3018)

## 8.6.0

Expand Down
40 changes: 16 additions & 24 deletions Sources/Sentry/SentryProfileTimeseries.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# import "SentryLog.h"
# import "SentryTransaction.h"

std::mutex _gSamplesArrayLock;

/**
* Print a debug log to help diagnose slicing errors.
* @param start @c YES if this is an attempt to find the start of the sliced data based on the
Expand Down Expand Up @@ -44,51 +42,45 @@
NSArray<SentrySample *> *_Nullable slicedProfileSamples(
NSArray<SentrySample *> *samples, SentryTransaction *transaction)
{
NSArray<SentrySample *> *samplesCopy;
{
std::lock_guard<std::mutex> l(_gSamplesArrayLock);
samplesCopy = [samples copy];
}

if (samplesCopy.count == 0) {
if (samples.count == 0) {
return nil;
}

const auto transactionStart = transaction.startSystemTime;
const auto firstIndex =
[samplesCopy indexOfObjectWithOptions:NSEnumerationConcurrent
passingTest:^BOOL(SentrySample *_Nonnull sample, NSUInteger idx,
BOOL *_Nonnull stop) {
*stop = sample.absoluteTimestamp >= transactionStart;
return *stop;
}];
[samples indexOfObjectWithOptions:NSEnumerationConcurrent
passingTest:^BOOL(SentrySample *_Nonnull sample, NSUInteger idx,
BOOL *_Nonnull stop) {
*stop = sample.absoluteTimestamp >= transactionStart;
return *stop;
}];

if (firstIndex == NSNotFound) {
logSlicingFailureWithArray(samplesCopy, transaction, /*start*/ YES);
logSlicingFailureWithArray(samples, transaction, /*start*/ YES);
return nil;
} else {
SENTRY_LOG_DEBUG(@"Found first slice sample at index %lu", firstIndex);
}

const auto transactionEnd = transaction.endSystemTime;
const auto lastIndex =
[samplesCopy indexOfObjectWithOptions:NSEnumerationConcurrent | NSEnumerationReverse
passingTest:^BOOL(SentrySample *_Nonnull sample, NSUInteger idx,
BOOL *_Nonnull stop) {
*stop = sample.absoluteTimestamp <= transactionEnd;
return *stop;
}];
[samples indexOfObjectWithOptions:NSEnumerationConcurrent | NSEnumerationReverse
passingTest:^BOOL(SentrySample *_Nonnull sample, NSUInteger idx,
BOOL *_Nonnull stop) {
*stop = sample.absoluteTimestamp <= transactionEnd;
return *stop;
}];

if (lastIndex == NSNotFound) {
logSlicingFailureWithArray(samplesCopy, transaction, /*start*/ NO);
logSlicingFailureWithArray(samples, transaction, /*start*/ NO);
return nil;
} else {
SENTRY_LOG_DEBUG(@"Found last slice sample at index %lu", lastIndex);
}

const auto range = NSMakeRange(firstIndex, (lastIndex - firstIndex) + 1);
const auto indices = [NSIndexSet indexSetWithIndexesInRange:range];
return [samplesCopy objectsAtIndexes:indices];
return [samples objectsAtIndexes:indices];
}

@implementation SentrySample
Expand Down

0 comments on commit 2ff3f84

Please sign in to comment.