mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-18 17:26:14 +10:00
[강운덕] [LUCYSUS-1744] span, spanchunk, spanevent를 toThrift를 거쳐 생성하지 않고 다이렉트로 생성하도록 성능 개선, JDBCUrlParser가 url을 캐쉬하도록 수정함.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@2426 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -24,6 +24,7 @@ import com.nhn.pinpoint.profiler.sender.DataSender;
|
||||
import com.nhn.pinpoint.profiler.sender.TcpDataSender;
|
||||
import com.nhn.pinpoint.profiler.sender.UdpDataSender;
|
||||
import com.nhn.pinpoint.profiler.util.NetworkUtils;
|
||||
import com.nhn.pinpoint.thrift.dto.TAgentKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -54,8 +55,10 @@ public class DefaultAgent implements Agent {
|
||||
|
||||
private final AgentInformation agentInformation;
|
||||
|
||||
private final TAgentKey tAgentKey;
|
||||
|
||||
// agent info는 heartbeat에서 매번 사용한다.
|
||||
private TAgentInfo agentInfo;
|
||||
private TAgentInfo tAgentInfo;
|
||||
|
||||
// agent의 상태,
|
||||
private volatile AgentStatus agentStatus;
|
||||
@@ -101,8 +104,9 @@ public class DefaultAgent implements Agent {
|
||||
// 매핑 테이블 초기화를 위해 엑세스
|
||||
// ApiMappingTable.findApiId("test", null, null);
|
||||
|
||||
this.agentInfo = createAgentInfo();
|
||||
this.heartBitChecker = new HeartBitChecker(tcpDataSender, profilerConfig.getHeartbeatInterval(), agentInfo);
|
||||
this.tAgentInfo = createTAgentInfo();
|
||||
this.tAgentKey = createTAgentKey();
|
||||
this.heartBitChecker = new HeartBitChecker(tcpDataSender, profilerConfig.getHeartbeatInterval(), tAgentInfo);
|
||||
|
||||
// JVM 통계 등을 주기적으로 수집하여 collector에 전송하는 monitor를 초기화한다.
|
||||
this.agentStatMonitor = new AgentStatMonitor(this.statDataSender, this.agentInformation.getAgentId());
|
||||
@@ -111,6 +115,8 @@ public class DefaultAgent implements Agent {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private AgentInformation createAgentInformation() {
|
||||
final String machineName = NetworkUtils.getHostName();
|
||||
final String agentId = getId("pinpoint.agentId", machineName, PinpointConstants.AGENT_NAME_MAX_LEN);
|
||||
@@ -176,7 +182,7 @@ public class DefaultAgent implements Agent {
|
||||
}
|
||||
}
|
||||
|
||||
private TAgentInfo createAgentInfo() {
|
||||
private TAgentInfo createTAgentInfo() {
|
||||
final ServerInfo serverInfo = this.serverInfo;
|
||||
String ip = serverInfo.getHostip();
|
||||
String ports = "";
|
||||
@@ -199,6 +205,14 @@ public class DefaultAgent implements Agent {
|
||||
return agentInfo;
|
||||
}
|
||||
|
||||
private TAgentKey createTAgentKey() {
|
||||
return new TAgentKey(agentInformation.getAgentId(), agentInformation.getApplicationName(), agentInformation.getStartTime());
|
||||
}
|
||||
|
||||
public TAgentKey getTAgentKey() {
|
||||
return tAgentKey;
|
||||
}
|
||||
|
||||
private void changeStatus(AgentStatus status) {
|
||||
this.agentStatus = status;
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -318,9 +332,9 @@ public class DefaultAgent implements Agent {
|
||||
public void stop() {
|
||||
logger.info("Stopping {} Agent.", ProductInfo.CAMEL_NAME);
|
||||
|
||||
agentInfo.setIsAlive(false);
|
||||
this.tcpDataSender.send(agentInfo);
|
||||
// TODO send agentInfo alive false후 send 메시지의 처리가 정확하지 않음
|
||||
tAgentInfo.setIsAlive(false);
|
||||
this.tcpDataSender.send(tAgentInfo);
|
||||
// TODO send tAgentInfo alive false후 send 메시지의 처리가 정확하지 않음
|
||||
|
||||
changeStatus(AgentStatus.STOPPING);
|
||||
this.heartBitChecker.stop();
|
||||
|
||||
@@ -37,7 +37,7 @@ public class BypassStorage implements Storage {
|
||||
if (spanEvent == null) {
|
||||
throw new NullPointerException("spanEvent must not be null");
|
||||
}
|
||||
dataSender.send(spanEvent);
|
||||
dataSender.send((Thriftable) spanEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -75,7 +75,7 @@ public class DefaultAsyncTrace implements AsyncTrace {
|
||||
|
||||
@Override
|
||||
public void markBeforeTime() {
|
||||
spanEvent.setStartTime(System.currentTimeMillis());
|
||||
spanEvent.markStartTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,7 +90,7 @@ public class DefaultAsyncTrace implements AsyncTrace {
|
||||
|
||||
@Override
|
||||
public void markAfterTime() {
|
||||
spanEvent.setEndTime(System.currentTimeMillis());
|
||||
spanEvent.markEndTime();
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ public class DefaultAsyncTrace implements AsyncTrace {
|
||||
|
||||
@Override
|
||||
public void recordServiceType(final ServiceType serviceType) {
|
||||
this.spanEvent.setServiceType(serviceType);
|
||||
this.spanEvent.setServiceType(serviceType.getCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,7 +147,7 @@ public class DefaultAsyncTrace implements AsyncTrace {
|
||||
|
||||
@Override
|
||||
public void recordDestinationId(String destinationId) {
|
||||
this.spanEvent.setDestionationId(destinationId);
|
||||
this.spanEvent.setDestinationId(destinationId);
|
||||
}
|
||||
|
||||
// TODO: final String... endPoint로 받으면 합치는데 비용이 들어가 그냥 한번에 받는게 나을것 같음.
|
||||
|
||||
@@ -345,7 +345,7 @@ public final class DefaultTrace implements Trace {
|
||||
span.setServiceType(serviceType.getCode());
|
||||
} else {
|
||||
SpanEvent spanEvent = ((SpanEventStackFrame) currentStackFrame).getSpanEvent();
|
||||
spanEvent.setServiceType(serviceType);
|
||||
spanEvent.setServiceType(serviceType.getCode());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -370,18 +370,19 @@ public final class DefaultTrace implements Trace {
|
||||
StackFrame currentStackFrame = this.currentStackFrame;
|
||||
if (currentStackFrame instanceof SpanEventStackFrame) {
|
||||
SpanEvent spanEvent = ((SpanEventStackFrame) currentStackFrame).getSpanEvent();
|
||||
spanEvent.setDestionationId(destinationId);
|
||||
spanEvent.setDestinationId(destinationId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void recordDestinationAddress(List<String> address) {
|
||||
// TODO API 단일화 필요.
|
||||
StackFrame currentStackFrame = this.currentStackFrame;
|
||||
if (currentStackFrame instanceof SpanEventStackFrame) {
|
||||
SpanEvent spanEvent = ((SpanEventStackFrame) currentStackFrame).getSpanEvent();
|
||||
spanEvent.setDestinationAddress();
|
||||
}
|
||||
// StackFrame currentStackFrame = this.currentStackFrame;
|
||||
// if (currentStackFrame instanceof SpanEventStackFrame) {
|
||||
// SpanEvent spanEvent = ((SpanEventStackFrame) currentStackFrame).getSpanEvent();
|
||||
// spanEvent.setDestinationAddress();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -415,13 +416,15 @@ public final class DefaultTrace implements Trace {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordNextSpanId(int spanId) {
|
||||
public void recordNextSpanId(int nextSpanId) {
|
||||
StackFrame currentStackFrame = this.currentStackFrame;
|
||||
if (currentStackFrame instanceof RootStackFrame) {
|
||||
logger.warn("OMG. Something's going wrong. Current stackframe is root Span. nextSpanId={}", spanId);
|
||||
logger.warn("OMG. Something's going wrong. Current stackframe is root Span. nextSpanId={}", nextSpanId);
|
||||
} else {
|
||||
SpanEvent spanEvent = ((SpanEventStackFrame) currentStackFrame).getSpanEvent();
|
||||
spanEvent.setNextSpanId(spanId);
|
||||
if (nextSpanId != -1) {
|
||||
spanEvent.setNextSpanId(nextSpanId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,14 +39,12 @@ public class RootStackFrame implements StackFrame {
|
||||
|
||||
@Override
|
||||
public void markAfterTime() {
|
||||
final long startTime = this.span.getStartTime();
|
||||
// long으로 바꿀것.
|
||||
this.span.setElapsed((int)(System.currentTimeMillis() - startTime));
|
||||
this.span.markEndTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAfterTime() {
|
||||
return this.span.getElapsed() + this.span.getStartTime();
|
||||
return span.getEndTime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@ import com.nhn.pinpoint.thrift.dto.TSpan;
|
||||
import com.nhn.pinpoint.thrift.dto.TSpanEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Span represent RPC
|
||||
@@ -18,15 +20,14 @@ import java.util.List;
|
||||
public class Span extends TSpan implements Thriftable {
|
||||
private final TraceId traceId;
|
||||
|
||||
private final List<TraceAnnotation> traceAnnotationList = new ArrayList<TraceAnnotation>(5);
|
||||
private List<TraceAnnotation> traceAnnotationList = new ArrayList<TraceAnnotation>(4);
|
||||
|
||||
private List<SpanEvent> spanEventList;
|
||||
|
||||
public Span(TraceId traceId) {
|
||||
if (traceId == null) {
|
||||
throw new NullPointerException("traceId must not be null");
|
||||
}
|
||||
this.traceId = traceId;
|
||||
recordTraceId(traceId);
|
||||
}
|
||||
|
||||
private void recordTraceId(TraceId traceId) {
|
||||
@@ -42,6 +43,26 @@ public class Span extends TSpan implements Thriftable {
|
||||
this.setFlag(traceId.getFlags());
|
||||
}
|
||||
|
||||
public void markBeforeTime() {
|
||||
this.setStartTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void markEndTime() {
|
||||
if (!isSetStartTime()) {
|
||||
throw new RuntimeException("startTime is not set");
|
||||
}
|
||||
final long startTime = this.getStartTime();
|
||||
// long으로 바꿀것.
|
||||
this.setElapsed((int)(System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
if (!isSetStartTime()) {
|
||||
throw new RuntimeException("startTime is not set");
|
||||
}
|
||||
return this.getStartTime() + this.getElapsed();
|
||||
}
|
||||
|
||||
|
||||
public boolean addAnnotation(TraceAnnotation traceAnnotation) {
|
||||
return traceAnnotationList.add(traceAnnotation);
|
||||
@@ -51,14 +72,8 @@ public class Span extends TSpan implements Thriftable {
|
||||
return traceAnnotationList.size();
|
||||
}
|
||||
|
||||
public List<SpanEvent> getPSpanEventList() {
|
||||
return spanEventList;
|
||||
}
|
||||
|
||||
public void setPSpanEventList(List<SpanEvent> spanEventList) {
|
||||
this.spanEventList = spanEventList;
|
||||
}
|
||||
|
||||
|
||||
public int getException() {
|
||||
return getErr();
|
||||
}
|
||||
@@ -73,7 +88,6 @@ public class Span extends TSpan implements Thriftable {
|
||||
|
||||
public TSpan toThrift() {
|
||||
|
||||
recordTraceId(traceId);
|
||||
final AgentInformation agentInformation = DefaultAgent.getInstance().getAgentInformation();
|
||||
this.setAgentId(agentInformation.getAgentId());
|
||||
this.setApplicationName(agentInformation.getApplicationName());
|
||||
@@ -86,17 +100,19 @@ public class Span extends TSpan implements Thriftable {
|
||||
annotationList.add(traceAnnotation.toThrift());
|
||||
}
|
||||
this.setAnnotations(annotationList);
|
||||
this.traceAnnotationList = null;
|
||||
|
||||
List<SpanEvent> spanEventList = this.getPSpanEventList();
|
||||
if (spanEventList != null && spanEventList.size() != 0) {
|
||||
List<TSpanEvent> tSpanEventList = new ArrayList<TSpanEvent>(spanEventList.size());
|
||||
for (SpanEvent spanEvent : spanEventList) {
|
||||
TSpanEvent tSpanEvent = spanEvent.toThrift(true);
|
||||
tSpanEventList.add(tSpanEvent);
|
||||
final List<TSpanEvent> spanEventList = this.getSpanEventList();
|
||||
if (spanEventList != null) {
|
||||
for (TSpanEvent spanEvent : spanEventList) {
|
||||
if (spanEvent instanceof SpanEvent) {
|
||||
((SpanEvent)spanEvent).toThrift(true);
|
||||
}
|
||||
}
|
||||
this.setSpanEventList(tSpanEventList);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,84 +14,57 @@ import com.nhn.pinpoint.profiler.DefaultAgent;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SpanChunk implements Thriftable {
|
||||
|
||||
private final List<SpanEvent> spanEventList;
|
||||
public class SpanChunk extends TSpanChunk implements Thriftable {
|
||||
|
||||
public SpanChunk(List<SpanEvent> spanEventList) {
|
||||
if (spanEventList == null) {
|
||||
throw new NullPointerException("spanEventList must not be null");
|
||||
}
|
||||
this.spanEventList = spanEventList;
|
||||
setSpanEventList((List) spanEventList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TBase toThrift() {
|
||||
TSpanChunk tSpanChunk = new TSpanChunk();
|
||||
// TODO 반드시 1개 이상이라는 조건을 충족해야 된다.
|
||||
SpanEvent first = spanEventList.get(0);
|
||||
Span parentSpan = first.getParentSpan();
|
||||
final List<TSpanEvent> spanEventList = getSpanEventList();
|
||||
TSpanEvent first = spanEventList.get(0);
|
||||
if (first == null) {
|
||||
throw new IllegalStateException("fist spanEvent not found");
|
||||
}
|
||||
Span parentSpan = ((SpanEvent)first).getSpan();
|
||||
|
||||
final AgentInformation agentInformation = DefaultAgent.getInstance().getAgentInformation();
|
||||
tSpanChunk.setAgentId(agentInformation.getAgentId());
|
||||
tSpanChunk.setApplicationName(agentInformation.getApplicationName());
|
||||
tSpanChunk.setAgentStartTime(agentInformation.getStartTime());
|
||||
this.setAgentId(agentInformation.getAgentId());
|
||||
this.setApplicationName(agentInformation.getApplicationName());
|
||||
this.setAgentStartTime(agentInformation.getStartTime());
|
||||
|
||||
tSpanChunk.setServiceType(parentSpan.getServiceType());
|
||||
this.setServiceType(parentSpan.getServiceType());
|
||||
|
||||
tSpanChunk.setTraceAgentId(parentSpan.getTraceAgentId());
|
||||
tSpanChunk.setTraceAgentStartTime(parentSpan.getTraceAgentStartTime());
|
||||
tSpanChunk.setTraceTransactionSequence(parentSpan.getTraceTransactionSequence());
|
||||
tSpanChunk.setSpanId(parentSpan.getSpanId());
|
||||
this.setTraceAgentId(parentSpan.getTraceAgentId());
|
||||
this.setTraceAgentStartTime(parentSpan.getTraceAgentStartTime());
|
||||
this.setTraceTransactionSequence(parentSpan.getTraceTransactionSequence());
|
||||
this.setSpanId(parentSpan.getSpanId());
|
||||
|
||||
this.setEndPoint(parentSpan.getEndPoint());
|
||||
|
||||
tSpanChunk.setEndPoint(parentSpan.getEndPoint());
|
||||
|
||||
List<TSpanEvent> tSpanEvent = createSpanEvent(spanEventList);
|
||||
List<TSpanEvent> tSpanEvent = createTSpanEvent(spanEventList);
|
||||
|
||||
tSpanChunk.setSpanEventList(tSpanEvent);
|
||||
this.setSpanEventList(tSpanEvent);
|
||||
|
||||
return tSpanChunk;
|
||||
return this;
|
||||
}
|
||||
|
||||
private List<TSpanEvent> createSpanEvent(List<SpanEvent> spanEventList) {
|
||||
List<TSpanEvent> result = new ArrayList<TSpanEvent>(spanEventList.size());
|
||||
for (SpanEvent spanEvent : spanEventList) {
|
||||
TSpanEvent tSpanEvent = new TSpanEvent();
|
||||
|
||||
private List<TSpanEvent> createTSpanEvent(List<TSpanEvent> spanEventList) {
|
||||
for (TSpanEvent tSpanEvent : spanEventList) {
|
||||
// tSpanEvent.setAgentId(Agent.getInstance().getAgentId());
|
||||
// tSpanEvent.setApplicationName(Agent.getInstance().getApplicationName());
|
||||
// tSpanEvent.setAgentIdentifier(Agent.getInstance().getPid());
|
||||
|
||||
long parentSpanStartTime = spanEvent.getParentSpan().getStartTime();
|
||||
tSpanEvent.setStartElapsed((int) (spanEvent.getStartTime() - parentSpanStartTime));
|
||||
tSpanEvent.setEndElapsed((int) (spanEvent.getEndTime() - spanEvent.getStartTime()));
|
||||
|
||||
tSpanEvent.setSequence(spanEvent.getSequence());
|
||||
|
||||
tSpanEvent.setRpc(spanEvent.getRpc());
|
||||
tSpanEvent.setServiceType(spanEvent.getServiceType().getCode());
|
||||
tSpanEvent.setDestinationId(spanEvent.getDestionationId());
|
||||
|
||||
tSpanEvent.setEndPoint(spanEvent.getEndPoint());
|
||||
|
||||
// 여기서 데이터 인코딩을 하자.
|
||||
List<TAnnotation> annotationList = new ArrayList<TAnnotation>(spanEvent.getAnnotationSize());
|
||||
for (TraceAnnotation traceAnnotation : spanEvent.getTraceAnnotationList()) {
|
||||
annotationList.add(traceAnnotation.toThrift());
|
||||
if (tSpanEvent instanceof SpanEvent) {
|
||||
((SpanEvent)tSpanEvent).toThrift(true);
|
||||
}
|
||||
|
||||
if (spanEvent.getDepth() != -1) {
|
||||
tSpanEvent.setDepth(spanEvent.getDepth());
|
||||
}
|
||||
|
||||
if (spanEvent.getNextSpanId() != -1) {
|
||||
tSpanEvent.setNextSpanId(spanEvent.getNextSpanId());
|
||||
}
|
||||
|
||||
tSpanEvent.setAnnotations(annotationList);
|
||||
result.add(tSpanEvent);
|
||||
}
|
||||
return result;
|
||||
// type check 무시.
|
||||
return spanEventList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.nhn.pinpoint.profiler.context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.nhn.pinpoint.profiler.AgentInformation;
|
||||
import com.nhn.pinpoint.profiler.DefaultAgent;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.thrift.dto.TAgentKey;
|
||||
import com.nhn.pinpoint.thrift.dto.TAnnotation;
|
||||
import com.nhn.pinpoint.thrift.dto.TSpanEvent;
|
||||
@@ -15,211 +14,86 @@ import com.nhn.pinpoint.thrift.dto.TSpanEvent;
|
||||
*
|
||||
* @author netspider
|
||||
*/
|
||||
public class SpanEvent implements Thriftable {
|
||||
public class SpanEvent extends TSpanEvent implements Thriftable {
|
||||
|
||||
private final Span parentSpan;
|
||||
private final Span span;
|
||||
|
||||
private short sequence;
|
||||
private List<TraceAnnotation> traceAnnotationList;
|
||||
|
||||
private long startTime;
|
||||
private long endTime;
|
||||
private String rpc;
|
||||
private ServiceType serviceType;
|
||||
|
||||
private String endPoint;
|
||||
|
||||
private String destionationId;
|
||||
private List<String> destinationAddress;
|
||||
|
||||
private final List<TraceAnnotation> traceAnnotationList = new ArrayList<TraceAnnotation>(4);
|
||||
|
||||
private int nextSpanId = -1;
|
||||
private int depth = -1;
|
||||
|
||||
public SpanEvent(Span parentSpan) {
|
||||
this.parentSpan = parentSpan;
|
||||
public SpanEvent(Span span) {
|
||||
if (span == null) {
|
||||
throw new NullPointerException("span must not be null");
|
||||
}
|
||||
this.span = span;
|
||||
}
|
||||
|
||||
public Span getParentSpan() {
|
||||
return parentSpan;
|
||||
}
|
||||
|
||||
public short getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public void setSequence(short sequence) {
|
||||
this.sequence = sequence;
|
||||
public Span getSpan() {
|
||||
return span;
|
||||
}
|
||||
|
||||
public boolean addAnnotation(TraceAnnotation traceAnnotation) {
|
||||
if (traceAnnotationList == null) {
|
||||
this.traceAnnotationList = new ArrayList<TraceAnnotation>(4);
|
||||
}
|
||||
return traceAnnotationList.add(traceAnnotation);
|
||||
}
|
||||
|
||||
public List<TraceAnnotation> getTraceAnnotationList() {
|
||||
return traceAnnotationList;
|
||||
}
|
||||
|
||||
public int getAnnotationSize() {
|
||||
return traceAnnotationList.size();
|
||||
}
|
||||
|
||||
public String getEndPoint() {
|
||||
return this.endPoint;
|
||||
}
|
||||
|
||||
|
||||
public String getRpc() {
|
||||
return rpc;
|
||||
}
|
||||
|
||||
public void setRpc(String rpc) {
|
||||
this.rpc = rpc;
|
||||
}
|
||||
|
||||
public void setEndPoint(String endPoint) {
|
||||
this.endPoint = endPoint;
|
||||
}
|
||||
|
||||
public String getDestionationId() {
|
||||
return destionationId;
|
||||
}
|
||||
|
||||
public void setDestionationId(String destionationId) {
|
||||
this.destionationId = destionationId;
|
||||
}
|
||||
|
||||
public List<String> getDestinationAddress() {
|
||||
return destinationAddress;
|
||||
}
|
||||
|
||||
public void setDestinationAddress(List<String> destinationAddress) {
|
||||
this.destinationAddress = destinationAddress;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
public void markStartTime() {
|
||||
// spanEvent.setStartElapsed((int) (startTime - parentSpanStartTime));
|
||||
final int startElapsed = (int)(System.currentTimeMillis() - span.getStartTime());
|
||||
this.setStartElapsed(startElapsed);
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
return span.getStartTime() + getStartElapsed();
|
||||
}
|
||||
|
||||
public void setEndTime(long endTime) {
|
||||
this.endTime = endTime;
|
||||
public void markEndTime() {
|
||||
// spanEvent.setEndElapsed((int) (endTime - startTime));
|
||||
final int endElapsed = (int)(System.currentTimeMillis() - getStartTime());
|
||||
this.setEndElapsed(endElapsed);
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
return span.getStartTime() + getStartElapsed() + getEndElapsed();
|
||||
}
|
||||
|
||||
public ServiceType getServiceType() {
|
||||
return serviceType;
|
||||
}
|
||||
|
||||
public void setServiceType(ServiceType serviceType) {
|
||||
this.serviceType = serviceType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public void setDepth(int depth) {
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
public int getNextSpanId() {
|
||||
return nextSpanId;
|
||||
}
|
||||
|
||||
public void setNextSpanId(int nextSpanId) {
|
||||
this.nextSpanId = nextSpanId;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(256);
|
||||
|
||||
sb.append("{");
|
||||
sb.append("\n\t Depth = ").append(depth);
|
||||
sb.append("\n\t NextSpanid=").append(nextSpanId);
|
||||
sb.append("\n\t ParentTraceID=").append(parentSpan.getTraceId());
|
||||
sb.append("\n\t Sequence=").append(sequence);
|
||||
sb.append(",\n\t StartTime=").append(startTime);
|
||||
sb.append(", EndTime=").append(endTime);
|
||||
sb.append(",\n\t Name=").append(rpc);
|
||||
sb.append(", ServiceType=").append(serviceType);
|
||||
sb.append(", EndPoint=").append(endPoint);
|
||||
sb.append(", Seq=").append(sequence);
|
||||
sb.append(",\n\t Annotations = {");
|
||||
for (TraceAnnotation a : traceAnnotationList) {
|
||||
sb.append("\n\t\t").append(a);
|
||||
}
|
||||
sb.append("\n\t}");
|
||||
|
||||
sb.append("}");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public TSpanEvent toThrift() {
|
||||
return toThrift(false);
|
||||
}
|
||||
|
||||
public TSpanEvent toThrift(boolean child) {
|
||||
TSpanEvent spanEvent = new TSpanEvent();
|
||||
|
||||
long parentSpanStartTime = parentSpan.getStartTime();
|
||||
spanEvent.setStartElapsed((int) (startTime - parentSpanStartTime));
|
||||
spanEvent.setEndElapsed((int) (endTime - startTime));
|
||||
|
||||
spanEvent.setSequence(sequence);
|
||||
// Span내부의 SpanEvent로 들어가지 않을 경우
|
||||
if (!child) {
|
||||
TAgentKey agentKey = new TAgentKey();
|
||||
final AgentInformation agentInformation = DefaultAgent.getInstance().getAgentInformation();
|
||||
agentKey.setAgentId(agentInformation.getAgentId());
|
||||
agentKey.setApplicationName(agentInformation.getApplicationName());
|
||||
agentKey.setAgentStartTime(agentInformation.getStartTime());
|
||||
final TAgentKey tAgentKey = DefaultAgent.getInstance().getTAgentKey();
|
||||
this.setAgentKey(tAgentKey);
|
||||
|
||||
spanEvent.setAgentKey(agentKey);
|
||||
// span 데이터 셋은 child일때만 한다.
|
||||
this.setParentServiceType(span.getServiceType()); // added
|
||||
this.setParentEndPoint(span.getEndPoint()); // added
|
||||
|
||||
spanEvent.setParentServiceType(parentSpan.getServiceType()); // added
|
||||
spanEvent.setParentEndPoint(parentSpan.getEndPoint()); // added
|
||||
|
||||
spanEvent.setTraceAgentId(parentSpan.getTraceAgentId());
|
||||
spanEvent.setTraceAgentStartTime(parentSpan.getTraceAgentStartTime());
|
||||
spanEvent.setTraceTransactionSequence(parentSpan.getTraceTransactionSequence());
|
||||
spanEvent.setSpanId(parentSpan.getSpanId());
|
||||
this.setTraceAgentId(span.getTraceAgentId());
|
||||
this.setTraceAgentStartTime(span.getTraceAgentStartTime());
|
||||
this.setTraceTransactionSequence(span.getTraceTransactionSequence());
|
||||
this.setSpanId(span.getSpanId());
|
||||
}
|
||||
|
||||
spanEvent.setRpc(rpc);
|
||||
spanEvent.setServiceType(serviceType.getCode());
|
||||
|
||||
spanEvent.setEndPoint(endPoint);
|
||||
spanEvent.setDestinationId(this.destionationId);
|
||||
|
||||
// 여기서 데이터 인코딩을 하자.
|
||||
List<TAnnotation> annotationList = new ArrayList<TAnnotation>(traceAnnotationList.size());
|
||||
for (TraceAnnotation traceAnnotation : traceAnnotationList) {
|
||||
annotationList.add(traceAnnotation.toThrift());
|
||||
if (traceAnnotationList != null) {
|
||||
List<TAnnotation> annotationList = new ArrayList<TAnnotation>(traceAnnotationList.size());
|
||||
for (TraceAnnotation traceAnnotation : traceAnnotationList) {
|
||||
annotationList.add(traceAnnotation.toThrift());
|
||||
}
|
||||
this.setAnnotations(annotationList);
|
||||
this.traceAnnotationList = null;
|
||||
}
|
||||
spanEvent.setAnnotations(annotationList);
|
||||
|
||||
if (depth != -1) {
|
||||
spanEvent.setDepth(depth);
|
||||
}
|
||||
|
||||
if (nextSpanId != -1) {
|
||||
spanEvent.setNextSpanId(nextSpanId);
|
||||
}
|
||||
|
||||
return spanEvent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setDestinationAddress() {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class SpanEventStackFrame implements StackFrame {
|
||||
|
||||
@Override
|
||||
public void markBeforeTime() {
|
||||
spanEvent.setStartTime(System.currentTimeMillis());
|
||||
spanEvent.markStartTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,7 +36,7 @@ public class SpanEventStackFrame implements StackFrame {
|
||||
|
||||
@Override
|
||||
public void markAfterTime() {
|
||||
spanEvent.setEndTime(System.currentTimeMillis());
|
||||
spanEvent.markEndTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.nhn.pinpoint.profiler.context;
|
||||
|
||||
import com.nhn.pinpoint.profiler.sender.DataSender;
|
||||
import org.apache.thrift.TBase;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -75,11 +74,11 @@ public class TimeBaseStorage implements Storage {
|
||||
}
|
||||
if (!add) {
|
||||
// add가 실패하였을 경우는 이미 span이 flush된 상태이다.
|
||||
dataSender.send(spanEvent);
|
||||
dataSender.send((Thriftable)spanEvent);
|
||||
return;
|
||||
}
|
||||
if (flushData != null) {
|
||||
dataSender.send(new SpanChunk(flushData));
|
||||
dataSender.send((Thriftable) new SpanChunk(flushData));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +96,7 @@ public class TimeBaseStorage implements Storage {
|
||||
}
|
||||
|
||||
private boolean checkLimit(SpanEvent spanEvent) {
|
||||
return checkLimit(spanEvent.getParentSpan());
|
||||
return checkLimit(spanEvent.getSpan());
|
||||
}
|
||||
|
||||
private boolean checkLimit(Span span) {
|
||||
@@ -136,7 +135,7 @@ public class TimeBaseStorage implements Storage {
|
||||
this.storage = null;
|
||||
}
|
||||
if (spanEventList != null && spanEventList.size() != 0) {
|
||||
span.setPSpanEventList(spanEventList);
|
||||
span.setSpanEventList((List)spanEventList);
|
||||
}
|
||||
dataSender.send((Thriftable)span);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -18,25 +20,23 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class JDBCUrlParser {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final ConcurrentMap<String, DefaultDatabaseInfo> cache = new ConcurrentHashMap<String, DefaultDatabaseInfo>();
|
||||
|
||||
|
||||
public DefaultDatabaseInfo parse(String url) {
|
||||
// jdbc 체크
|
||||
String lowCaseURL = url.toLowerCase().trim();
|
||||
if (!lowCaseURL.startsWith("jdbc:")) {
|
||||
return createUnknownDataBase(url);
|
||||
final DefaultDatabaseInfo hit = cache.get(url);
|
||||
if (hit != null) {
|
||||
logger.debug("database url cache hit:{} {}", url, hit);
|
||||
return hit;
|
||||
}
|
||||
|
||||
if (driverTypeCheck(lowCaseURL, "mysql")) {
|
||||
return parseMysql(url);
|
||||
final DefaultDatabaseInfo databaseInfo = doParse(url);
|
||||
final DefaultDatabaseInfo old = cache.putIfAbsent(url, databaseInfo);
|
||||
if (old != null) {
|
||||
return old;
|
||||
}
|
||||
if (driverTypeCheck(lowCaseURL, "oracle")) {
|
||||
return parseOracle(url);
|
||||
}
|
||||
if (driverTypeCheck(lowCaseURL, "cubrid")) {
|
||||
return parseCubrid(url);
|
||||
}
|
||||
return createUnknownDataBase(url);
|
||||
return databaseInfo;
|
||||
|
||||
// else if (url.indexOf("jdbc:oracle") >= 0) {
|
||||
// maker.lower().after("jdbc:oracle:").after(':');
|
||||
// info.type = TYPE.ORACLE;
|
||||
@@ -84,6 +84,25 @@ public class JDBCUrlParser {
|
||||
// return null;
|
||||
}
|
||||
|
||||
private DefaultDatabaseInfo doParse(String url) {
|
||||
// jdbc 체크
|
||||
String lowCaseURL = url.toLowerCase().trim();
|
||||
if (!lowCaseURL.startsWith("jdbc:")) {
|
||||
return createUnknownDataBase(url);
|
||||
}
|
||||
|
||||
if (driverTypeCheck(lowCaseURL, "mysql")) {
|
||||
return parseMysql(url);
|
||||
}
|
||||
if (driverTypeCheck(lowCaseURL, "oracle")) {
|
||||
return parseOracle(url);
|
||||
}
|
||||
if (driverTypeCheck(lowCaseURL, "cubrid")) {
|
||||
return parseCubrid(url);
|
||||
}
|
||||
return createUnknownDataBase(url);
|
||||
}
|
||||
|
||||
private boolean driverTypeCheck(String lowCaseURL, String type) {
|
||||
final int jdbcNextIndex = 5;
|
||||
return lowCaseURL.startsWith(type, jdbcNextIndex);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.nhn.pinpoint.profiler.context;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SpanEventTest {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Test
|
||||
public void testMarkStartTime() throws Exception {
|
||||
final DefaultTraceId traceId = new DefaultTraceId("agentTime", 0, 0);
|
||||
Span span = new Span(traceId);
|
||||
span.markBeforeTime();
|
||||
Thread.sleep(10);
|
||||
span.markEndTime();
|
||||
logger.debug("span:{}", span);
|
||||
|
||||
final SpanEvent spanEvent = new SpanEvent(span);
|
||||
spanEvent.markStartTime();
|
||||
Thread.sleep(10);
|
||||
spanEvent.markEndTime();
|
||||
logger.debug("spanEvent:{}", spanEvent);
|
||||
|
||||
Assert.assertEquals("startTime", span.getStartTime() + spanEvent.getStartElapsed(), spanEvent.getStartTime());
|
||||
Assert.assertEquals("endTime", span.getStartTime() + spanEvent.getStartElapsed() + spanEvent.getEndElapsed(), spanEvent.getEndTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStartTime() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkEndTime() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEndTime() throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user