Skip to content

Commit 1ab1f7e

Browse files
committed
use platform checker
1 parent e2d07f0 commit 1ab1f7e

3 files changed

Lines changed: 17 additions & 20 deletions

File tree

dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ class IoEnricherEventProcessor implements EnricherEventProcessor {
103103
}
104104

105105
SentryDevice _getDevice(SentryDevice? device) {
106-
final platformMemory = PlatformMemory(Platform.operatingSystem, _options);
106+
final platformMemory = PlatformMemory(_options);
107107
return (device ?? SentryDevice()).copyWith(
108108
name: device?.name ?? Platform.localHostname,
109109
processorCount: device?.processorCount ?? Platform.numberOfProcessors,
110-
memorySize: platformMemory.getTotalPhysicalMemory() ?? device?.memorySize,
111-
freeMemory: platformMemory.getFreePhysicalMemory() ?? device?.freeMemory,
110+
memorySize: device?.memorySize ?? platformMemory.getTotalPhysicalMemory(),
111+
freeMemory: device?.freeMemory ?? platformMemory.getFreePhysicalMemory(),
112112
);
113113
}
114114

dart/lib/src/event_processor/enricher/io_platform_memory.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,27 @@ import '../../sentry_options.dart';
66
// Get total & free platform memory (in bytes) for linux and windows operating systems.
77
// Source: https://github.com/onepub-dev/system_info/blob/8a9bf6b8eb7c86a09b3c3df4bf6d7fa5a6b50732/lib/src/platform/memory.dart
88
class PlatformMemory {
9-
PlatformMemory(this.operatingSystem, this.options);
9+
PlatformMemory(this.options);
1010

11-
final String operatingSystem;
1211
final SentryOptions options;
1312

1413
int? getTotalPhysicalMemory() {
15-
switch (operatingSystem) {
16-
case 'linux':
17-
return _getLinuxMemInfoValue('MemTotal');
18-
case 'windows':
19-
return _getWindowsWmicValue('ComputerSystem', 'TotalPhysicalMemory');
20-
default:
21-
return null;
14+
if (options.platformChecker.platform.isLinux) {
15+
return _getLinuxMemInfoValue('MemTotal');
16+
} else if (options.platformChecker.platform.isWindows) {
17+
return _getWindowsWmicValue('ComputerSystem', 'TotalPhysicalMemory');
18+
} else {
19+
return null;
2220
}
2321
}
2422

2523
int? getFreePhysicalMemory() {
26-
switch (operatingSystem) {
27-
case 'linux':
28-
return _getLinuxMemInfoValue('MemFree');
29-
case 'windows':
30-
return _getWindowsWmicValue('OS', 'FreePhysicalMemory');
31-
default:
32-
return null;
24+
if (options.platformChecker.platform.isLinux) {
25+
return _getLinuxMemInfoValue('MemFree');
26+
} else if (options.platformChecker.platform.isWindows) {
27+
return _getWindowsWmicValue('OS', 'FreePhysicalMemory');
28+
} else {
29+
return null;
3330
}
3431
}
3532

dart/test/event_processor/enricher/io_platform_memory_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ class Fixture {
5555
var options = SentryOptions();
5656

5757
PlatformMemory getSut() {
58-
return PlatformMemory(Platform.operatingSystem, options);
58+
return PlatformMemory(options);
5959
}
6060
}

0 commit comments

Comments
 (0)