[유치수] [NOBTS] thrift

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@572 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Chisu Yu
2012-09-04 08:37:38 +00:00
parent 98a3f71464
commit a57e2ab393
13 changed files with 565 additions and 634 deletions
@@ -13,4 +13,8 @@ public class EndPoint {
public String toString() {
return "EndPoint{ip=" + ip + ", port=" + port + "}";
}
public com.profiler.context.gen.Endpoint toThrift() {
return new com.profiler.context.gen.Endpoint(ip, (short) port);
}
}
@@ -32,4 +32,16 @@ public class HippoAnnotation {
return sb.toString();
}
public com.profiler.context.gen.Annotation toThrift() {
com.profiler.context.gen.Annotation ann = new com.profiler.context.gen.Annotation();
ann.setTimestamp(time);
ann.setValue(value);
if (duration != null) {
ann.setDuration(duration);
}
return ann;
}
}
@@ -1,18 +1,20 @@
package com.profiler.context;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
public class HippoBinaryAnnotation {
private final long time;
private final String key;
private final Object value;
private final Long duration;
private final String threadname; // TODO: remove, just for debug.
public HippoBinaryAnnotation(long time, String key, Object value, Long duration) {
public HippoBinaryAnnotation(long time, String key, Object value) {
this.time = time;
this.key = key;
this.value = value;
this.duration = duration;
this.threadname = Thread.currentThread().getName();
}
@@ -24,11 +26,29 @@ public class HippoBinaryAnnotation {
sb.append("time=").append(time);
sb.append(", key=").append(key);
sb.append(", value=").append(value);
sb.append(", duration=").append(duration);
sb.append(", threadname=").append(threadname);
sb.append("}");
return sb.toString();
}
public com.profiler.context.gen.BinaryAnnotation toThrift() {
com.profiler.context.gen.BinaryAnnotation ann = new com.profiler.context.gen.BinaryAnnotation();
ann.setTimestamp(time);
ann.setKey(key);
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(value);
ann.setValue(bos.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
ann.setValueType(value.getClass().getName());
return ann;
}
}
@@ -91,4 +91,31 @@ public class Span {
return sb.toString();
}
public com.profiler.context.gen.Span toThrift() {
com.profiler.context.gen.Span span = new com.profiler.context.gen.Span();
span.setTimestamp(createTime);
span.setMostTraceID(traceID.getTraceId().getMostSignificantBits());
span.setLeastTraceID(traceID.getTraceId().getLeastSignificantBits());
span.setName(name);
span.setSpanID(traceID.getSpanId());
span.setParentSpanId(traceID.getParentSpanId());
List<com.profiler.context.gen.Annotation> annotationList = new ArrayList<com.profiler.context.gen.Annotation>(annotations.size());
for (HippoAnnotation a : annotations) {
annotationList.add(a.toThrift());
}
span.setAnnotations(annotationList);
List<com.profiler.context.gen.BinaryAnnotation> binaryAnnotationList = new ArrayList<com.profiler.context.gen.BinaryAnnotation>(binaryAnnotations.size());
for (HippoBinaryAnnotation a : binaryAnnotations) {
binaryAnnotationList.add(a.toThrift());
}
span.setBinaryAnnotations(binaryAnnotationList);
span.setFlag(traceID.getFlags());
return span;
}
}
@@ -3,6 +3,7 @@ package com.profiler.context;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.profiler.sender.DataSender;
import com.profiler.util.NamedThreadLocal;
/**
@@ -80,6 +81,8 @@ public final class Trace {
try {
// TODO: send span to server
System.out.println("\n\nWrite span hash=" + span.hashCode() + ", value=" + span + ", spanMap.size=" + spanMap.size() + ", threadid=" + Thread.currentThread().getId() + "\n\n");
DataSender.getInstance().addDataToSend(span.toThrift());
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.SEVERE, e.getMessage());
@@ -108,7 +111,7 @@ public final class Trace {
mutate(getTraceId(), new SpanUpdater() {
@Override
public Span updateSpan(Span span) {
span.addAnnotation(new HippoBinaryAnnotation(System.currentTimeMillis(), key, value, null));
span.addAnnotation(new HippoBinaryAnnotation(System.currentTimeMillis(), key, value));
return span;
}
});
@@ -1,38 +1,42 @@
package com.profiler.util;
import com.profiler.context.gen.Span;
import com.profiler.dto.*;
import org.apache.thrift.TBase;
public class DefaultTBaseLocator implements TBaseLocator {
private static final short JVM_INFO_THRIFT_DTO = 10;
private static final short REQUEST_DATA_LIST_THRIFT_DTO = 20;
private static final short REQUEST_THRIFT_DTO = 30;
private static final short JVM_INFO_THRIFT_DTO = 10;
private static final short REQUEST_DATA_LIST_THRIFT_DTO = 20;
private static final short REQUEST_THRIFT_DTO = 30;
private static final short SPAN = 40;
@Override
public TBase<?, ?> tBaseLookup(short type) {
switch (type) {
case JVM_INFO_THRIFT_DTO:
return new JVMInfoThriftDTO();
case REQUEST_DATA_LIST_THRIFT_DTO:
return new RequestDataListThriftDTO();
case REQUEST_THRIFT_DTO:
return new RequestThriftDTO();
switch (type) {
case JVM_INFO_THRIFT_DTO:
return new JVMInfoThriftDTO();
case REQUEST_DATA_LIST_THRIFT_DTO:
return new RequestDataListThriftDTO();
case REQUEST_THRIFT_DTO:
return new RequestThriftDTO();
}
throw new IllegalArgumentException("Unsupported type:" + type);
}
public short typeLookup(TBase<?, ?> tbase) {
if(tbase instanceof JVMInfoThriftDTO) {
return JVM_INFO_THRIFT_DTO;
}
if(tbase instanceof RequestDataListThriftDTO) {
return REQUEST_DATA_LIST_THRIFT_DTO;
}
if(tbase instanceof RequestThriftDTO) {
return REQUEST_THRIFT_DTO;
}
throw new UnsupportedOperationException("Unsupported Type");
}
public short typeLookup(TBase<?, ?> tbase) {
if (tbase instanceof JVMInfoThriftDTO) {
return JVM_INFO_THRIFT_DTO;
}
if (tbase instanceof RequestDataListThriftDTO) {
return REQUEST_DATA_LIST_THRIFT_DTO;
}
if (tbase instanceof RequestThriftDTO) {
return REQUEST_THRIFT_DTO;
}
if (tbase instanceof Span) {
return SPAN;
}
throw new UnsupportedOperationException("Unsupported Type");
}
}