Skip to content

Commit 062ca20

Browse files
authored
ref: Convert SentrySysctl to Swift (#6209)
1 parent 56d2052 commit 062ca20

File tree

11 files changed

+56
-16
lines changed

11 files changed

+56
-16
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@
542542
7BD729962463E83300EA3610 /* SentryDateUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BD729952463E83300EA3610 /* SentryDateUtil.h */; };
543543
7BD729982463E93500EA3610 /* SentryDateUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD729972463E93500EA3610 /* SentryDateUtil.m */; };
544544
7BD7299A2463EA4A00EA3610 /* SentryDateUtilTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD729992463EA4A00EA3610 /* SentryDateUtilTests.swift */; };
545-
7BD86EC5264A63F6005439DB /* SentrySysctl.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BD86EC4264A63F6005439DB /* SentrySysctl.h */; };
546-
7BD86EC7264A641D005439DB /* SentrySysctl.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD86EC6264A641D005439DB /* SentrySysctl.m */; };
545+
7BD86EC5264A63F6005439DB /* SentrySysctlObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BD86EC4264A63F6005439DB /* SentrySysctlObjC.h */; };
546+
7BD86EC7264A641D005439DB /* SentrySysctlObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD86EC6264A641D005439DB /* SentrySysctlObjC.m */; };
547547
7BD86ECB264A6DB5005439DB /* TestSysctl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD86ECA264A6DB5005439DB /* TestSysctl.swift */; };
548548
7BD86ECD264A78A6005439DB /* SentryAppStartTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD86ECC264A78A6005439DB /* SentryAppStartTrackerTests.swift */; };
549549
7BD86ECF264A7C77005439DB /* SentryAppStartMeasurement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BD86ECE264A7C77005439DB /* SentryAppStartMeasurement.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1118,6 +1118,7 @@
11181118
FACEED132E3179A10007B4AC /* SentyOptionsInternal.m in Sources */ = {isa = PBXBuildFile; fileRef = FACEED122E3179A10007B4AC /* SentyOptionsInternal.m */; };
11191119
FAE2DAB82E1F317900262307 /* SentryProfilingSwiftHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = FAE2DAB72E1F317900262307 /* SentryProfilingSwiftHelpers.m */; };
11201120
FAE2DABA2E1F318900262307 /* SentryProfilingSwiftHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE2DAB92E1F318900262307 /* SentryProfilingSwiftHelpers.h */; };
1121+
FAE5798D2E7D9D4C00B710F9 /* SentrySysctl.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */; };
11211122
FAE80C242E4695B40010A595 /* SentryEvent+Serialize.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE80C232E4695AE0010A595 /* SentryEvent+Serialize.h */; };
11221123
FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */; };
11231124
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
@@ -1818,8 +1819,8 @@
18181819
7BD729952463E83300EA3610 /* SentryDateUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDateUtil.h; path = include/SentryDateUtil.h; sourceTree = "<group>"; };
18191820
7BD729972463E93500EA3610 /* SentryDateUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDateUtil.m; sourceTree = "<group>"; };
18201821
7BD729992463EA4A00EA3610 /* SentryDateUtilTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDateUtilTests.swift; sourceTree = "<group>"; };
1821-
7BD86EC4264A63F6005439DB /* SentrySysctl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySysctl.h; path = include/SentrySysctl.h; sourceTree = "<group>"; };
1822-
7BD86EC6264A641D005439DB /* SentrySysctl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySysctl.m; sourceTree = "<group>"; };
1822+
7BD86EC4264A63F6005439DB /* SentrySysctlObjC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySysctlObjC.h; path = include/SentrySysctlObjC.h; sourceTree = "<group>"; };
1823+
7BD86EC6264A641D005439DB /* SentrySysctlObjC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySysctlObjC.m; sourceTree = "<group>"; };
18231824
7BD86ECA264A6DB5005439DB /* TestSysctl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSysctl.swift; sourceTree = "<group>"; };
18241825
7BD86ECC264A78A6005439DB /* SentryAppStartTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryAppStartTrackerTests.swift; sourceTree = "<group>"; };
18251826
7BD86ECE264A7C77005439DB /* SentryAppStartMeasurement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryAppStartMeasurement.h; path = include/HybridPublic/SentryAppStartMeasurement.h; sourceTree = "<group>"; };
@@ -2464,6 +2465,7 @@
24642465
FACEED122E3179A10007B4AC /* SentyOptionsInternal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentyOptionsInternal.m; sourceTree = "<group>"; };
24652466
FAE2DAB72E1F317900262307 /* SentryProfilingSwiftHelpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryProfilingSwiftHelpers.m; sourceTree = "<group>"; };
24662467
FAE2DAB92E1F318900262307 /* SentryProfilingSwiftHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryProfilingSwiftHelpers.h; path = Sources/Sentry/include/SentryProfilingSwiftHelpers.h; sourceTree = SOURCE_ROOT; };
2468+
FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySysctl.swift; sourceTree = "<group>"; };
24672469
FAE80C232E4695AE0010A595 /* SentryEvent+Serialize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryEvent+Serialize.h"; path = "include/SentryEvent+Serialize.h"; sourceTree = "<group>"; };
24682470
FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUserFeedback.swift; sourceTree = "<group>"; };
24692471
FAEC273C2DF3933200878871 /* NSData+Unzip.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Unzip.m"; sourceTree = "<group>"; };
@@ -2603,6 +2605,7 @@
26032605
621D9F2D2B9B030E003D94DE /* Helper */ = {
26042606
isa = PBXGroup;
26052607
children = (
2608+
FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */,
26062609
62CB19242E77F8FD00AF5DA2 /* SentryDispatchSourceWrapper.swift */,
26072610
FAEEC04C2E75E55A00E79CA9 /* SentrySerializationSwift.swift */,
26082611
FA94E7232E6F32FA00576666 /* SentryEnvelopeItemType.swift */,
@@ -2930,8 +2933,8 @@
29302933
FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */,
29312934
7B8ECBF926498906005FE2EF /* SentryAppStateManager.h */,
29322935
7B8ECBFB26498958005FE2EF /* SentryAppStateManager.m */,
2933-
7BD86EC4264A63F6005439DB /* SentrySysctl.h */,
2934-
7BD86EC6264A641D005439DB /* SentrySysctl.m */,
2936+
7BD86EC4264A63F6005439DB /* SentrySysctlObjC.h */,
2937+
7BD86EC6264A641D005439DB /* SentrySysctlObjC.m */,
29352938
D8479327278873A100BE8E99 /* SentryByteCountFormatter.h */,
29362939
D84793242788737D00BE8E99 /* SentryByteCountFormatter.m */,
29372940
7B2A70DA27D607CF008B0D15 /* SentryThreadWrapper.h */,
@@ -5127,7 +5130,7 @@
51275130
7B0DC72F288698F70039995F /* NSMutableDictionary+Sentry.h in Headers */,
51285131
63FE713920DA4C1100CDBAE8 /* SentryCrashMach.h in Headers */,
51295132
63EED6BE2237923600E02400 /* SentryOptions.h in Headers */,
5130-
7BD86EC5264A63F6005439DB /* SentrySysctl.h in Headers */,
5133+
7BD86EC5264A63F6005439DB /* SentrySysctlObjC.h in Headers */,
51315134
63BE85701ECEC6DE00DC44F5 /* SentryDateUtils.h in Headers */,
51325135
63FE709520DA4C1000CDBAE8 /* SentryCrashReportFilterBasic.h in Headers */,
51335136
D8B088B629C9E3FF00213258 /* SentryTracerConfiguration.h in Headers */,
@@ -5867,6 +5870,7 @@
58675870
D4CD2A812DE9F91900DA9F59 /* SentryRedactRegionType.swift in Sources */,
58685871
6344DDB11EC308E400D9160D /* SentryCrashInstallationReporter.m in Sources */,
58695872
84BA62272CAE2EEF0049F636 /* SentryUserFeedbackWidgetButtonView.swift in Sources */,
5873+
FAE5798D2E7D9D4C00B710F9 /* SentrySysctl.swift in Sources */,
58705874
D85596F3280580F10041FF8B /* SentryScreenshotIntegration.m in Sources */,
58715875
92ECD73E2E05AD320063EC10 /* SentryLogLevel.swift in Sources */,
58725876
92ECD7402E05AD580063EC10 /* SentryLogAttribute.swift in Sources */,
@@ -5933,7 +5937,7 @@
59335937
8EBF870926140D37001A6853 /* SentryPerformanceTracker.m in Sources */,
59345938
D865893029D6ECA7000BE151 /* SentryCrashBinaryImageCache.c in Sources */,
59355939
D859696B27BECD8F0036A46E /* SentryCoreDataTrackingIntegration.m in Sources */,
5936-
7BD86EC7264A641D005439DB /* SentrySysctl.m in Sources */,
5940+
7BD86EC7264A641D005439DB /* SentrySysctlObjC.m in Sources */,
59375941
84281C432A578E5600EE88F2 /* SentryProfilerState.mm in Sources */,
59385942
D859697327BECDD20036A46E /* SentryCoreDataSwizzling.m in Sources */,
59395943
FABB48B32E59310D0071397E /* SentryMeasurementValue.swift in Sources */,

Sources/Sentry/SentryAppStartTracker.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# import "SentryDefines.h"
88
# import "SentryFramesTracker.h"
99
# import "SentryLogC.h"
10-
# import "SentrySysctl.h"
1110
# import <PrivateSentrySDKOnly.h>
1211
# import <SentryDependencyContainer.h>
1312
# import <SentryInternalDefines.h>

Sources/Sentry/SentryAppStateManager.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#import "SentryCrashSysCtl.h"
22
#import "SentryDependencyContainer.h"
33
#import "SentryNotificationNames.h"
4-
#import "SentrySysctl.h"
54
#import <SentryAppStateManager.h>
65
#import <SentryFileManager.h>
76
#import <SentryOptions.h>

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#import <SentrySDK+Private.h>
2828
#import <SentrySwift.h>
2929
#import <SentrySwizzleWrapper.h>
30-
#import <SentrySysctl.h>
3130
#import <SentryThreadWrapper.h>
3231
#import <SentryTracer.h>
3332
#import <SentryUIViewControllerPerformanceTracker.h>

Sources/Sentry/SentrySysctl.m renamed to Sources/Sentry/SentrySysctlObjC.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#import "SentrySysctl.h"
1+
#import "SentrySysctlObjC.h"
22
#import "SentryCrashSysCtl.h"
33
#import "SentrySwift.h"
44
#import "SentryTime.h"
@@ -26,7 +26,7 @@ __used __attribute__((constructor(60000))) static void
2626
moduleInitializationTimestamp = [NSDate date];
2727
}
2828

29-
@implementation SentrySysctl
29+
@implementation SentrySysctlObjC
3030

3131
+ (void)load
3232
{

Sources/Sentry/include/SentryPrivate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#import "SentrySessionInternal.h"
4747
#import "SentrySpanDataKey.h"
4848
#import "SentrySpanOperation.h"
49+
#import "SentrySysctlObjC.h"
4950
#import "SentryTraceHeader.h"
5051
#import "SentryTraceOrigin.h"
5152
#import "SentryUser+Serialize.h"

Sources/Sentry/include/SentrySysctl.h renamed to Sources/Sentry/include/SentrySysctlObjC.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
NS_ASSUME_NONNULL_BEGIN
44

55
/**
6-
* A wrapper around sysctl for testability.
6+
* This needs to be in ObjC because it overrides the +load method
77
*/
8-
@interface SentrySysctl : NSObject
8+
@interface SentrySysctlObjC : NSObject
99

1010
/**
1111
* Returns the time the system was booted with a precision of microseconds.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@_implementationOnly import _SentryPrivate
2+
3+
/// A wrapper around sysctl for testability.
4+
@_spi(Private) @objc public class SentrySysctl: NSObject {
5+
6+
private let objcHelper = SentrySysctlObjC()
7+
8+
/// Returns the time the system was booted with a precision of microseconds.
9+
///
10+
/// @warning We must not send this information off device because Apple forbids that.
11+
/// We are allowed send the amount of time that has elapsed between events that occurred within the
12+
/// app though. For more information see
13+
/// https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api#4278394.
14+
@objc public var systemBootTimestamp: Date {
15+
objcHelper.systemBootTimestamp
16+
}
17+
18+
@objc public var processStartTimestamp: Date {
19+
objcHelper.processStartTimestamp
20+
}
21+
22+
/// The system time that the process started, as measured in @c SentrySysctl.load, essentially the
23+
/// earliest time we can record a system timestamp, which is the number of nanoseconds since the
24+
/// device booted, which is why we can't simply convert @c processStartTimestamp to the nanosecond
25+
/// representation of its @c timeIntervalSinceReferenceDate .
26+
@objc public var runtimeInitSystemTimestamp: UInt64 {
27+
objcHelper.runtimeInitSystemTimestamp
28+
}
29+
30+
@objc public var runtimeInitTimestamp: Date {
31+
objcHelper.runtimeInitTimestamp
32+
}
33+
34+
@objc public var moduleInitializationTimestamp: Date {
35+
objcHelper.moduleInitializationTimestamp
36+
}
37+
}

Tests/SentryTests/Helper/SentrySysctlTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@_spi(Private) import Sentry
12
import XCTest
23

34
class SentrySysctlTests: XCTestCase {

Tests/SentryTests/Helper/TestSysctl.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
@_spi(Private) @testable import Sentry
23

34
class TestSysctl: SentrySysctl {
45

0 commit comments

Comments
 (0)