Skip to content

Commit

Permalink
Merge 50b8aa3 into 0810952
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanosiano authored Dec 19, 2023
2 parents 0810952 + 50b8aa3 commit 1da0e4d
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 196 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Early profiling 1 - Decouple Profiler from Transaction ([#3101](https://github.com/getsentry/sentry-java/pull/3101))

## 7.1.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ProfileEndData(
private static final int BUFFER_SIZE_BYTES = 3_000_000;

private static final int PROFILING_TIMEOUT_MILLIS = 30_000;
private long transactionStartNanos = 0;
private long profileStartNanos = 0;
private final @NotNull File traceFilesDir;
private final int intervalUs;
private @Nullable Future<?> scheduledFinish = null;
Expand Down Expand Up @@ -150,14 +150,14 @@ public void onFrameMetricCollected(
final boolean isSlow,
final boolean isFrozen,
final float refreshRate) {
// transactionStartNanos is calculated through SystemClock.elapsedRealtimeNanos(),
// profileStartNanos is calculated through SystemClock.elapsedRealtimeNanos(),
// but frameEndNanos uses System.nanotime(), so we convert it to get the timestamp
// relative to transactionStartNanos
// relative to profileStartNanos
final long frameTimestampRelativeNanos =
frameEndNanos
- System.nanoTime()
+ SystemClock.elapsedRealtimeNanos()
- transactionStartNanos;
- profileStartNanos;

// We don't allow negative relative timestamps.
// So we add a check, even if this should never happen.
Expand Down Expand Up @@ -191,7 +191,7 @@ public void onFrameMetricCollected(
e);
}

transactionStartNanos = SystemClock.elapsedRealtimeNanos();
profileStartNanos = SystemClock.elapsedRealtimeNanos();
long profileStartCpuMillis = Process.getElapsedCpuTime();

// We don't make any check on the file existence or writeable state, because we don't want to
Expand All @@ -203,7 +203,7 @@ public void onFrameMetricCollected(
// tests)
Debug.startMethodTracingSampling(traceFile.getPath(), BUFFER_SIZE_BYTES, intervalUs);
isRunning = true;
return new ProfileStartData(transactionStartNanos, profileStartCpuMillis);
return new ProfileStartData(profileStartNanos, profileStartCpuMillis);
} catch (Throwable e) {
endAndCollect(false, null);
logger.log(SentryLevel.ERROR, "Unable to start a profile: ", e);
Expand Down Expand Up @@ -304,7 +304,7 @@ private void putPerformanceCollectionDataInMeasurements(
// the beginning, expressed with SystemClock.elapsedRealtimeNanos()
long timestampDiff =
SystemClock.elapsedRealtimeNanos()
- transactionStartNanos
- profileStartNanos
- TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
if (performanceCollectionData != null) {
final @NotNull ArrayDeque<ProfileMeasurementValue> memoryUsageMeasurements =
Expand Down
Loading

0 comments on commit 1da0e4d

Please sign in to comment.