use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.
the class SpanSerializer method writeColumnValue.
// Variable encoding has been added in case of write io operation. The data size can be reduced by about 10%.
public ByteBuffer writeColumnValue(SpanBo span) {
/*
It is difficult to calculate the size of buffer. It's not impossible.
However just use automatic incremental buffer for convenience's sake.
Consider to reuse getBufferLength when memory can be used more efficiently later.
*/
final Buffer buffer = new AutomaticBuffer(256);
buffer.putByte(span.getRawVersion());
buffer.putPrefixedString(span.getAgentId());
// Using var makes the sie of time smaller based on the present time. That consumes only 6 bytes.
buffer.putVLong(span.getAgentStartTime());
// insert for rowkey
// buffer.put(spanID);
buffer.putLong(span.getParentSpanId());
// use var encoding because of based on the present time
buffer.putVLong(span.getStartTime());
buffer.putVInt(span.getElapsed());
buffer.putPrefixedString(span.getRpc());
buffer.putPrefixedString(span.getApplicationId());
buffer.putShort(span.getServiceType());
buffer.putPrefixedString(span.getEndPoint());
buffer.putPrefixedString(span.getRemoteAddr());
buffer.putSVInt(span.getApiId());
// errCode value may be negative
buffer.putSVInt(span.getErrCode());
if (span.hasException()) {
buffer.putBoolean(true);
buffer.putSVInt(span.getExceptionId());
buffer.putPrefixedString(span.getExceptionMessage());
} else {
buffer.putBoolean(false);
}
buffer.putShort(span.getFlag());
if (span.hasApplicationServiceType()) {
buffer.putBoolean(true);
buffer.putShort(span.getApplicationServiceType());
} else {
buffer.putBoolean(false);
}
buffer.putByte(span.getLoggingTransactionInfo());
buffer.putPrefixedString(span.getAcceptorHost());
return buffer.wrapByteBuffer();
}
use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.
the class AgentStatEncoder method encodeValue.
public ByteBuffer encodeValue(List<T> agentStatDataPoints) {
Buffer valueBuffer = new AutomaticBuffer();
valueBuffer.putByte(this.codec.getVersion());
codec.encodeValues(valueBuffer, agentStatDataPoints);
return valueBuffer.wrapByteBuffer();
}
use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.
the class AgentStatDataPointCodecTest method test_single_timestamp.
@Test
public void test_single_timestamp() {
// Given
final long givenTimestamp = System.currentTimeMillis();
final List<Long> expectedTimestamp = Arrays.asList(givenTimestamp);
final Buffer timestampBuffer = new AutomaticBuffer();
// When
codec.encodeTimestamps(timestampBuffer, expectedTimestamp);
// Then
List<Long> decodedTimestamp = codec.decodeTimestamps(givenTimestamp, new FixedBuffer(timestampBuffer.getBuffer()), 1);
Assert.assertEquals(expectedTimestamp, decodedTimestamp);
}
use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.
the class SpanEncoderV0 method encodeSpanColumnValue.
@Override
public ByteBuffer encodeSpanColumnValue(SpanEncodingContext<SpanBo> encodingContext) {
final SpanBo span = encodingContext.getValue();
final SpanBitFiled bitField = SpanBitFiled.build(span);
final Buffer buffer = new AutomaticBuffer(256);
final byte version = span.getRawVersion();
buffer.putByte(version);
// bit field
buffer.putByte(bitField.getBitField());
final short serviceType = span.getServiceType();
buffer.putShort(serviceType);
switch(bitField.getApplicationServiceTypeEncodingStrategy()) {
case PREV_EQUALS:
break;
case RAW:
buffer.putShort(span.getApplicationServiceType());
break;
default:
throw new IllegalStateException("applicationServiceType");
}
// buffer.put(spanID);
if (!bitField.isRoot()) {
buffer.putLong(span.getParentSpanId());
}
// prevSpanEvent coding
final long startTime = span.getStartTime();
final long startTimeDelta = span.getCollectorAcceptTime() - startTime;
buffer.putVLong(startTimeDelta);
buffer.putVInt(span.getElapsed());
buffer.putPrefixedString(span.getRpc());
buffer.putPrefixedString(span.getEndPoint());
buffer.putPrefixedString(span.getRemoteAddr());
buffer.putSVInt(span.getApiId());
// BIT flag
if (bitField.isSetErrorCode()) {
buffer.putInt(span.getErrCode());
}
if (bitField.isSetHasException()) {
buffer.putSVInt(span.getExceptionId());
buffer.putPrefixedString(span.getExceptionMessage());
}
if (bitField.isSetFlag()) {
buffer.putShort(span.getFlag());
}
if (bitField.isSetLoggingTransactionInfo()) {
buffer.putByte(span.getLoggingTransactionInfo());
}
buffer.putPrefixedString(span.getAcceptorHost());
if (bitField.isSetAnnotation()) {
List<AnnotationBo> annotationBoList = span.getAnnotationBoList();
writeAnnotationList(buffer, annotationBoList, encodingContext);
}
final List<SpanEventBo> spanEventBoList = span.getSpanEventBoList();
writeSpanEventList(buffer, spanEventBoList, encodingContext);
return buffer.wrapByteBuffer();
}
use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.
the class SpanEncoderV0 method encodeQualifier.
private ByteBuffer encodeQualifier(byte type, String applicationId, String agentId, long agentStartTime, long spanId, SpanEventBo firstEvent) {
final Buffer buffer = new AutomaticBuffer(128);
buffer.putByte(type);
buffer.putPrefixedString(applicationId);
buffer.putPrefixedString(agentId);
buffer.putVLong(agentStartTime);
buffer.putLong(spanId);
if (firstEvent != null) {
buffer.putSVInt(firstEvent.getSequence());
final byte bitField = SpanEventQualifierBitField.buildBitField(firstEvent);
buffer.putByte(bitField);
// case : async span
if (SpanEventQualifierBitField.isSetAsync(bitField)) {
buffer.putInt(firstEvent.getAsyncId());
buffer.putVInt(firstEvent.getAsyncSequence());
}
} else {
// simple trace case
// buffer.putSVInt((short) -1);
// byte cfBitField = SpanEventQualifierBitField.setAsync((byte) 0, false);
// buffer.putByte(cfBitField);
}
return buffer.wrapByteBuffer();
}
Aggregations