Skip to content

Commit

Permalink
feat: Add CPU Core count in device context (#2814)
Browse files Browse the repository at this point in the history
Added the amount of CPU cores in the device context.
  • Loading branch information
brustolin committed Mar 21, 2023
1 parent cbf6225 commit ea73af6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 8.3.2

### Features

- Add CPU core count in device context (#2814)

### Fixes

- Updating AppHang state on main thread (#2793)
Expand Down
4 changes: 4 additions & 0 deletions Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions Tests/SentryTests/SentryClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}

Expand Down

0 comments on commit ea73af6

Please sign in to comment.