-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/timber-sdk-version
- Loading branch information
Showing
22 changed files
with
565 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
sentry-android-core/src/main/java/io/sentry/android/core/AndroidMemoryCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.sentry.android.core; | ||
|
||
import android.os.Debug; | ||
import io.sentry.IMemoryCollector; | ||
import io.sentry.MemoryCollectionData; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
@ApiStatus.Internal | ||
public class AndroidMemoryCollector implements IMemoryCollector { | ||
@Override | ||
public MemoryCollectionData collect() { | ||
long now = System.currentTimeMillis(); | ||
long usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); | ||
long usedNativeMemory = Debug.getNativeHeapSize() - Debug.getNativeHeapFreeSize(); | ||
return new MemoryCollectionData(now, usedMemory, usedNativeMemory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
sentry-android-core/src/test/java/io/sentry/android/core/AndroidMemoryCollectorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.sentry.android.core | ||
|
||
import android.os.Debug | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotEquals | ||
import kotlin.test.assertNotNull | ||
|
||
class AndroidMemoryCollectorTest { | ||
|
||
private val fixture = Fixture() | ||
|
||
private class Fixture { | ||
val runtime: Runtime = Runtime.getRuntime() | ||
val collector = AndroidMemoryCollector() | ||
} | ||
|
||
@Test | ||
fun `when collect, both native and heap memory are collected`() { | ||
val usedNativeMemory = Debug.getNativeHeapSize() - Debug.getNativeHeapFreeSize() | ||
val usedMemory = fixture.runtime.totalMemory() - fixture.runtime.freeMemory() | ||
val data = fixture.collector.collect() | ||
assertNotNull(data) | ||
assertNotEquals(-1, data.usedNativeMemory) | ||
assertEquals(usedNativeMemory, data.usedNativeMemory) | ||
assertEquals(usedMemory, data.usedHeapMemory) | ||
assertNotEquals(0, data.timestamp) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.sentry; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** Used for collecting data about memory load when a transaction is active. */ | ||
@ApiStatus.Internal | ||
public interface IMemoryCollector { | ||
/** Used for collecting data about memory load when a transaction is active. */ | ||
@Nullable | ||
MemoryCollectionData collect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.sentry; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@ApiStatus.Internal | ||
public final class JavaMemoryCollector implements IMemoryCollector { | ||
|
||
private final @NotNull Runtime runtime = Runtime.getRuntime(); | ||
|
||
@Override | ||
public @Nullable MemoryCollectionData collect() { | ||
final long now = System.currentTimeMillis(); | ||
final long usedMemory = runtime.totalMemory() - runtime.freeMemory(); | ||
return new MemoryCollectionData(now, usedMemory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.sentry; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
@ApiStatus.Internal | ||
public final class MemoryCollectionData { | ||
final long timestamp; | ||
final long usedHeapMemory; | ||
final long usedNativeMemory; | ||
|
||
public MemoryCollectionData( | ||
final long timestamp, final long usedHeapMemory, final long usedNativeMemory) { | ||
this.timestamp = timestamp; | ||
this.usedHeapMemory = usedHeapMemory; | ||
this.usedNativeMemory = usedNativeMemory; | ||
} | ||
|
||
public MemoryCollectionData(final long timestamp, final long usedHeapMemory) { | ||
this(timestamp, usedHeapMemory, -1); | ||
} | ||
|
||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public long getUsedHeapMemory() { | ||
return usedHeapMemory; | ||
} | ||
|
||
public long getUsedNativeMemory() { | ||
return usedNativeMemory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.sentry; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@ApiStatus.Internal | ||
public final class NoOpMemoryCollector implements IMemoryCollector { | ||
|
||
private static final NoOpMemoryCollector instance = new NoOpMemoryCollector(); | ||
|
||
public static NoOpMemoryCollector getInstance() { | ||
return instance; | ||
} | ||
|
||
private NoOpMemoryCollector() {} | ||
|
||
@Override | ||
public @Nullable MemoryCollectionData collect() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.