diff --git a/SentryTestUtils/ClearTestState.swift b/SentryTestUtils/ClearTestState.swift index c0c8a92e75..c1f25057a8 100644 --- a/SentryTestUtils/ClearTestState.swift +++ b/SentryTestUtils/ClearTestState.swift @@ -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) diff --git a/Sources/Sentry/PrivateSentrySDKOnly.mm b/Sources/Sentry/PrivateSentrySDKOnly.mm index 07d68dfdf7..c524cba1e9 100644 --- a/Sources/Sentry/PrivateSentrySDKOnly.mm +++ b/Sources/Sentry/PrivateSentrySDKOnly.mm @@ -154,7 +154,7 @@ + (uint64_t)startProfilerForTrace:(SentryId *)traceId; + (void)discardProfilerForTrace:(SentryId *)traceId; { - discardProfilerForTracer(traceId); + sentry_discardProfilerForTracer(traceId); } #endif // SENTRY_TARGET_PROFILING_SUPPORTED diff --git a/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm b/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm index fe2913dfa2..a7bbf7f96a 100644 --- a/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm +++ b/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm @@ -54,7 +54,7 @@ std::mutex _gStateLock; void -trackProfilerForTracer(SentryProfiler *profiler, SentryId *internalTraceId) +sentry_trackProfilerForTracer(SentryProfiler *profiler, SentryId *internalTraceId) { std::lock_guard l(_gStateLock); @@ -82,7 +82,7 @@ } void -discardProfilerForTracer(SentryId *internalTraceId) +sentry_discardProfilerForTracer(SentryId *internalTraceId) { std::lock_guard l(_gStateLock); @@ -105,7 +105,7 @@ # endif // SENTRY_HAS_UIKIT } -SentryProfiler *_Nullable profilerForFinishedTracer(SentryId *internalTraceId) +SentryProfiler *_Nullable sentry_profilerForFinishedTracer(SentryId *internalTraceId) { std::lock_guard l(_gStateLock); @@ -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]; @@ -135,7 +135,7 @@ # if defined(TEST) || defined(TESTCI) void -resetConcurrencyTracking() +sentry_resetConcurrencyTracking() { std::lock_guard l(_gStateLock); [_gTracersToProfilers removeAllObjects]; @@ -143,7 +143,7 @@ } NSUInteger -currentProfiledTracers() +sentry_currentProfiledTracers() { std::lock_guard l(_gStateLock); return [_gTracersToProfilers count]; diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index f4a0af72ab..2e81dac467 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -70,7 +70,7 @@ SentryProfiler *_Nullable _gCurrentProfiler; NSString * -profilerTruncationReasonName(SentryProfilerTruncationReason reason) +sentry_profilerTruncationReasonName(SentryProfilerTruncationReason reason) { switch (reason) { case SentryProfilerTruncationReasonNormal: @@ -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; @@ -296,7 +296,7 @@ + (BOOL)startWithTracer:(SentryId *)traceId return NO; } - trackProfilerForTracer(_gCurrentProfiler, traceId); + sentry_trackProfilerForTracer(_gCurrentProfiler, traceId); return YES; } @@ -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; } @@ -384,13 +384,13 @@ + (void)updateProfilePayload:(NSMutableDictionary *)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 ); } @@ -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( [state](auto &backtrace) { // in test, we'll overwrite the sample's timestamp to one mocked by SentryCurrentDate @@ -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) diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 91e9add850..2494f01f8c 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -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 } diff --git a/Sources/Sentry/include/SentryProfiledTracerConcurrency.h b/Sources/Sentry/include/SentryProfiledTracerConcurrency.h index 68f1194d4d..b93358a6e9 100644 --- a/Sources/Sentry/include/SentryProfiledTracerConcurrency.h +++ b/Sources/Sentry/include/SentryProfiledTracerConcurrency.h @@ -14,13 +14,13 @@ 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 @@ -28,11 +28,11 @@ void discardProfilerForTracer(SentryId *internalTraceId); * 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 diff --git a/Sources/Sentry/include/SentryProfiler+Private.h b/Sources/Sentry/include/SentryProfiler+Private.h index aa1fd06af5..d37ddbd45e 100644 --- a/Sources/Sentry/include/SentryProfiler+Private.h +++ b/Sources/Sentry/include/SentryProfiler+Private.h @@ -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 @@ -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 /** diff --git a/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift b/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift index 0306569cd2..e7402cb906 100644 --- a/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift +++ b/Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift @@ -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") @@ -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) } @@ -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]) @@ -314,7 +314,7 @@ class SentryProfilerSwiftTests: XCTestCase { } XCTAssertFalse(SentryProfiler.isCurrentlyProfiling()) - XCTAssertEqual(SentryProfiler.currentProfiledTracers(), UInt(0)) + XCTAssertEqual(SentryProfiler.sentry_currentProfiledTracers(), UInt(0)) } try createConcurrentSpansWithMetrics() @@ -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) @@ -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) @@ -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)) } } diff --git a/Tests/SentryProfilerTests/SentryProfilerTests.mm b/Tests/SentryProfilerTests/SentryProfilerTests.mm index a0da151c13..89e39e6862 100644 --- a/Tests/SentryProfilerTests/SentryProfilerTests.mm +++ b/Tests/SentryProfilerTests/SentryProfilerTests.mm @@ -169,9 +169,9 @@ - (void)testProfilerMutationDuringSerialization // serialize the data as if it were captured in a transaction envelope const auto profileData = [state copyProfilingData]; - const auto serialization = serializedProfileData( - profileData, 1, 2, profilerTruncationReasonName(SentryProfilerTruncationReasonNormal), @{}, - @[], [[SentryHub alloc] initWithClient:nil andScope:nil] + const auto serialization = serializedProfileData(profileData, 1, 2, + sentry_profilerTruncationReasonName(SentryProfilerTruncationReasonNormal), @{}, @[], + [[SentryHub alloc] initWithClient:nil andScope:nil] # if SENTRY_HAS_UIKIT , [[SentryScreenFrames alloc] initWithTotal:5 diff --git a/Tests/SentryTests/SentryProfiler+Test.h b/Tests/SentryTests/SentryProfiler+Test.h index 6f57f36865..933a2411eb 100644 --- a/Tests/SentryTests/SentryProfiler+Test.h +++ b/Tests/SentryTests/SentryProfiler+Test.h @@ -23,9 +23,9 @@ NSMutableDictionary *serializedProfileData( + (SentryProfiler *)getCurrentProfiler; -+ (void)resetConcurrencyTracking; ++ (void)sentry_resetConcurrencyTracking; -+ (NSUInteger)currentProfiledTracers; ++ (NSUInteger)sentry_currentProfiledTracers; @end