Skip to content

Commit

Permalink
[#10023] Improve reference release timing for GC
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jun 8, 2023
1 parent a39c034 commit 6c63cd0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public GrpcSpanMessageConverter(String agentId, short applicationServiceType,
public GeneratedMessageV3 toMessage(SpanType message) {
if (message instanceof SpanChunk) {
final SpanChunk spanChunk = (SpanChunk) message;
final PSpanChunk pSpanChunk = buildPSpanChunk(spanChunk);
return pSpanChunk;
return buildPSpanChunk(spanChunk);
}
if (message instanceof Span) {
final Span span = (Span) message;
Expand Down Expand Up @@ -246,8 +245,8 @@ private List<PSpanEvent> buildPSpanEventList(List<SpanEvent> spanEventList) {
final int eventSize = spanEventList.size();
final List<PSpanEvent> pSpanEventList = new ArrayList<>(eventSize);
for (SpanEvent spanEvent : spanEventList) {
final PSpanEvent.Builder pSpanEvent = buildPSpanEvent(spanEvent);
pSpanEventList.add(pSpanEvent.build());
final PSpanEvent pSpanEvent = buildPSpanEvent(spanEvent);
pSpanEventList.add(pSpanEvent);
}
return pSpanEventList;
}
Expand Down Expand Up @@ -298,50 +297,53 @@ PSpanChunk buildPSpanChunk(SpanChunk spanChunk) {
}

@VisibleForTesting
public PSpanEvent.Builder buildPSpanEvent(SpanEvent spanEvent) {
final PSpanEvent.Builder pSpanEvent = getSpanEventBuilder();

public PSpanEvent buildPSpanEvent(SpanEvent spanEvent) {
final PSpanEvent.Builder builder = this.pSpanEventBuilder;
try {
// if (spanEvent.getStartElapsed() != 0) {
// tSpanEvent.setStartElapsed(spanEvent.getStartElapsed());
// builder.setStartElapsed(spanEvent.getStartElapsed());
// }
// tSpanEvent.setStartElapsed(spanEvent.getStartElapsed());
if (spanEvent.getElapsedTime() != 0) {
pSpanEvent.setEndElapsed(spanEvent.getElapsedTime());
}
pSpanEvent.setSequence(spanEvent.getSequence());
// tSpanEvent.setRpc(spanEvent.getRpc());
pSpanEvent.setServiceType(spanEvent.getServiceType());
if (spanEvent.getElapsedTime() != 0) {
builder.setEndElapsed(spanEvent.getElapsedTime());
}
builder.setSequence(spanEvent.getSequence());
// builder.setRpc(spanEvent.getRpc());
builder.setServiceType(spanEvent.getServiceType());

// tSpanEvent.setAnnotations();
if (spanEvent.getDepth() != -1) {
pSpanEvent.setDepth(spanEvent.getDepth());
}
// tSpanEvent.setAnnotations();
if (spanEvent.getDepth() != -1) {
builder.setDepth(spanEvent.getDepth());
}

pSpanEvent.setApiId(spanEvent.getApiId());
builder.setApiId(spanEvent.getApiId());

final IntStringValue exceptionInfo = spanEvent.getExceptionInfo();
if (exceptionInfo != null) {
PIntStringValue pIntStringValue = buildPIntStringValue(exceptionInfo);
pSpanEvent.setExceptionInfo(pIntStringValue);
}
final IntStringValue exceptionInfo = spanEvent.getExceptionInfo();
if (exceptionInfo != null) {
PIntStringValue pIntStringValue = buildPIntStringValue(exceptionInfo);
builder.setExceptionInfo(pIntStringValue);
}

final PNextEvent nextEvent = buildNextEvent(spanEvent);
if (nextEvent != null) {
pSpanEvent.setNextEvent(nextEvent);
}
final AsyncId asyncIdObject = spanEvent.getAsyncIdObject();
if (asyncIdObject != null) {
pSpanEvent.setAsyncEvent(asyncIdObject.getAsyncId());
}
final PNextEvent nextEvent = buildNextEvent(spanEvent);
if (nextEvent != null) {
builder.setNextEvent(nextEvent);
}
final AsyncId asyncIdObject = spanEvent.getAsyncIdObject();
if (asyncIdObject != null) {
builder.setAsyncEvent(asyncIdObject.getAsyncId());
}


final List<Annotation<?>> annotations = spanEvent.getAnnotations();
if (CollectionUtils.hasLength(annotations)) {
final List<PAnnotation> pAnnotations = buildPAnnotation(annotations);
pSpanEvent.addAllAnnotation(pAnnotations);
}
final List<Annotation<?>> annotations = spanEvent.getAnnotations();
if (CollectionUtils.hasLength(annotations)) {
final List<PAnnotation> pAnnotations = buildPAnnotation(annotations);
builder.addAllAnnotation(pAnnotations);
}

return pSpanEvent;
return builder.build();
} finally {
builder.clear();
}
}

private PNextEvent buildNextEvent(SpanEvent spanEvent) {
Expand Down Expand Up @@ -391,28 +393,26 @@ private PIntStringValue buildPIntStringValue(IntStringValue exceptionInfo) {

@VisibleForTesting
List<PAnnotation> buildPAnnotation(List<Annotation<?>> annotations) {
final List<PAnnotation> tAnnotationList = new ArrayList<>(annotations.size());
for (Annotation<?> annotation : annotations) {
final PAnnotation.Builder builder = getAnnotationBuilder();
final List<PAnnotation> tAnnotationList = new ArrayList<>(annotations.size());
for (Annotation<?> annotation : annotations) {
PAnnotation pAnnotation = buildPAnnotation0(annotation);
tAnnotationList.add(pAnnotation);
}
return tAnnotationList;
}

private PAnnotation buildPAnnotation0(Annotation<?> annotation) {
final PAnnotation.Builder builder = this.pAnnotationBuilder;
try {
builder.setKey(annotation.getKey());
final PAnnotationValue pAnnotationValue = grpcAnnotationValueMapper.buildPAnnotationValue(annotation);
if (pAnnotationValue != null) {
builder.setValue(pAnnotationValue);
}
PAnnotation pAnnotation = builder.build();
tAnnotationList.add(pAnnotation);
return builder.build();
} finally {
builder.clear();
}
return tAnnotationList;
}

private PAnnotation.Builder getAnnotationBuilder() {
this.pAnnotationBuilder.clear();
return pAnnotationBuilder;
}

private PSpanEvent.Builder getSpanEventBuilder() {
pSpanEventBuilder.clear();
return pSpanEventBuilder;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void postProcess() {

PSpan.Builder builder = PSpan.newBuilder();
for (SpanEvent spanEvent : span.getSpanEventList()) {
PSpanEvent.Builder pSpanEvent = converter.buildPSpanEvent(spanEvent);
PSpanEvent pSpanEvent = converter.buildPSpanEvent(spanEvent);
builder.addSpanEvent(pSpanEvent);
}

Expand Down

0 comments on commit 6c63cd0

Please sign in to comment.