Skip to content

Commit 94de2d3

Browse files
authored
chore: Convert SentryFramesTracker to Swift (#6447)
* chore: Convert SentryFramesTracker to Swift * Move slowFrameThreshold into SentryFramesTracker * Fix build in SPM * Fix build in macOS * Fix SPM build * Updatye RN branch * Fix merge issue
1 parent aa643c5 commit 94de2d3

36 files changed

+514
-560
lines changed

.github/workflows/test-cross-platform.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
with:
5656
repository: getsentry/sentry-react-native
5757
path: sentry-react-native
58-
ref: denrase/options-enable-logs
58+
ref: itay/frames_tracker_swift
5959

6060
- name: Enable Corepack
6161
working-directory: sentry-react-native

Sentry.xcodeproj/project.pbxproj

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@
409409
7B6C5ED6264E62CA0010D138 /* SentryTransactionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6C5ED5264E62CA0010D138 /* SentryTransactionTests.swift */; };
410410
7B6C5EDA264E8D860010D138 /* SentryFramesTrackingIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6C5ED9264E8D860010D138 /* SentryFramesTrackingIntegration.h */; };
411411
7B6C5EDC264E8DA80010D138 /* SentryFramesTrackingIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B6C5EDB264E8DA80010D138 /* SentryFramesTrackingIntegration.m */; };
412-
7B6C5EDE264E8DF00010D138 /* SentryFramesTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B6C5EDD264E8DF00010D138 /* SentryFramesTracker.m */; };
413-
7B6C5EE0264E8E050010D138 /* SentryFramesTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6C5EDF264E8E050010D138 /* SentryFramesTracker.h */; settings = {ATTRIBUTES = (Private, ); }; };
414412
7B6C5F8126034354007F7DFF /* SentryWatchdogTerminationLogic.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B6C5F8026034354007F7DFF /* SentryWatchdogTerminationLogic.h */; };
415413
7B6C5F8726034395007F7DFF /* SentryWatchdogTerminationLogic.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B6C5F8626034395007F7DFF /* SentryWatchdogTerminationLogic.m */; };
416414
7B6CC50224EE5A42001816D7 /* SentryHubTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6CC50124EE5A42001816D7 /* SentryHubTests.swift */; };
@@ -986,6 +984,8 @@
986984
D8F8F5572B835BC600AC5465 /* SentryMsgPackSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D8F8F5562B835BC600AC5465 /* SentryMsgPackSerializerTests.m */; };
987985
D8FC98AB2CD0DAB30009824C /* BreadcrumbExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8FC98AA2CD0DAAC0009824C /* BreadcrumbExtension.swift */; };
988986
D8FFE50C2703DBB400607131 /* SwizzlingCallTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8FFE50B2703DAAE00607131 /* SwizzlingCallTests.swift */; };
987+
F40E42352EA1887000E53876 /* SentryFramesTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40E42342EA1887000E53876 /* SentryFramesTracker.swift */; };
988+
F40E423C2EA18E8000E53876 /* SentryDelayedFramesTrackerWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40E423B2EA18E8000E53876 /* SentryDelayedFramesTrackerWrapper.swift */; };
989989
F41362112E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362102E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift */; };
990990
F41362132E1C566100B84443 /* SentryScopePersistentStore+User.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362122E1C566100B84443 /* SentryScopePersistentStore+User.swift */; };
991991
F41362152E1C568400B84443 /* SentryScopePersistentStore+Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362142E1C568400B84443 /* SentryScopePersistentStore+Context.swift */; };
@@ -1635,7 +1635,6 @@
16351635
7B2BB0012966F55900A1E102 /* SentryOptionsInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryOptionsInternal.h; path = include/HybridPublic/SentryOptionsInternal.h; sourceTree = "<group>"; };
16361636
7B30B67F26527C3C006B2752 /* SentryFramesTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFramesTrackerTests.swift; sourceTree = "<group>"; };
16371637
7B30B68126527C55006B2752 /* TestDisplayLinkWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDisplayLinkWrapper.swift; sourceTree = "<group>"; };
1638-
7B30B6882653AEA8006B2752 /* SentryFramesTracker+TestInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryFramesTracker+TestInit.h"; sourceTree = "<group>"; };
16391638
7B31C290277B04A000337126 /* SentryCrashPlatformSpecificDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryCrashPlatformSpecificDefines.h; sourceTree = "<group>"; };
16401639
7B3398622459C14000BD9C96 /* SentryEnvelopeRateLimit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeRateLimit.h; path = include/SentryEnvelopeRateLimit.h; sourceTree = "<group>"; };
16411640
7B3398642459C15200BD9C96 /* SentryEnvelopeRateLimit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryEnvelopeRateLimit.m; sourceTree = "<group>"; };
@@ -1691,8 +1690,6 @@
16911690
7B6C5ED5264E62CA0010D138 /* SentryTransactionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTransactionTests.swift; sourceTree = "<group>"; };
16921691
7B6C5ED9264E8D860010D138 /* SentryFramesTrackingIntegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryFramesTrackingIntegration.h; path = include/SentryFramesTrackingIntegration.h; sourceTree = "<group>"; };
16931692
7B6C5EDB264E8DA80010D138 /* SentryFramesTrackingIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryFramesTrackingIntegration.m; sourceTree = "<group>"; };
1694-
7B6C5EDD264E8DF00010D138 /* SentryFramesTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryFramesTracker.m; sourceTree = "<group>"; };
1695-
7B6C5EDF264E8E050010D138 /* SentryFramesTracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryFramesTracker.h; path = include/HybridPublic/SentryFramesTracker.h; sourceTree = "<group>"; };
16961693
7B6C5F8026034354007F7DFF /* SentryWatchdogTerminationLogic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryWatchdogTerminationLogic.h; path = include/SentryWatchdogTerminationLogic.h; sourceTree = "<group>"; };
16971694
7B6C5F8626034395007F7DFF /* SentryWatchdogTerminationLogic.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryWatchdogTerminationLogic.m; sourceTree = "<group>"; };
16981695
7B6CC50124EE5A42001816D7 /* SentryHubTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryHubTests.swift; sourceTree = "<group>"; };
@@ -2350,6 +2347,8 @@
23502347
D8F8F5562B835BC600AC5465 /* SentryMsgPackSerializerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMsgPackSerializerTests.m; sourceTree = "<group>"; };
23512348
D8FC98AA2CD0DAAC0009824C /* BreadcrumbExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BreadcrumbExtension.swift; sourceTree = "<group>"; };
23522349
D8FFE50B2703DAAE00607131 /* SwizzlingCallTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwizzlingCallTests.swift; sourceTree = "<group>"; };
2350+
F40E42342EA1887000E53876 /* SentryFramesTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFramesTracker.swift; sourceTree = "<group>"; };
2351+
F40E423B2EA18E8000E53876 /* SentryDelayedFramesTrackerWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDelayedFramesTrackerWrapper.swift; sourceTree = "<group>"; };
23532352
F41362102E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+Tags.swift"; sourceTree = "<group>"; };
23542353
F41362122E1C566100B84443 /* SentryScopePersistentStore+User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+User.swift"; sourceTree = "<group>"; };
23552354
F41362142E1C568400B84443 /* SentryScopePersistentStore+Context.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+Context.swift"; sourceTree = "<group>"; };
@@ -3713,8 +3712,6 @@
37133712
children = (
37143713
7B6C5ED9264E8D860010D138 /* SentryFramesTrackingIntegration.h */,
37153714
7B6C5EDB264E8DA80010D138 /* SentryFramesTrackingIntegration.m */,
3716-
7B6C5EDF264E8E050010D138 /* SentryFramesTracker.h */,
3717-
7B6C5EDD264E8DF00010D138 /* SentryFramesTracker.m */,
37183715
62862B1B2B1DDBC8009B16E3 /* SentryDelayedFrame.h */,
37193716
62862B1D2B1DDC35009B16E3 /* SentryDelayedFrame.m */,
37203717
62C316802B1F2E93000D7031 /* SentryDelayedFramesTracker.h */,
@@ -3859,7 +3856,6 @@
38593856
children = (
38603857
7B5B94342657AD21002E474B /* SentryFramesTrackingIntegrationTests.swift */,
38613858
7B30B67F26527C3C006B2752 /* SentryFramesTrackerTests.swift */,
3862-
7B30B6882653AEA8006B2752 /* SentryFramesTracker+TestInit.h */,
38633859
);
38643860
path = FramesTracking;
38653861
sourceTree = "<group>";
@@ -4883,6 +4879,8 @@
48834879
FA67DCD22DDBD4EA00896B02 /* FramesTracking */ = {
48844880
isa = PBXGroup;
48854881
children = (
4882+
F40E423B2EA18E8000E53876 /* SentryDelayedFramesTrackerWrapper.swift */,
4883+
F40E42342EA1887000E53876 /* SentryFramesTracker.swift */,
48864884
F44D2B582E6B779E00FF31FA /* SentryScreenFrames.swift */,
48874885
FA67DCD12DDBD4EA00896B02 /* SentryFramesDelayResult.swift */,
48884886
);
@@ -5165,7 +5163,6 @@
51655163
FAF120182E70C08F006E1DA3 /* SentryEnvelopeHeaderHelper.h in Headers */,
51665164
62A456E12B03704A003F19A1 /* SentryUIEventTrackerMode.h in Headers */,
51675165
03F84D2327DD414C008FE43F /* SentryThreadHandle.hpp in Headers */,
5168-
7B6C5EE0264E8E050010D138 /* SentryFramesTracker.h in Headers */,
51695166
84A305572BC9EF8C00D84283 /* SentryTraceProfiler.h in Headers */,
51705167
FA034AC82DD3DB4900FE3107 /* SentryIntegrationProtocol.h in Headers */,
51715168
63FE715720DA4C1100CDBAE8 /* SentryCrashThread.h in Headers */,
@@ -5684,7 +5681,6 @@
56845681
F48F78692E61DE28009D4E7D /* SentryReachability.swift in Sources */,
56855682
D8739D142BEE5049007D2F66 /* SentryRRWebSpanEvent.swift in Sources */,
56865683
FAAB2F972E4D345800FE8B7E /* SentryUIDeviceWrapper.swift in Sources */,
5687-
7B6C5EDE264E8DF00010D138 /* SentryFramesTracker.m in Sources */,
56885684
D84F833E2A1CC401005828E0 /* SentrySwiftAsyncIntegration.m in Sources */,
56895685
7B6438AB26A70F24000D0F65 /* UIViewController+Sentry.m in Sources */,
56905686
84302A812B5767A50027A629 /* SentryLaunchProfiling.m in Sources */,
@@ -5765,6 +5761,7 @@
57655761
D81988C02BEBFFF70020E36C /* SentryReplayRecording.swift in Sources */,
57665762
7B6C5F8726034395007F7DFF /* SentryWatchdogTerminationLogic.m in Sources */,
57675763
63FE708D20DA4C1000CDBAE8 /* SentryCrashReportFilterBasic.m in Sources */,
5764+
F40E42352EA1887000E53876 /* SentryFramesTracker.swift in Sources */,
57685765
63FE718120DA4C1100CDBAE8 /* SentryCrashDoctor.m in Sources */,
57695766
63FE713720DA4C1100CDBAE8 /* SentryCrashCPU_x86_64.c in Sources */,
57705767
8ECC674725C23A20000E2BF6 /* SentrySpanContext.m in Sources */,
@@ -5914,6 +5911,7 @@
59145911
A8F17B2E2901765900990B25 /* SentryRequest.m in Sources */,
59155912
FABE8E172E307A7F0040809A /* Dependencies.swift in Sources */,
59165913
D4ECA4012E3CBEDE00C757EA /* SentryDummyPublicEmptyClass.m in Sources */,
5914+
F40E423C2EA18E8000E53876 /* SentryDelayedFramesTrackerWrapper.swift in Sources */,
59175915
F44D2B592E6B779E00FF31FA /* SentryScreenFrames.swift in Sources */,
59185916
D4ECA4022E3CBEDE00C757EA /* SentryDummyPrivateEmptyClass.m in Sources */,
59195917
D80299502BA83A88000F0081 /* SentryPixelBuffer.swift in Sources */,

SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#if SENTRY_HAS_UIKIT
1010
# import "SentryAppStartTracker.h"
1111
# import "SentryDefaultUIViewControllerPerformanceTracker.h"
12-
# import "SentryFramesTracker+TestInit.h"
1312
#endif // SENTRY_HAS_UIKIT
1413

1514
#import "SentryProfilingConditionals.h"

SentryTestUtils/TestDisplayLinkWrapper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ public enum FrameRate: UInt64 {
8787
}
8888

8989
public func fastestSlowFrame() -> CFTimeInterval {
90-
let duration: Double = slowFrameThreshold(currentFrameRate.rawValue) + timeEpsilon
90+
let duration: Double = SentryFramesTracker.slowFrameThreshold(currentFrameRate.rawValue) + timeEpsilon
9191
dateProvider.advance(by: duration)
9292
call()
9393
return duration
9494
}
9595

9696
public func middlingSlowFrameDuration() -> CFTimeInterval {
97-
(frozenFrameThreshold - (slowFrameThreshold(currentFrameRate.rawValue) + timeEpsilon)) / 2.0
97+
(frozenFrameThreshold - (SentryFramesTracker.slowFrameThreshold(currentFrameRate.rawValue) + timeEpsilon)) / 2.0
9898
}
9999

100100
public func middlingSlowFrame() -> CFTimeInterval {

SentryTestUtils/TestFramesTracker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@_spi(Private) @testable import Sentry
22

33
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
4-
public class TestFramesTracker: SentryFramesTracker {
4+
@_spi(Private) public class TestFramesTracker: SentryFramesTracker {
55
@_spi(Private) public var expectedFrames: SentryScreenFrames?
66

77
@_spi(Private) public override func currentFrames() -> SentryScreenFrames {

Sources/Resources/Sentry.modulemap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ framework module Sentry {
1313
header "SentryDebugImageProvider+HybridSDKs.h"
1414
header "SentryDependencyContainer.h"
1515
header "SentryFormatter.h"
16-
header "SentryFramesTracker.h"
1716
header "SentryOptionsInternal.h"
1817
header "SentrySwizzle.h"
1918
header "SentryUser+Private.h"

Sources/Sentry/PrivateSentrySDKOnly.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#import "SentryUser+Private.h"
1919
#import <SentryBreadcrumb.h>
2020
#import <SentryDependencyContainer.h>
21-
#import <SentryFramesTracker.h>
2221
#import <SentryScope+Private.h>
2322
#import <SentryUser.h>
2423

Sources/Sentry/Profiling/SentryContinuousProfiler.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
# include <mutex>
1717

1818
# if SENTRY_HAS_UIKIT
19-
# import "SentryFramesTracker.h"
2019
# import <UIKit/UIKit.h>
2120
# endif // SENTRY_HAS_UIKIT
2221

2322
# pragma mark - Private
2423

24+
NSString *const kSentryNotificationContinuousProfileStarted
25+
= @"io.sentry.notification.continuous-profile-started";
26+
2527
NSTimeInterval kSentryProfilerChunkExpirationInterval = 60;
2628

2729
namespace {
@@ -71,10 +73,9 @@
7173
[profiler.metricProfiler clear];
7274

7375
# if SENTRY_HAS_UIKIT
74-
const auto framesTracker = SentryDependencyContainer.sharedInstance.framesTracker;
7576
SentryScreenFrames *screenFrameData =
76-
[SentryProfilingScreenFramesHelper copyScreenFrames:framesTracker.currentFrames];
77-
[framesTracker resetProfilingTimestamps];
77+
[SentryProfilingScreenFramesHelper copyScreenFrames:sentry_framesTrackerGetCurrentFrames()];
78+
sentry_framesTrackerResetProfilingTimestamps();
7879
# endif // SENTRY_HAS_UIKIT
7980

8081
// Capture profiler ID on main thread since we need it for the background work

Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
# if SENTRY_HAS_UIKIT
3131
# import "SentryAppStartMeasurement.h"
32-
# import "SentryFramesTracker.h"
3332
# import "SentryProfilingScreenFramesHelper.h"
3433
# endif // SENTRY_HAS_UIKIT
3534

@@ -210,7 +209,7 @@
210209
@"initialized by the time they are being queried");
211210
}
212211
if (_gProfilersToTracers.count == 0) {
213-
[SentryDependencyContainer.sharedInstance.framesTracker resetProfilingTimestamps];
212+
sentry_framesTrackerResetProfilingTimestamps();
214213
}
215214
# endif // SENTRY_HAS_UIKIT
216215
}
@@ -237,13 +236,13 @@
237236
_unsafe_cleanUpTraceProfiler(profiler, tracerKey);
238237

239238
# if SENTRY_HAS_UIKIT
240-
profiler.screenFrameData = [SentryProfilingScreenFramesHelper
241-
copyScreenFrames:SentryDependencyContainer.sharedInstance.framesTracker.currentFrames];
239+
profiler.screenFrameData =
240+
[SentryProfilingScreenFramesHelper copyScreenFrames:sentry_framesTrackerGetCurrentFrames()];
242241
SENTRY_LOG_DEBUG(
243242
@"Grabbing copy of frames tracker screen frames data to attach to profiler: %@.",
244243
profiler.screenFrameData);
245244
if (_gProfilersToTracers.count == 0) {
246-
[SentryDependencyContainer.sharedInstance.framesTracker resetProfilingTimestamps];
245+
sentry_framesTrackerResetProfilingTimestamps();
247246
}
248247
# endif // SENTRY_HAS_UIKIT
249248

Sources/Sentry/Profiling/SentryProfilingSwiftHelpers.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,29 @@
166166
repeats:repeats];
167167
}
168168

169+
# if SENTRY_HAS_UIKIT
170+
void
171+
sentry_startFramesTracker(void)
172+
{
173+
[SentryDependencyContainer.sharedInstance.framesTracker start];
174+
}
175+
176+
void
177+
sentry_stopFramesTracker(void)
178+
{
179+
[SentryDependencyContainer.sharedInstance.framesTracker stop];
180+
}
181+
182+
void
183+
sentry_framesTrackerResetProfilingTimestamps(void)
184+
{
185+
[SentryDependencyContainer.sharedInstance.framesTracker resetProfilingTimestamps];
186+
}
187+
188+
SentryScreenFrames *
189+
sentry_framesTrackerGetCurrentFrames(void)
190+
{
191+
return [SentryDependencyContainer.sharedInstance.framesTracker currentFrames];
192+
}
193+
# endif // SENTRY_HAS_UIKIT
169194
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

0 commit comments

Comments
 (0)