Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(profiling): rename more functions to prefix with sentry_ and remove leading underscores on public members #3874

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SentryTestUtils/ClearTestState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TestCleanup: NSObject {

#if os(iOS) || os(macOS) || targetEnvironment(macCatalyst)
SentryProfiler.getCurrent().stop(for: .normal)
SentryProfiler.resetConcurrencyTracking()
SentryProfiler.sentry_resetConcurrencyTracking()
#endif // os(iOS) || os(macOS) || targetEnvironment(macCatalyst)

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/PrivateSentrySDKOnly.mm
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ + (uint64_t)startProfilerForTrace:(SentryId *)traceId;

+ (void)discardProfilerForTrace:(SentryId *)traceId;
{
discardProfilerForTracer(traceId);
sentry_discardProfilerForTracer(traceId);
}

#endif // SENTRY_TARGET_PROFILING_SUPPORTED
Expand Down
12 changes: 6 additions & 6 deletions Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
std::mutex _gStateLock;

void
trackProfilerForTracer(SentryProfiler *profiler, SentryId *internalTraceId)
sentry_trackProfilerForTracer(SentryProfiler *profiler, SentryId *internalTraceId)
{
std::lock_guard<std::mutex> l(_gStateLock);

Expand Down Expand Up @@ -82,7 +82,7 @@
}

void
discardProfilerForTracer(SentryId *internalTraceId)
sentry_discardProfilerForTracer(SentryId *internalTraceId)
{
std::lock_guard<std::mutex> l(_gStateLock);

Expand All @@ -105,7 +105,7 @@
# endif // SENTRY_HAS_UIKIT
}

SentryProfiler *_Nullable profilerForFinishedTracer(SentryId *internalTraceId)
SentryProfiler *_Nullable sentry_profilerForFinishedTracer(SentryId *internalTraceId)
{
std::lock_guard<std::mutex> l(_gStateLock);

Expand All @@ -123,7 +123,7 @@
_unsafe_cleanUpProfiler(profiler, tracerKey);

# if SENTRY_HAS_UIKIT
profiler._screenFrameData =
profiler.screenFrameData =
[SentryDependencyContainer.sharedInstance.framesTracker.currentFrames copy];
if (_gProfilersToTracers.count == 0) {
[SentryDependencyContainer.sharedInstance.framesTracker resetProfilingTimestamps];
Expand All @@ -135,15 +135,15 @@

# if defined(TEST) || defined(TESTCI)
void
resetConcurrencyTracking()
sentry_resetConcurrencyTracking()
{
std::lock_guard<std::mutex> l(_gStateLock);
[_gTracersToProfilers removeAllObjects];
[_gProfilersToTracers removeAllObjects];
}

NSUInteger
currentProfiledTracers()
sentry_currentProfiledTracers()
{
std::lock_guard<std::mutex> l(_gStateLock);
return [_gTracersToProfilers count];
Expand Down
30 changes: 15 additions & 15 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
SentryProfiler *_Nullable _gCurrentProfiler;

NSString *
profilerTruncationReasonName(SentryProfilerTruncationReason reason)
sentry_profilerTruncationReasonName(SentryProfilerTruncationReason reason)
{
switch (reason) {
case SentryProfilerTruncationReasonNormal:
Expand Down Expand Up @@ -284,7 +284,7 @@ + (BOOL)startWithTracer:(SentryId *)traceId

if (_gCurrentProfiler && [_gCurrentProfiler isRunning]) {
SENTRY_LOG_DEBUG(@"A profiler is already running.");
trackProfilerForTracer(_gCurrentProfiler, traceId);
sentry_trackProfilerForTracer(_gCurrentProfiler, traceId);
// record a new metric sample for every concurrent span start
[_gCurrentProfiler->_metricProfiler recordMetrics];
return YES;
Expand All @@ -296,7 +296,7 @@ + (BOOL)startWithTracer:(SentryId *)traceId
return NO;
}

trackProfilerForTracer(_gCurrentProfiler, traceId);
sentry_trackProfilerForTracer(_gCurrentProfiler, traceId);
return YES;
}

Expand Down Expand Up @@ -352,7 +352,7 @@ + (nullable SentryEnvelopeItem *)createEnvelopeItemForProfilePayload:
forTrace:(SentryId *)traceId
onHub:(SentryHub *)hub;
{
const auto profiler = profilerForFinishedTracer(traceId);
const auto profiler = sentry_profilerForFinishedTracer(traceId);
if (!profiler) {
return nil;
}
Expand Down Expand Up @@ -384,13 +384,13 @@ + (void)updateProfilePayload:(NSMutableDictionary<NSString *, id> *)payload
and:(uint64_t)endSystemTime
onHub:(SentryHub *)hub;
{
return serializedProfileData([self._state copyProfilingData], startSystemTime, endSystemTime,
profilerTruncationReasonName(_truncationReason),
return serializedProfileData([self.state copyProfilingData], startSystemTime, endSystemTime,
sentry_profilerTruncationReasonName(_truncationReason),
[_metricProfiler serializeBetween:startSystemTime and:endSystemTime],
[_debugImageProvider getDebugImagesCrashed:NO], hub
# if SENTRY_HAS_UIKIT
,
self._screenFrameData
self.screenFrameData
# endif // SENTRY_HAS_UIKIT
);
}
Expand Down Expand Up @@ -474,7 +474,7 @@ - (void)start
SENTRY_LOG_DEBUG(@"Starting profiler.");

SentryProfilerState *const state = [[SentryProfilerState alloc] init];
self._state = state;
self.state = state;
_profiler = std::make_shared<SamplingProfiler>(
[state](auto &backtrace) {
// in test, we'll overwrite the sample's timestamp to one mocked by SentryCurrentDate
Expand Down Expand Up @@ -512,17 +512,17 @@ + (SentryProfiler *)getCurrentProfiler
return _gCurrentProfiler;
}

// this just calls through to SentryProfiledTracerConcurrency.resetConcurrencyTracking(). we have to
// do this through SentryTracer because SentryProfiledTracerConcurrency cannot be included in test
// targets via ObjC bridging headers because it contains C++.
+ (void)resetConcurrencyTracking
// this just calls through to SentryProfiledTracerConcurrency.sentry_resetConcurrencyTracking(). we
// have to do this through SentryTracer because SentryProfiledTracerConcurrency cannot be included
// in test targets via ObjC bridging headers because it contains C++.
+ (void)sentry_resetConcurrencyTracking
{
resetConcurrencyTracking();
sentry_resetConcurrencyTracking();
}

+ (NSUInteger)currentProfiledTracers
+ (NSUInteger)sentry_currentProfiledTracers
{
return currentProfiledTracers();
return sentry_currentProfiledTracers();
}
# endif // defined(TEST) || defined(TESTCI)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ - (void)dealloc
{
#if SENTRY_TARGET_PROFILING_SUPPORTED
if (self.isProfiling) {
discardProfilerForTracer(self.internalID);
sentry_discardProfilerForTracer(self.internalID);
}
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Sentry/include/SentryProfiledTracerConcurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ SENTRY_EXTERN_C_BEGIN
* Associate the provided profiler and tracer so that profiling data may be retrieved by the tracer
* when it is ready to transmit its envelope.
*/
void trackProfilerForTracer(SentryProfiler *profiler, SentryId *internalTraceId);
void sentry_trackProfilerForTracer(SentryProfiler *profiler, SentryId *internalTraceId);

/**
* For transactions that will be discarded, clean up the bookkeeping state associated with them to
* reclaim the memory they're using.
*/
void discardProfilerForTracer(SentryId *internalTraceId);
void sentry_discardProfilerForTracer(SentryId *internalTraceId);

/**
* Return the profiler instance associated with the tracer. If it was the last tracer for the
* associated profiler, stop that profiler. Copy any recorded @c SentryScreenFrames data into the
* profiler instance, and if this is the last profiler being tracked, reset the
* @c SentryFramesTracker data.
*/
SentryProfiler *_Nullable profilerForFinishedTracer(SentryId *internalTraceId);
SentryProfiler *_Nullable sentry_profilerForFinishedTracer(SentryId *internalTraceId);

# if defined(TEST) || defined(TESTCI)
void resetConcurrencyTracking(void);
NSUInteger currentProfiledTracers(void);
void sentry_resetConcurrencyTracking(void);
NSUInteger sentry_currentProfiledTracers(void);
# endif // defined(TEST) || defined(TESTCI)

SENTRY_EXTERN_C_END
Expand Down
6 changes: 3 additions & 3 deletions Sources/Sentry/include/SentryProfiler+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SENTRY_EXTERN NSString *const kSentryProfilerSerializationKeyFrameRates;

SENTRY_EXTERN_C_BEGIN

NSString *profilerTruncationReasonName(SentryProfilerTruncationReason reason);
NSString *sentry_profilerTruncationReasonName(SentryProfilerTruncationReason reason);

SENTRY_EXTERN_C_END

Expand All @@ -45,10 +45,10 @@ SENTRY_EXTERN_C_END

@property (strong, nonatomic) SentryId *profilerId;

@property (strong, nonatomic) SentryProfilerState *_state;
@property (strong, nonatomic) SentryProfilerState *state;

# if SENTRY_HAS_UIKIT
@property (strong, nonatomic) SentryScreenFrames *_screenFrameData;
@property (strong, nonatomic) SentryScreenFrames *screenFrameData;
# endif // SENTRY_HAS_UIKIT

/**
Expand Down
54 changes: 27 additions & 27 deletions Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class SentryProfilerSwiftTests: XCTestCase {

func createConcurrentSpansWithMetrics() throws {
XCTAssertFalse(SentryProfiler.isCurrentlyProfiling())
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))

for i in 0 ..< numberOfTransactions {
print("creating new concurrent transaction for test")
Expand All @@ -289,7 +289,7 @@ class SentryProfilerSwiftTests: XCTestCase {
fixture.systemWrapper.overrides.cpuEnergyUsage = NSNumber(value: fixture.systemWrapper.overrides.cpuEnergyUsage!.intValue + fixture.mockEnergyUsage.intValue)

XCTAssertTrue(SentryProfiler.isCurrentlyProfiling())
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(i + 1))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(i + 1))
spans.append(span)
fixture.currentDateProvider.advanceBy(nanoseconds: 100)
}
Expand All @@ -301,7 +301,7 @@ class SentryProfilerSwiftTests: XCTestCase {
try fixture.gatherMockedMetrics(span: span)
XCTAssertTrue(SentryProfiler.isCurrentlyProfiling())
span.finish()
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(numberOfTransactions - (i + 1)))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(numberOfTransactions - (i + 1)))

try self.assertValidProfileData(expectedThreadMetadata: [threadMetadata])

Expand All @@ -314,7 +314,7 @@ class SentryProfilerSwiftTests: XCTestCase {
}

XCTAssertFalse(SentryProfiler.isCurrentlyProfiling())
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
}

try createConcurrentSpansWithMetrics()
Expand Down Expand Up @@ -453,102 +453,102 @@ class SentryProfilerSwiftTests: XCTestCase {

/// based on ``SentryTracerTests.testFinish_WithoutHub_DoesntCaptureTransaction``
func testProfilerCleanedUpAfterTransactionDiscarded_NoHub() throws {
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
func performTransaction() {
let sut = SentryTracer(transactionContext: TransactionContext(name: fixture.transactionName, operation: fixture.transactionOperation), hub: nil)
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
sut.finish()
}
performTransaction()
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
XCTAssertEqual(self.fixture.client?.captureEventWithScopeInvocations.count, 0)
}

/// based on ``SentryTracerTests.testFinish_WaitForAllChildren_ExceedsMaxDuration_NoTransactionCaptured``
func testProfilerCleanedUpAfterTransactionDiscarded_ExceedsMaxDuration() throws {
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
func performTransaction() throws {
let sut = try fixture.newTransaction(automaticTransaction: true)
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(1))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(1))
fixture.currentDateProvider.advance(by: 500)
sut.finish()
}
try performTransaction()
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
XCTAssertEqual(self.fixture.client?.captureEventWithScopeInvocations.count, 0)
}

func testProfilerCleanedUpAfterInFlightTransactionDeallocated() throws {
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
func performTransaction() throws {
let sut = try fixture.newTransaction(automaticTransaction: true)
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(1))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(1))
XCTAssertFalse(sut.isFinished)
}
try performTransaction()
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
XCTAssertEqual(self.fixture.client?.captureEventWithScopeInvocations.count, 0)
}

/// based on ``SentryTracerTests.testFinish_IdleTimeout_ExceedsMaxDuration_NoTransactionCaptured``
func testProfilerCleanedUpAfterTransactionDiscarded_IdleTimeout_ExceedsMaxDuration() throws {
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
func performTransaction() throws {
let sut = try fixture.newTransaction(automaticTransaction: true, idleTimeout: 1)
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(1))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(1))
fixture.currentDateProvider.advance(by: 500)
sut.finish()
}
try performTransaction()
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
XCTAssertEqual(self.fixture.client?.captureEventWithScopeInvocations.count, 0)
}

/// based on ``SentryTracerTests.testIdleTimeout_NoChildren_TransactionNotCaptured``
func testProfilerCleanedUpAfterTransactionDiscarded_IdleTimeout_NoChildren() throws {
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
func performTransaction() throws {
let span = try fixture.newTransaction(automaticTransaction: true, idleTimeout: 1)
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(1))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(1))
fixture.currentDateProvider.advance(by: 500)
fixture.dispatchQueueWrapper.invokeLastDispatchAfter()
XCTAssert(span.isFinished)
}
try performTransaction()
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
XCTAssertEqual(self.fixture.client?.captureEventWithScopeInvocations.count, 0)
}

/// based on ``SentryTracerTests.testIdleTransaction_CreatingDispatchBlockFails_NoTransactionCaptured``
func testProfilerCleanedUpAfterTransactionDiscarded_IdleTransaction_CreatingDispatchBlockFails() throws {
fixture.dispatchQueueWrapper.createDispatchBlockReturnsNULL = true
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
func performTransaction() throws {
let span = try fixture.newTransaction(automaticTransaction: true, idleTimeout: 1)
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(1))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(1))
fixture.currentDateProvider.advance(by: 500)
span.finish()
}
try performTransaction()
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
XCTAssertEqual(self.fixture.client?.captureEventWithScopeInvocations.count, 0)
}

#if !os(macOS)
/// based on ``SentryTracerTests.testFinish_WaitForAllChildren_StartTimeModified_NoTransactionCaptured``
func testProfilerCleanedUpAfterTransactionDiscarded_WaitForAllChildren_StartTimeModified() throws {
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
let appStartMeasurement = fixture.getAppStartMeasurement(type: .cold)
SentrySDK.setAppStartMeasurement(appStartMeasurement)
fixture.currentDateProvider.advance(by: 1)
func performTransaction() throws {
let sut = try fixture.newTransaction(testingAppLaunchSpans: true, automaticTransaction: true)
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(1))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(1))
fixture.currentDateProvider.advance(by: 499)
sut.finish()
}
try performTransaction()
XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0))
XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0))
XCTAssertEqual(self.fixture.client?.captureEventWithScopeInvocations.count, 0)
}
#endif // !os(macOS)
Expand All @@ -571,7 +571,7 @@ private extension SentryProfilerSwiftTests {
}

func addMockSamples(threadMetadata: ThreadMetadata = ThreadMetadata(id: 1, priority: 2, name: "test-thread"), addresses: [NSNumber] = [0x3, 0x4, 0x5]) {
let state = SentryProfiler.getCurrent()._state
let state = SentryProfiler.getCurrent().state
fixture.currentDateProvider.advanceBy(nanoseconds: 1)
SentryProfilerMocksSwiftCompatible.appendMockBacktrace(to: state, threadID: threadMetadata.id, threadPriority: threadMetadata.priority, threadName: threadMetadata.name, addresses: addresses)
fixture.currentDateProvider.advanceBy(nanoseconds: 1)
Expand Down Expand Up @@ -836,7 +836,7 @@ private extension SentryProfilerSwiftTests {
}

if shouldTimeout {
XCTAssertEqual(try XCTUnwrap(profile["truncation_reason"] as? String), profilerTruncationReasonName(.timeout))
XCTAssertEqual(try XCTUnwrap(profile["truncation_reason"] as? String), sentry_profilerTruncationReasonName(.timeout))
}
}

Expand Down
Loading
Loading