Fix the profiling segment count not correct (#491)

This commit is contained in:
mrproliu 2023-03-29 15:31:28 +08:00 committed by GitHub
parent 89e5262f99
commit db7a14d167
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -31,11 +31,13 @@ import java.util.concurrent.atomic.AtomicInteger;
public class ProfileStatusContext {
private volatile ProfileStatus status;
private volatile boolean fromFirstSegment;
private volatile long firstSegmentCreateTime;
private volatile AtomicInteger subThreadProfilingCount;
private ProfileStatusContext(ProfileStatus status, long firstSegmentCreateTime, AtomicInteger subThreadProfilingCount) {
this.status = status;
this.fromFirstSegment = true;
this.firstSegmentCreateTime = firstSegmentCreateTime;
this.subThreadProfilingCount = subThreadProfilingCount;
}
@ -62,6 +64,10 @@ public class ProfileStatusContext {
return this.firstSegmentCreateTime;
}
public boolean isFromFirstSegment() {
return fromFirstSegment;
}
/**
* The profile monitoring is watching, wait for some profile conditions.
*/
@ -83,6 +89,7 @@ public class ProfileStatusContext {
*/
public boolean continued(ContextSnapshot snapshot) {
this.status = snapshot.getProfileStatusContext().get();
this.fromFirstSegment = false;
this.firstSegmentCreateTime = snapshot.getProfileStatusContext().firstSegmentCreateTime();
this.subThreadProfilingCount = snapshot.getProfileStatusContext().subThreadProfilingCount;
return this.isBeingWatched() &&

View File

@ -131,7 +131,7 @@ public class ProfileTaskExecutionContext {
// update profiling status
tracingContext.profileStatus()
.updateStatus(attemptProfiling(tracingContext, traceSegmentId, firstSpanOPName));
.updateStatus(attemptProfiling(tracingContext, traceSegmentId, firstSpanOPName));
}
/**
@ -147,7 +147,9 @@ public class ProfileTaskExecutionContext {
// setting stop running
currentProfiler.stopProfiling();
currentEndpointProfilingCount.addAndGet(-1);
if (currentProfiler.profilingStatus().isFromFirstSegment()) {
currentEndpointProfilingCount.addAndGet(-1);
}
break;
}
}