The split state was not getting recycled as it was manged internally by splits class.

The state management moved to LogToken.
This commit is contained in:
Vishal Ratna 2022-02-24 14:33:01 +05:30
Родитель ebb401593e
Коммит 4218e5ffca
2 изменённых файлов: 12 добавлений и 7 удалений

Просмотреть файл

@ -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<Split> 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;
}
}

Просмотреть файл

@ -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) {