mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-16 16:28:48 +10:00
[유치수] [NOBTS] remove binary annotation.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@788 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -1,53 +1,59 @@
|
||||
package com.profiler.context;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class HippoAnnotation {
|
||||
|
||||
protected final long time;
|
||||
protected final String value;
|
||||
protected final Long duration;
|
||||
protected final String threadname; // TODO: remove, just for debug.
|
||||
private final long timestamp;
|
||||
private final Long duration;
|
||||
private final String key;
|
||||
private final int valueTypeCode;
|
||||
private final byte[] value;
|
||||
private final String threadname;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param time
|
||||
* @param value
|
||||
* @param duration duration in nano second.
|
||||
*/
|
||||
public HippoAnnotation(long time, String value, Long duration) {
|
||||
this.time = time;
|
||||
this.value = value;
|
||||
public HippoAnnotation(long timestamp, String key, Long duration) {
|
||||
this.timestamp = timestamp;
|
||||
this.duration = duration;
|
||||
this.key = key;
|
||||
this.valueTypeCode = -1;
|
||||
this.value = null;
|
||||
this.threadname = Thread.currentThread().getName();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
public HippoAnnotation(long timestamp, String key, int valueTypeCode, byte[] value, Long duration) {
|
||||
this.timestamp = timestamp;
|
||||
this.duration = duration;
|
||||
this.key = key;
|
||||
this.valueTypeCode = valueTypeCode;
|
||||
this.value = value;
|
||||
this.threadname = Thread.currentThread().getName();
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("@={");
|
||||
sb.append("time=").append(time);
|
||||
sb.append(", value=").append(value);
|
||||
sb.append(", duration=").append(duration);
|
||||
sb.append(", threadname=").append(threadname);
|
||||
sb.append("}");
|
||||
|
||||
return sb.toString();
|
||||
return "HippoAnnotation [timestamp=" + timestamp + ", duration=" + duration + ", key=" + key + ", valueTypeCode=" + valueTypeCode + ", value=" + value + ", threadname=" + threadname + "]";
|
||||
}
|
||||
|
||||
public com.profiler.common.dto.thrift.Annotation toThrift() {
|
||||
com.profiler.common.dto.thrift.Annotation ann = new com.profiler.common.dto.thrift.Annotation();
|
||||
|
||||
ann.setTimestamp(time);
|
||||
ann.setValue(value);
|
||||
ann.setTimestamp(timestamp);
|
||||
|
||||
if (duration != null) {
|
||||
ann.setDuration(duration);
|
||||
}
|
||||
|
||||
ann.setKey(key);
|
||||
ann.setValueTypeCode(valueTypeCode);
|
||||
ann.setValue(value);
|
||||
|
||||
return ann;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
@Deprecated
|
||||
public class HippoBinaryAnnotation {
|
||||
|
||||
private final long time;
|
||||
|
||||
@@ -24,10 +24,9 @@ public class Span {
|
||||
private String endPoint;
|
||||
private boolean isTerminal = false;
|
||||
|
||||
private final List<HippoBinaryAnnotation> binaryAnnotations = new ArrayList<HippoBinaryAnnotation>(5);
|
||||
private final List<HippoAnnotation> annotations = new ArrayList<HippoAnnotation>(5);
|
||||
private final Set<String> annotationValues = new HashSet<String>(5);
|
||||
|
||||
private final Set<String> annotationKeys = new HashSet<String>(5);
|
||||
|
||||
/**
|
||||
* Cancel timer logic.
|
||||
* TODO: refactor this.
|
||||
@@ -50,14 +49,10 @@ public class Span {
|
||||
}
|
||||
|
||||
public boolean addAnnotation(HippoAnnotation annotation) {
|
||||
annotationValues.add(annotation.getValue());
|
||||
annotationKeys.add(annotation.getKey());
|
||||
return annotations.add(annotation);
|
||||
}
|
||||
|
||||
public boolean addAnnotation(HippoBinaryAnnotation annotation) {
|
||||
return binaryAnnotations.add(annotation);
|
||||
}
|
||||
|
||||
public int getAnnotationSize() {
|
||||
return annotations.size();
|
||||
}
|
||||
@@ -68,8 +63,8 @@ public class Span {
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public boolean isExistsAnnotationType(String value) {
|
||||
return annotationValues.contains(value);
|
||||
public boolean isExistsAnnotationKey(String key) {
|
||||
return annotationKeys.contains(key);
|
||||
}
|
||||
|
||||
public String getEndPoint() {
|
||||
@@ -103,7 +98,7 @@ public class Span {
|
||||
public void setTerminal(boolean isTerminal) {
|
||||
this.isTerminal = isTerminal;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -120,17 +115,11 @@ public class Span {
|
||||
}
|
||||
sb.append("\n\t}");
|
||||
|
||||
sb.append(",\n\t BinaryAnnotations=");
|
||||
for (HippoBinaryAnnotation a : binaryAnnotations) {
|
||||
sb.append("\n\t\t").append(a);
|
||||
}
|
||||
sb.append("\n\t}");
|
||||
|
||||
sb.append("}");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public com.profiler.common.dto.thrift.Span toThrift() {
|
||||
com.profiler.common.dto.thrift.Span span = new com.profiler.common.dto.thrift.Span();
|
||||
|
||||
@@ -151,12 +140,6 @@ public class Span {
|
||||
}
|
||||
span.setAnnotations(annotationList);
|
||||
|
||||
List<com.profiler.common.dto.thrift.BinaryAnnotation> binaryAnnotationList = new ArrayList<com.profiler.common.dto.thrift.BinaryAnnotation>(binaryAnnotations.size());
|
||||
for (HippoBinaryAnnotation a : binaryAnnotations) {
|
||||
binaryAnnotationList.add(a.toThrift());
|
||||
}
|
||||
span.setBinaryAnnotations(binaryAnnotationList);
|
||||
|
||||
span.setFlag(traceID.getFlags());
|
||||
|
||||
return span;
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.profiler.context;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.profiler.common.util.AnnotationTranscoder;
|
||||
import com.profiler.common.util.AnnotationTranscoder.Encoded;
|
||||
import com.profiler.sender.DataSender;
|
||||
import com.profiler.util.NamedThreadLocal;
|
||||
|
||||
@@ -19,6 +21,8 @@ public final class Trace {
|
||||
private static final ThreadLocal<TraceIDStack> traceIdLocal = new NamedThreadLocal<TraceIDStack>("TraceId");
|
||||
private static volatile boolean tracingEnabled = true;
|
||||
|
||||
private static final AnnotationTranscoder transcoder = new AnnotationTranscoder();
|
||||
|
||||
private Trace() {
|
||||
}
|
||||
|
||||
@@ -176,7 +180,7 @@ public final class Trace {
|
||||
private static void mutate(TraceID traceId, SpanUpdater spanUpdater) {
|
||||
Span span = spanMap.update(traceId, spanUpdater);
|
||||
|
||||
if (span.isExistsAnnotationType(Annotation.ClientRecv.getCode()) || span.isExistsAnnotationType(Annotation.ServerSend.getCode())) {
|
||||
if (span.isExistsAnnotationKey(Annotation.ClientRecv.getCode()) || span.isExistsAnnotationKey(Annotation.ServerSend.getCode())) {
|
||||
// remove current context threadId from stack
|
||||
removeCurrentTraceIdFromStack();
|
||||
logSpan(span);
|
||||
@@ -230,7 +234,8 @@ public final class Trace {
|
||||
mutate(getTraceIdOrCreateNew(), new SpanUpdater() {
|
||||
@Override
|
||||
public Span updateSpan(Span span) {
|
||||
span.addAnnotation(new HippoBinaryAnnotation(System.currentTimeMillis(), key, value));
|
||||
Encoded enc = transcoder.encode(value);
|
||||
span.addAnnotation(new HippoAnnotation(System.currentTimeMillis(), key, enc.getValueType(), enc.getBytes(), null));
|
||||
return span;
|
||||
}
|
||||
});
|
||||
@@ -292,7 +297,7 @@ public final class Trace {
|
||||
}
|
||||
}
|
||||
|
||||
private static void annotate(final String value, final Long duration) {
|
||||
private static void annotate(final String key, final Long duration) {
|
||||
if (!tracingEnabled)
|
||||
return;
|
||||
|
||||
@@ -300,7 +305,7 @@ public final class Trace {
|
||||
mutate(getTraceIdOrCreateNew(), new SpanUpdater() {
|
||||
@Override
|
||||
public Span updateSpan(Span span) {
|
||||
span.addAnnotation(new HippoAnnotation(System.currentTimeMillis(), value, duration));
|
||||
span.addAnnotation(new HippoAnnotation(System.currentTimeMillis(), key, duration));
|
||||
return span;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user