Skip to content

Commit

Permalink
[pinpoint-apm#9693] CallStack OverFlow check is missing in AsyncChild…
Browse files Browse the repository at this point in the history
…Trace
  • Loading branch information
emeroad committed Feb 13, 2023
1 parent f40b797 commit 4eb3eb9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private SpanEvent traceBlockBegin0(final int stackId) {

private void stackDump(String caused) {
PinpointException exception = new PinpointException(caused);
logger.warn("[DefaultTrace] Corrupted call stack found TraceRoot:{}, CallStack:{}", getTraceRoot(), callStack, exception);
logger.warn("Corrupted call stack found TraceRoot:{}, CallStack:{}", getTraceRoot(), callStack, exception);
}

@Override
Expand Down Expand Up @@ -258,20 +258,20 @@ public SpanEventRecorder currentSpanEventRecorder() {
}

private SpanEvent newSpanEvent(int stackId) {
final SpanEvent spanEvent = callStack.getFactory().newInstance();
final SpanEvent spanEvent = callStack.newInstance();
spanEvent.markStartTime();
spanEvent.setStackId(stackId);
return spanEvent;
}

@VisibleForTesting
SpanEvent dummySpanEvent() {
return callStack.getFactory().disableInstance();
return callStack.disableInstance();
}

@VisibleForTesting
boolean isDummySpanEvent(final SpanEvent spanEvent) {
return callStack.getFactory().isDisable(spanEvent);
return callStack.isDisable(spanEvent);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public interface CallStack<T> {

T newInstance();

Factory<T> getFactory();
T disableInstance();

boolean isDisable(T element);

void setOverflowListener(CallStackOverflowListener overflowListener);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,14 @@ public T newInstance() {
}

@Override
public Factory<T> getFactory() {
return factory;
public T disableInstance() {
return this.factory.disableInstance();
}

@Override
public boolean isDisable(T element) {
return this.factory.isDisable(element);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private SpanEvent traceBlockBegin0(final int stackId) {
private void stackDump(String caused) {
PinpointException exception = new PinpointException(caused);
if (logger.isWarnEnabled()) {
logger.warn("[{}] Corrupted call stack found TraceRoot:{}, CallStack:{}", getClass().getSimpleName(), getTraceRoot(), callStack, exception);
logger.warn("Corrupted call stack found TraceRoot:{}, CallStack:{}", getTraceRoot(), callStack, exception);
}
}

Expand Down Expand Up @@ -282,12 +282,12 @@ private SpanEvent newSpanEvent(int stackId) {

@VisibleForTesting
SpanEvent dummySpanEvent() {
return callStack.getFactory().disableInstance();
return callStack.disableInstance();
}

@VisibleForTesting
boolean isDummySpanEvent(final SpanEvent spanEvent) {
return callStack.getFactory().isDisable(spanEvent);
return callStack.isDisable(spanEvent);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void newInstance() {
callStack.push(spanEvent1);

SpanEvent spanEvent2 = callStack.newInstance();
assertTrue(callStack.getFactory().isDisable(spanEvent2));
assertTrue(callStack.isDisable(spanEvent2));
}

@Test
Expand Down Expand Up @@ -177,19 +177,19 @@ public void overflow2() {
// overflow by sequence
assertEquals(maxDepth - 1, callStack.getIndex());
assertTrue(callStack.isOverflow());
assertFalse(callStack.getFactory().isDisable(callStack.peek()));
assertFalse(callStack.isDisable(callStack.peek()));

callStack.push(getSpanEvent());
assertEquals(maxDepth, callStack.getIndex());
assertTrue(callStack.getFactory().isDisable(callStack.peek()));
assertTrue(callStack.getFactory().isDisable(callStack.pop()));
assertTrue(callStack.isDisable(callStack.peek()));
assertTrue(callStack.isDisable(callStack.pop()));

for (int i = maxDepth - 1; i > 0; i--) {
assertNotNull(callStack.peek());
assertFalse(callStack.getFactory().isDisable(callStack.peek()));
assertFalse(callStack.isDisable(callStack.peek()));
SpanEvent element = callStack.pop();
assertNotNull(element);
assertFalse(callStack.getFactory().isDisable(element));
assertFalse(callStack.isDisable(element));
assertTrue(callStack.isOverflow());
}
}
Expand Down

0 comments on commit 4eb3eb9

Please sign in to comment.