From 4218e5ffca28c7cf4233a9fa79ad6b0a540e6b8d Mon Sep 17 00:00:00 2001 From: Vishal Ratna Date: Thu, 24 Feb 2022 14:33:01 +0530 Subject: [PATCH] Fix issue with splits. The split state was not getting recycled as it was manged internally by splits class. The state management moved to LogToken. --- .../src/main/java/com/microsoft/snippet/Snippet.java | 8 ++++++-- .../src/main/java/com/microsoft/snippet/Split.java | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/snippet/src/main/java/com/microsoft/snippet/Snippet.java b/snippet/src/main/java/com/microsoft/snippet/Snippet.java index 47f4834..47cd7c0 100644 --- a/snippet/src/main/java/com/microsoft/snippet/Snippet.java +++ b/snippet/src/main/java/com/microsoft/snippet/Snippet.java @@ -19,6 +19,7 @@ import com.microsoft.snippet.token.LogTokenState; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.concurrent.atomic.AtomicInteger; /** @@ -492,6 +493,7 @@ public final class Snippet { private volatile LogTokenState mState; private long mLastSplitTimeCaptured = 0L; private List mSplitRecord; + private final AtomicInteger mSequenceNumber = new AtomicInteger(1); // To be called only through LogTokenPool. Should not be created through any other ways. protected LogToken() { @@ -561,6 +563,8 @@ public final class Snippet { if (this.mSplitRecord != null) { this.mSplitRecord.clear(); } + this.mSequenceNumber.set(1); + this.mLastSplitTimeCaptured = 0L; this.mSplitRecord = null; } @@ -614,11 +618,11 @@ public final class Snippet { if (mLastSplitTimeCaptured == 0L) { // Split called for the first time // We use the token start time as the reference. mLastSplitTimeCaptured = ToolBox.currentTime(); - newSplit = new Split(getStart(), mLastSplitTimeCaptured); + newSplit = new Split(getStart(), mLastSplitTimeCaptured, mSequenceNumber.getAndIncrement()); } else { // Here we use the last split time captured. long currentTime = ToolBox.currentTime(); - newSplit = new Split(mLastSplitTimeCaptured, currentTime); + newSplit = new Split(getStart(), mLastSplitTimeCaptured, mSequenceNumber.getAndIncrement()); mLastSplitTimeCaptured = currentTime; } } diff --git a/snippet/src/main/java/com/microsoft/snippet/Split.java b/snippet/src/main/java/com/microsoft/snippet/Split.java index c80ff20..4f4381c 100644 --- a/snippet/src/main/java/com/microsoft/snippet/Split.java +++ b/snippet/src/main/java/com/microsoft/snippet/Split.java @@ -1,9 +1,11 @@ +/* + * Copyright © Microsoft Corporation. All rights reserved. + */ + package com.microsoft.snippet; import androidx.annotation.RestrictTo; -import java.util.concurrent.atomic.AtomicInteger; - /** * Split is a sub section of code within a capture( a contiguous/non-contiguous section of code). * It is used to measure the duration of subsections and helps in double clicking the areas that are @@ -16,7 +18,6 @@ import java.util.concurrent.atomic.AtomicInteger; @RestrictTo(RestrictTo.Scope.LIBRARY) public class Split { - private static final AtomicInteger SEQUENCE = new AtomicInteger(1); private final long mStarted; private final long mEnded; private final int mSequence; @@ -24,10 +25,10 @@ public class Split { private String mInfo; - public Split(long start, long end) { + public Split(long start, long end, int seqNumber) { this.mStarted = start; this.mEnded = end; - this.mSequence = SEQUENCE.getAndIncrement(); + this.mSequence = seqNumber; } public void setName(String name) {