Skip to content

Commit 2943b3d

Browse files
Merge pull request #3 from microsoft/develop
Fix issue with splits.
2 parents ab465dc + 4218e5f commit 2943b3d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

snippet/src/main/java/com/microsoft/snippet/Snippet.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121
import java.util.Locale;
22+
import java.util.concurrent.atomic.AtomicInteger;
2223

2324

2425
/**
@@ -492,6 +493,7 @@ public static class LogToken implements ILogToken {
492493
private volatile LogTokenState mState;
493494
private long mLastSplitTimeCaptured = 0L;
494495
private List<Split> mSplitRecord;
496+
private final AtomicInteger mSequenceNumber = new AtomicInteger(1);
495497

496498
// To be called only through LogTokenPool. Should not be created through any other ways.
497499
protected LogToken() {
@@ -561,6 +563,8 @@ public void reset() {
561563
if (this.mSplitRecord != null) {
562564
this.mSplitRecord.clear();
563565
}
566+
this.mSequenceNumber.set(1);
567+
this.mLastSplitTimeCaptured = 0L;
564568
this.mSplitRecord = null;
565569
}
566570

@@ -614,11 +618,11 @@ private Split createSplit() {
614618
if (mLastSplitTimeCaptured == 0L) { // Split called for the first time
615619
// We use the token start time as the reference.
616620
mLastSplitTimeCaptured = ToolBox.currentTime();
617-
newSplit = new Split(getStart(), mLastSplitTimeCaptured);
621+
newSplit = new Split(getStart(), mLastSplitTimeCaptured, mSequenceNumber.getAndIncrement());
618622
} else {
619623
// Here we use the last split time captured.
620624
long currentTime = ToolBox.currentTime();
621-
newSplit = new Split(mLastSplitTimeCaptured, currentTime);
625+
newSplit = new Split(getStart(), mLastSplitTimeCaptured, mSequenceNumber.getAndIncrement());
622626
mLastSplitTimeCaptured = currentTime;
623627
}
624628
}

snippet/src/main/java/com/microsoft/snippet/Split.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/*
2+
* Copyright © Microsoft Corporation. All rights reserved.
3+
*/
4+
15
package com.microsoft.snippet;
26

37
import androidx.annotation.RestrictTo;
48

5-
import java.util.concurrent.atomic.AtomicInteger;
6-
79
/**
810
* Split is a sub section of code within a capture( a contiguous/non-contiguous section of code).
911
* It is used to measure the duration of subsections and helps in double clicking the areas that are
@@ -16,18 +18,17 @@
1618
@RestrictTo(RestrictTo.Scope.LIBRARY)
1719
public class Split {
1820

19-
private static final AtomicInteger SEQUENCE = new AtomicInteger(1);
2021
private final long mStarted;
2122
private final long mEnded;
2223
private final int mSequence;
2324
private String mName;
2425

2526
private String mInfo;
2627

27-
public Split(long start, long end) {
28+
public Split(long start, long end, int seqNumber) {
2829
this.mStarted = start;
2930
this.mEnded = end;
30-
this.mSequence = SEQUENCE.getAndIncrement();
31+
this.mSequence = seqNumber;
3132
}
3233

3334
public void setName(String name) {

0 commit comments

Comments
 (0)