diff --git a/CHANGELOG.md b/CHANGELOG.md index b049066a0a1..09eefa60fb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 8.3.2 +### Features + +- Add CPU core count in device context (#2814) + ### Fixes - Updating AppHang state on main thread (#2793) diff --git a/Sources/Sentry/SentryClient.m b/Sources/Sentry/SentryClient.m index 03145d8467e..c9c962a3d17 100644 --- a/Sources/Sentry/SentryClient.m +++ b/Sources/Sentry/SentryClient.m @@ -31,6 +31,7 @@ #import "SentryMessage.h" #import "SentryMeta.h" #import "SentryNSError.h" +#import "SentryNSProcessInfoWrapper.h" #import "SentryOptions+Private.h" #import "SentrySDK+Private.h" #import "SentryScope+Private.h" @@ -63,6 +64,7 @@ @property (nonatomic, strong) SentryUIDeviceWrapper *deviceWrapper; @property (nonatomic, strong) NSLocale *locale; @property (nonatomic, strong) NSTimeZone *timezone; +@property (nonatomic, strong) SentryNSProcessInfoWrapper *processInfoWrapper; @end @@ -171,6 +173,7 @@ - (instancetype)initWithOptions:(SentryOptions *)options self.timezone = timezone; self.attachmentProcessors = [[NSMutableArray alloc] init]; self.deviceWrapper = deviceWrapper; + self.processInfoWrapper = [[SentryNSProcessInfoWrapper alloc] init]; if (deleteOldEnvelopeItems) { [fileManager deleteOldEnvelopeItems]; @@ -794,6 +797,7 @@ - (void)applyExtraDeviceContextToEvent:(SentryEvent *)event block:^(NSMutableDictionary *device) { device[SentryDeviceContextFreeMemoryKey] = @(self.crashWrapper.freeMemorySize); device[@"free_storage"] = @(self.crashWrapper.freeStorageSize); + device[@"processor_count"] = @([self.processInfoWrapper processorCount]); #if TARGET_OS_IOS if (self.deviceWrapper.orientation != UIDeviceOrientationUnknown) { diff --git a/Tests/SentryTests/SentryClientTests.swift b/Tests/SentryTests/SentryClientTests.swift index bca1f80c621..4d91e2d19c1 100644 --- a/Tests/SentryTests/SentryClientTests.swift +++ b/Tests/SentryTests/SentryClientTests.swift @@ -607,9 +607,14 @@ class SentryClientTest: XCTestCase { } } - func testCaptureEvent_AddCurrentMemoryAndStorage() { + func testCaptureEvent_AddCurrentMemoryStorageAndCPUCoreCount() { - fixture.getSut().capture(event: TestData.event) + let sut = fixture.getSut() + let testProcessWrapper = TestSentryNSProcessInfoWrapper() + testProcessWrapper.overrides.processorCount = 12 + Dynamic(sut).processInfoWrapper = testProcessWrapper + + sut.capture(event: TestData.event) assertLastSentEvent { actual in let eventFreeMemory = actual.context?["device"]?[SentryDeviceContextFreeMemoryKey] as? Int @@ -620,6 +625,9 @@ class SentryClientTest: XCTestCase { let eventFreeStorage = actual.context?["device"]?["free_storage"] as? Int XCTAssertEqual(eventFreeStorage, 345_678) + + let cpuCoreCount = actual.context?["device"]?["processor_count"] as? UInt + XCTAssertEqual(testProcessWrapper.processorCount, cpuCoreCount) } }