Skip to content

Commit

Permalink
Merge 3557f57 into 1bf8571
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed May 10, 2023
2 parents 1bf8571 + 3557f57 commit 619be64
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 185 deletions.
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 619be64

Please sign in to comment.