[강운덕] [LUCYSUS-1744] arcus asynctrace부분 개발

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@856 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2012-11-13 05:00:44 +00:00
parent 6a63099ad0
commit b2c37b5242
19 changed files with 371 additions and 308 deletions
+115 -125
View File
@@ -10,157 +10,147 @@ import com.profiler.Agent;
/**
* Span represent RPC
*
*
* @author netspider
*
*/
public class Span {
private final TraceID traceID;
private final long createTime;
private final TraceID traceID;
private final long createTime;
private String serviceName;
private String name;
private String endPoint;
private boolean isTerminal = false;
private String serviceName;
private String name;
private String endPoint;
private boolean isTerminal = false;
private final List<HippoAnnotation> annotations = new ArrayList<HippoAnnotation>(5);
private final Set<String> annotationKeys = new HashSet<String>(5);
private long rpcStartTime;
private long rpcEndTime;
/**
* Cancel timer logic.
* TODO: refactor this.
*/
private TimerTask timerTask;
private final List<HippoAnnotation> annotations = new ArrayList<HippoAnnotation>(5);
private final Set<String> annotationKeys = new HashSet<String>(5);
public void setTimerTask(TimerTask task) {
this.timerTask = task;
}
private long rpcStartTime;
private long rpcEndTime;
public boolean cancelTimer() {
return timerTask.cancel();
}
public Span(TraceID traceId, String name, String endPoint) {
this.traceID = traceId;
this.name = name;
this.endPoint = endPoint;
this.createTime = System.currentTimeMillis();
}
public Span(TraceID traceId, String name, String endPoint) {
this.traceID = traceId;
this.name = name;
this.endPoint = endPoint;
this.createTime = System.currentTimeMillis();
}
public boolean addAnnotation(HippoAnnotation annotation) {
annotationKeys.add(annotation.getKey());
if (annotation.getKey().equals(Annotation.ClientSend.getCode()) || annotation.getKey().equals(Annotation.ServerRecv.getCode())) {
rpcStartTime = annotation.getTimestamp();
}
if (annotation.getKey().equals(Annotation.ClientRecv.getCode()) || annotation.getKey().equals(Annotation.ServerSend.getCode())) {
rpcEndTime = annotation.getTimestamp();
}
return annotations.add(annotation);
}
public boolean addAnnotation(HippoAnnotation annotation) {
annotationKeys.add(annotation.getKey());
if (annotation.getKey().equals(Annotation.ClientSend.getCode()) || annotation.getKey().equals(Annotation.ServerRecv.getCode())) {
rpcStartTime = annotation.getTimestamp();
}
if (annotation.getKey().equals(Annotation.ClientRecv.getCode()) || annotation.getKey().equals(Annotation.ServerSend.getCode())) {
rpcEndTime = annotation.getTimestamp();
}
return annotations.add(annotation);
}
public int getAnnotationSize() {
return annotations.size();
}
public int getAnnotationSize() {
return annotations.size();
}
/**
* this method only works for Trace.mutate()
*
* @param value
* @return
*/
public boolean isExistsAnnotationKey(String key) {
return annotationKeys.contains(key);
}
/**
* this method only works for Trace.mutate()
*
* @param value
* @return
*/
public boolean isExistsAnnotationKey(String key) {
return annotationKeys.contains(key);
}
public String getEndPoint() {
return this.endPoint;
}
public String getEndPoint() {
return this.endPoint;
}
public String getServiceName() {
return serviceName;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public String getName() {
return name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
public boolean isTerminal() {
return isTerminal;
}
public boolean isTerminal() {
return isTerminal;
}
public void setTerminal(boolean isTerminal) {
this.isTerminal = isTerminal;
}
public long getRpcStartTime() {
return rpcStartTime;
}
public void setTerminal(boolean isTerminal) {
this.isTerminal = isTerminal;
}
public long getRpcEndTime() {
return rpcEndTime;
}
public long getRpcStartTime() {
return rpcStartTime;
}
public String toString() {
StringBuilder sb = new StringBuilder();
public long getRpcEndTime() {
return rpcEndTime;
}
sb.append("{");
sb.append("\n\t TraceID = ").append(traceID);
sb.append(",\n\t CreateTime = ").append(createTime);
sb.append(",\n\t Name = ").append(name);
sb.append(",\n\t ServiceName = ").append(serviceName);
sb.append(",\n\t EndPoint = ").append(endPoint);
public long getCreateTime() {
return createTime;
}
sb.append(",\n\t Annotations = {");
for (HippoAnnotation a : annotations) {
sb.append("\n\t\t").append(a);
}
sb.append("\n\t}");
sb.append("}");
public String toString() {
StringBuilder sb = new StringBuilder();
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();
sb.append("{");
sb.append("\n\t TraceID = ").append(traceID);
sb.append(",\n\t CreateTime = ").append(createTime);
sb.append(",\n\t Name = ").append(name);
sb.append(",\n\t ServiceName = ").append(serviceName);
sb.append(",\n\t EndPoint = ").append(endPoint);
span.setAgentId(Agent.getInstance().getAgentId());
span.setTimestamp(createTime);
span.setMostTraceId(traceID.getId().getMostSignificantBits());
span.setLeastTraceId(traceID.getId().getLeastSignificantBits());
span.setName(name);
span.setServiceName(serviceName);
span.setSpanId(traceID.getSpanId());
span.setParentSpanId(traceID.getParentSpanId());
span.setEndPoint(endPoint);
span.setTerminal(isTerminal);
// TODO: set duration.
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(annotations.size());
for (HippoAnnotation a : annotations) {
annotationList.add(a.toThrift());
}
span.setAnnotations(annotationList);
sb.append(",\n\t Annotations = {");
for (HippoAnnotation a : annotations) {
sb.append("\n\t\t").append(a);
}
sb.append("\n\t}");
span.setFlag(traceID.getFlags());
sb.append("}");
return span;
}
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();
span.setAgentId(Agent.getInstance().getAgentId());
span.setTimestamp(createTime);
span.setMostTraceId(traceID.getId().getMostSignificantBits());
span.setLeastTraceId(traceID.getId().getLeastSignificantBits());
span.setName(name);
span.setServiceName(serviceName);
span.setSpanId(traceID.getSpanId());
span.setParentSpanId(traceID.getParentSpanId());
span.setEndPoint(endPoint);
span.setTerminal(isTerminal);
// TODO: set duration.
List<com.profiler.common.dto.thrift.Annotation> annotationList = new ArrayList<com.profiler.common.dto.thrift.Annotation>(annotations.size());
for (HippoAnnotation a : annotations) {
annotationList.add(a.toThrift());
}
span.setAnnotations(annotationList);
span.setFlag(traceID.getFlags());
return span;
}
}