Skip to content

Commit

Permalink
Merge branch 'indragiek/remove-queue-metadata' of github.com:getsentr…
Browse files Browse the repository at this point in the history
…y/sentry-cocoa into indragiek/remove-queue-metadata
  • Loading branch information
indragiek committed Dec 30, 2023
2 parents db05a92 + 8a19bbe commit e6cc5f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion SentryTestUtils/SentryProfilerMocks.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#if SENTRY_TARGET_PROFILING_SUPPORTED

Backtrace
mockBacktrace(thread::TIDType threadID, const int threadPriority, const char *threadName, std::vector<std::uintptr_t> addresses)
mockBacktrace(thread::TIDType threadID, const int threadPriority, const char *threadName,
std::vector<std::uintptr_t> addresses)
{
ThreadMetadata threadMetadata;
if (threadName != nullptr) {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Sentry/Profiling/SentryProfilerState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# import "SentryFormatter.h"
# import "SentryProfileTimeseries.h"
# import "SentrySample.h"
# import <mutex>
# import <mach/mach_types.h>
# import <mach/port.h>
# import <mutex>

# if defined(DEBUG)
# include <execinfo.h>
Expand Down Expand Up @@ -66,9 +66,7 @@ - (instancetype)init
if ([NSThread isMainThread]) {
[self cacheMainThreadID];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[self cacheMainThreadID];
});
dispatch_async(dispatch_get_main_queue(), ^{ [self cacheMainThreadID]; });
}
}
return self;
Expand All @@ -81,7 +79,8 @@ - (void)mutate:(void (^)(SentryProfilerMutableState *))block
block(_mutableState);
}

- (void)cacheMainThreadID {
- (void)cacheMainThreadID
{
std::lock_guard<std::mutex> l(_lock);
NSAssert([NSThread isMainThread], @"Must be called on main thread");
const auto currentThread = pthread_mach_thread_np(pthread_self());
Expand All @@ -104,7 +103,8 @@ - (void)appendBacktrace:(const Backtrace &)backtrace
if (!backtrace.threadMetadata.name.empty()) {
metadata[@"name"] =
[NSString stringWithUTF8String:backtrace.threadMetadata.name.c_str()];
} else if (self->_mainThreadID != 0 && backtrace.threadMetadata.threadID == self->_mainThreadID) {
} else if (self->_mainThreadID != 0
&& backtrace.threadMetadata.threadID == self->_mainThreadID) {
metadata[@"name"] = @"main";
}
}
Expand Down
26 changes: 13 additions & 13 deletions Tests/SentryProfilerTests/SentryProfilerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ - (void)testProfilerMutationDuringSlicing
const auto addresses
= std::vector<std::uintptr_t>({ address + 1, address + 2, address + 3 });

auto backtrace
= mockBacktrace(threadID, threadPriority, threadName, addresses);
auto backtrace = mockBacktrace(threadID, threadPriority, threadName, addresses);

for (auto sample = 0; sample < samplesPerThread; sample++) {
backtrace.absoluteTimestamp = sampleIdx; // simulate 1 sample per nanosecond
Expand Down Expand Up @@ -116,8 +115,8 @@ - (void)testProfilerMutationDuringSlicing
}];
};

const auto backtrace = mockBacktrace(12345568910, 666, "testThread",
std::vector<std::uintptr_t>({ 777, 888, 789 }));
const auto backtrace = mockBacktrace(
12345568910, 666, "testThread", std::vector<std::uintptr_t>({ 777, 888, 789 }));

const auto mutateExpectation =
[self expectationWithDescription:@"all mutating operations complete"];
Expand Down Expand Up @@ -158,8 +157,8 @@ - (void)testProfilerMutationDuringSerialization
// initialize the data structures with some simulated data
{
// leave thread name as nil so it can be overwritten later
auto backtrace = mockBacktrace(
1, 2, nullptr, std::vector<std::uintptr_t>({ 0x4, 0x5, 0x6 }));
auto backtrace
= mockBacktrace(1, 2, nullptr, std::vector<std::uintptr_t>({ 0x4, 0x5, 0x6 }));

backtrace.absoluteTimestamp = 1;
[state appendBacktrace:backtrace];
Expand Down Expand Up @@ -187,15 +186,16 @@ - (void)testProfilerMutationDuringSerialization

// cause the data structures to be modified again: add new addresses
{
const auto backtrace = mockBacktrace(12345568910, 666, "newThread-2", std::vector<std::uintptr_t>({ 0x777, 0x888, 0x999 }));
const auto backtrace = mockBacktrace(
12345568910, 666, "newThread-2", std::vector<std::uintptr_t>({ 0x777, 0x888, 0x999 }));
[state appendBacktrace:backtrace];
}

// cause the data structures to be modified again: overwrite previous thread metadata
// subdictionary contents
{
auto backtrace = mockBacktrace(
1, 2, "testThread-1", std::vector<std::uintptr_t>({ 0x4, 0x5, 0x6 }));
auto backtrace
= mockBacktrace(1, 2, "testThread-1", std::vector<std::uintptr_t>({ 0x4, 0x5, 0x6 }));
backtrace.absoluteTimestamp = 6;
[state appendBacktrace:backtrace];
}
Expand Down Expand Up @@ -231,13 +231,13 @@ - (void)testProfilerPayload
SentryProfilerState *state = [[SentryProfilerState alloc] init];

// record an initial backtrace
const auto backtrace1 = mockBacktrace(12345568910, 666, "testThread",
std::vector<std::uintptr_t>({ 0x123, 0x456, 0x789 }));
const auto backtrace1 = mockBacktrace(
12345568910, 666, "testThread", std::vector<std::uintptr_t>({ 0x123, 0x456, 0x789 }));
[state appendBacktrace:backtrace1];

// record a second backtrace with some common addresses to test frame deduplication
const auto backtrace2 = mockBacktrace(12345568910, 666, "testThread",
std::vector<std::uintptr_t>({ 0x777, 0x888, 0x789 }));
const auto backtrace2 = mockBacktrace(
12345568910, 666, "testThread", std::vector<std::uintptr_t>({ 0x777, 0x888, 0x789 }));
[state appendBacktrace:backtrace2];

// record a third backtrace that's identical to the second to test stack/frame deduplication
Expand Down

0 comments on commit e6cc5f9

Please sign in to comment.