Skip to content

Commit

Permalink
Merge da4c1b2 into 081ee0b
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Sep 13, 2023
2 parents 081ee0b + da4c1b2 commit 5c548d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Add `sendModules` option for disable sending modules ([#2926](https://github.com/getsentry/sentry-java/pull/2926))
- Send `db.system` and `db.name` in span data for androidx.sqlite spans ([#2928](https://github.com/getsentry/sentry-java/pull/2928))

### Fixes

- Always send memory stats for transactions ([#2936](https://github.com/getsentry/sentry-java/pull/2936))
- This makes it possible to query transactions by the `device.class` tag on Sentry

### Dependencies

- Bump Gradle from v8.2.1 to v8.3.0 ([#2900](https://github.com/getsentry/sentry-java/pull/2900))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public final class DeviceInfoUtil {
private final @Nullable ContextUtils.SideLoadedInfo sideLoadedInfo;
private final @NotNull OperatingSystem os;

private final @Nullable Long totalMem;

public DeviceInfoUtil(
final @NotNull Context context, final @NotNull SentryAndroidOptions options) {
this.context = context;
Expand All @@ -59,6 +61,13 @@ public DeviceInfoUtil(
isEmulator = buildInfoProvider.isEmulator();
sideLoadedInfo =
ContextUtils.retrieveSideLoadedInfo(context, options.getLogger(), buildInfoProvider);
final @Nullable ActivityManager.MemoryInfo memInfo =
ContextUtils.getMemInfo(context, options.getLogger());
if (memInfo != null) {
totalMem = getMemorySize(memInfo);
} else {
totalMem = null;
}
}

@NotNull
Expand Down Expand Up @@ -132,6 +141,8 @@ public Device collectDeviceInformation(
device.setProcessorCount(cpuFrequencies.size());
}

device.setMemorySize(totalMem);

// setting such values require IO hence we don't run for transactions
if (collectDeviceIO && options.isCollectAdditionalContext()) {
setDeviceIO(device, collectDynamicData);
Expand Down Expand Up @@ -193,16 +204,11 @@ private void setDeviceIO(final @NotNull Device device, final boolean includeDyna
device.setOnline(connected);

final @Nullable ActivityManager.MemoryInfo memInfo =
ContextUtils.getMemInfo(context, options.getLogger());
if (memInfo != null) {
// in bytes
device.setMemorySize(getMemorySize(memInfo));
if (includeDynamicData) {
ContextUtils.getMemInfo(context, options.getLogger());
if (memInfo != null && includeDynamicData) {
// in bytes
device.setFreeMemory(memInfo.availMem);
device.setLowMemory(memInfo.lowMemory);
}
// there are runtime.totalMemory() and runtime.freeMemory(), but I kept the same for
// compatibility
}

// this way of getting the size of storage might be problematic for storages bigger than 2GB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DeviceInfoUtilTest {
}

@Test
fun `provides os and sideloaded info`() {
fun `provides os, memory and sideloaded info`() {
val deviceInfoUtil = DeviceInfoUtil.getInstance(context, SentryAndroidOptions())

val os = deviceInfoUtil.operatingSystem
Expand All @@ -48,6 +48,7 @@ class DeviceInfoUtilTest {
assertNotNull(sideLoadedInfo.isSideLoaded)

assertNotNull(deviceInfo.isSimulator)
assertNotNull(deviceInfo.memorySize)
}

@Test
Expand Down Expand Up @@ -106,7 +107,6 @@ class DeviceInfoUtilTest {
val deviceInfoUtil = DeviceInfoUtil.getInstance(context, options)
val deviceInfo = deviceInfoUtil.collectDeviceInformation(false, false)

assertNull(deviceInfo.memorySize)
assertNull(deviceInfo.storageSize)
assertNull(deviceInfo.freeStorage)
}
Expand Down

0 comments on commit 5c548d8

Please sign in to comment.