Skip to content

Commit

Permalink
extract implementation of SentryProfilerState; extract SentrySample
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Jul 7, 2023
1 parent 6c31077 commit 5cfe118
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Tests/SentryProfilerTests/SentryBacktraceTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ - (void)testCollectsMultiThreadBacktrace
break;
}
std::this_thread::sleep_for(
std::chrono::milliseconds(static_cast<long long>(std::pow(2, i + 1)) * 1000));
std::chrono::milliseconds(static_cast<long long>(std::pow(2, i + 1))));
}

XCTAssertEqual(pthread_cancel(thread1), 0);
Expand Down
8 changes: 5 additions & 3 deletions Tests/SentryProfilerTests/SentrySamplingProfilerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ - (void)testProfiling
profiler->startSampling([&start] { start = getAbsoluteTime(); });
XCTAssertTrue(profiler->isSampling());

std::this_thread::sleep_for(std::chrono::seconds(3));
// sleep long enough for 2 samples to be collected
const auto sleep = (uint64_t)(2.0 / samplingRateHz * 1000);
std::this_thread::sleep_for(std::chrono::milliseconds(sleep));

profiler->stopSampling();

XCTAssertFalse(profiler->isSampling());

const auto duration = std::chrono::nanoseconds(getDurationNs(start, getAbsoluteTime()));
XCTAssertGreaterThan(start, static_cast<std::uint64_t>(0));
XCTAssertGreaterThan(std::chrono::duration_cast<std::chrono::seconds>(duration).count(), 0);
XCTAssertGreaterThan(getDurationNs(start, getAbsoluteTime()), 0ULL);
XCTAssertGreaterThan(profiler->numSamples(), static_cast<std::uint64_t>(0));
XCTAssertGreaterThan(numIdleSamples, 0);
}
Expand Down
6 changes: 0 additions & 6 deletions Tests/SentryProfilerTests/SentryThreadMetadataCacheTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ - (void)testRetrievesThreadMetadata
SENTRY_PROF_LOG_ERROR_RETURN(pthread_setschedparam(thread, policy, &param));
}

std::this_thread::sleep_for(std::chrono::seconds(1));

const auto cache = std::make_shared<ThreadMetadataCache>();
ThreadHandle handle(pthread_mach_thread_np(thread));
const auto metadata = cache->metadataForThread(handle);
Expand All @@ -72,8 +70,6 @@ - (void)testReturnsCachedThreadMetadata
SENTRY_PROF_LOG_ERROR_RETURN(pthread_setschedparam(thread, policy, &param));
}

std::this_thread::sleep_for(std::chrono::seconds(1));

const auto cache = std::make_shared<ThreadMetadataCache>();
ThreadHandle handle(pthread_mach_thread_np(thread));
XCTAssertEqual(cache->metadataForThread(handle).priority, 50);
Expand All @@ -94,8 +90,6 @@ - (void)testIgnoresSentryOwnedThreads
char name[] = "io.sentry.SentryThreadMetadataCacheTests";
XCTAssertEqual(pthread_create(&thread, nullptr, threadSpin, reinterpret_cast<void *>(name)), 0);

std::this_thread::sleep_for(std::chrono::seconds(1));

const auto cache = std::make_shared<ThreadMetadataCache>();
ThreadHandle handle(pthread_mach_thread_np(thread));
XCTAssertEqual(cache->metadataForThread(handle).threadID, static_cast<unsigned long long>(0));
Expand Down

0 comments on commit 5cfe118

Please sign in to comment.