Skip to content

Commit db7a14d

Browse files
authored
Fix the profiling segment count not correct (#491)
1 parent 89e5262 commit db7a14d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/profile/ProfileStatusContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
public class ProfileStatusContext {
3232

3333
private volatile ProfileStatus status;
34+
private volatile boolean fromFirstSegment;
3435
private volatile long firstSegmentCreateTime;
3536
private volatile AtomicInteger subThreadProfilingCount;
3637

3738
private ProfileStatusContext(ProfileStatus status, long firstSegmentCreateTime, AtomicInteger subThreadProfilingCount) {
3839
this.status = status;
40+
this.fromFirstSegment = true;
3941
this.firstSegmentCreateTime = firstSegmentCreateTime;
4042
this.subThreadProfilingCount = subThreadProfilingCount;
4143
}
@@ -62,6 +64,10 @@ public long firstSegmentCreateTime() {
6264
return this.firstSegmentCreateTime;
6365
}
6466

67+
public boolean isFromFirstSegment() {
68+
return fromFirstSegment;
69+
}
70+
6571
/**
6672
* The profile monitoring is watching, wait for some profile conditions.
6773
*/
@@ -83,6 +89,7 @@ public ProfileStatusContext clone() {
8389
*/
8490
public boolean continued(ContextSnapshot snapshot) {
8591
this.status = snapshot.getProfileStatusContext().get();
92+
this.fromFirstSegment = false;
8693
this.firstSegmentCreateTime = snapshot.getProfileStatusContext().firstSegmentCreateTime();
8794
this.subThreadProfilingCount = snapshot.getProfileStatusContext().subThreadProfilingCount;
8895
return this.isBeingWatched() &&

apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/profile/ProfileTaskExecutionContext.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void profilingRecheck(TracingContext tracingContext, String traceSegmentI
131131

132132
// update profiling status
133133
tracingContext.profileStatus()
134-
.updateStatus(attemptProfiling(tracingContext, traceSegmentId, firstSpanOPName));
134+
.updateStatus(attemptProfiling(tracingContext, traceSegmentId, firstSpanOPName));
135135
}
136136

137137
/**
@@ -147,7 +147,9 @@ public void stopTracingProfile(TracingContext tracingContext) {
147147

148148
// setting stop running
149149
currentProfiler.stopProfiling();
150-
currentEndpointProfilingCount.addAndGet(-1);
150+
if (currentProfiler.profilingStatus().isFromFirstSegment()) {
151+
currentEndpointProfilingCount.addAndGet(-1);
152+
}
151153
break;
152154
}
153155
}

0 commit comments

Comments
 (0)