Skip to content

Commit b25ea04

Browse files
authored
Merge ac876d4 into c34791a
2 parents c34791a + ac876d4 commit b25ea04

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

sentry-android-core/src/main/java/io/sentry/android/core/AndroidCpuCollector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.sentry.util.Objects;
1515
import java.io.File;
1616
import java.io.IOException;
17+
import java.util.regex.Pattern;
1718
import org.jetbrains.annotations.ApiStatus;
1819
import org.jetbrains.annotations.NotNull;
1920

@@ -42,6 +43,7 @@ public final class AndroidCpuCollector implements IPerformanceSnapshotCollector
4243
private final @NotNull ILogger logger;
4344
private final @NotNull BuildInfoProvider buildInfoProvider;
4445
private boolean isEnabled = false;
46+
private final @NotNull Pattern newLinePattern = Pattern.compile("[\n\t\r ]");
4547

4648
public AndroidCpuCollector(
4749
final @NotNull ILogger logger, final @NotNull BuildInfoProvider buildInfoProvider) {
@@ -102,7 +104,7 @@ private long readTotalCpuNanos() {
102104
}
103105
if (stat != null) {
104106
stat = stat.trim();
105-
String[] stats = stat.split("[\n\t\r ]");
107+
String[] stats = newLinePattern.split(stat);
106108
try {
107109
// Amount of clock ticks this process has been scheduled in user mode
108110
long uTime = Long.parseLong(stats[13]);

sentry/src/main/java/io/sentry/DefaultTransactionPerformanceCollector.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class DefaultTransactionPerformanceCollector
2828

2929
private final @NotNull SentryOptions options;
3030
private final @NotNull AtomicBoolean isStarted = new AtomicBoolean(false);
31+
private long lastCollectionTimestamp = 0;
3132

3233
public DefaultTransactionPerformanceCollector(final @NotNull SentryOptions options) {
3334
this.options = Objects.requireNonNull(options, "The options object is required.");
@@ -104,6 +105,14 @@ public void run() {
104105
new TimerTask() {
105106
@Override
106107
public void run() {
108+
long now = System.currentTimeMillis();
109+
// The timer is scheduled to run every 100ms on average. In case it takes longer,
110+
// subsequent tasks are executed more quickly. If two tasks are scheduled to run in
111+
// less than 10ms, the measurement that we collect is not meaningful, so we skip it
112+
if (now - lastCollectionTimestamp < 10) {
113+
return;
114+
}
115+
lastCollectionTimestamp = now;
107116
final @NotNull PerformanceCollectionData tempData = new PerformanceCollectionData();
108117

109118
for (IPerformanceSnapshotCollector collector : snapshotCollectors) {

0 commit comments

Comments
 (0)