Skip to content

Commit

Permalink
moved transaction data notifyFinish call later in the profiler, so th…
Browse files Browse the repository at this point in the history
…at the last transaction has the same timestamp of the profile
  • Loading branch information
stefanosiano committed Aug 12, 2022
1 parent a2058f1 commit 6a763b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,6 @@ public synchronized void onTransactionStart(@NotNull ITransaction transaction) {
return null;
}

// We notify the data referring to this transaction that it finished
ProfilingTransactionData transactionData =
transactionMap.get(transaction.getEventId().toString());
if (transactionData != null) {
transactionData.notifyFinish(SystemClock.elapsedRealtimeNanos(), transactionStartNanos);
}

if (transactionsCounter > 0) {
transactionsCounter--;
}
Expand All @@ -233,6 +226,12 @@ public synchronized void onTransactionStart(@NotNull ITransaction transaction) {
transactionsCounter);

if (transactionsCounter != 0 && !isTimeout) {
// We notify the data referring to this transaction that it finished
ProfilingTransactionData transactionData =
transactionMap.get(transaction.getEventId().toString());
if (transactionData != null) {
transactionData.notifyFinish(SystemClock.elapsedRealtimeNanos(), transactionStartNanos);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,21 @@ class EnvelopeTests : BaseUiTest() {
assertEquals(transaction3.eventId.toString(), transactionItem.eventId.toString())
assertEquals(profilingTraceData.transactionId, transactionItem.eventId.toString())
assertTrue(profilingTraceData.transactionName == "e2etests")

// Transaction timestamps should be all different from each other
val transactions = profilingTraceData.transactions
assertContains(transactions.map { t -> t.id }, transactionItem.eventId.toString())
val startTimes = transactions.map { t -> t.relativeStartNs }
val endTimes = transactions.map { t -> t.relativeEndNs }
assertEquals(0, startTimes[0])
val endTimes = transactions.mapNotNull { t -> t.relativeEndNs }
assertNotEquals(startTimes[0], startTimes[1])
assertNotEquals(startTimes[0], startTimes[2])
assertNotEquals(startTimes[1], startTimes[2])
assertNotEquals(0, endTimes[0])
assertNotEquals(endTimes[0], endTimes[1])
assertNotEquals(endTimes[0], endTimes[2])
assertNotEquals(endTimes[1], endTimes[2])

// The first and last transactions should be aligned to the start/stop of profile
assertEquals(endTimes.maxOrNull()!! - startTimes.minOrNull()!!, profilingTraceData.durationNs.toLong())
}
assertNoOtherEnvelopes()
assertNoOtherRequests()
Expand Down

0 comments on commit 6a763b7

Please sign in to comment.