Search in sources :

Example 26 with AutomaticBuffer

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();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) ByteBuffer(java.nio.ByteBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer)

Example 27 with AutomaticBuffer

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();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) ByteBuffer(java.nio.ByteBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer)

Example 28 with AutomaticBuffer

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);
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) Test(org.junit.Test)

Example 29 with AutomaticBuffer

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();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) ByteBuffer(java.nio.ByteBuffer) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) SpanBitFiled(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanBitFiled) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo)

Example 30 with AutomaticBuffer

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();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) ByteBuffer(java.nio.ByteBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer)

Aggregations

AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)39 Buffer (com.navercorp.pinpoint.common.buffer.Buffer)39 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)13 ByteBuffer (java.nio.ByteBuffer)9 Test (org.junit.Test)6 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)4 AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)3 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)2 BasicSpan (com.navercorp.pinpoint.common.server.bo.BasicSpan)2 Put (org.apache.hadoop.hbase.client.Put)2 ApiMetaDataBo (com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo)1 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)1 SpanChunkBo (com.navercorp.pinpoint.common.server.bo.SpanChunkBo)1 EncodingStrategy (com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy)1 AgentStatDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.stat.AgentStatDecodingContext)1 SpanBitFiled (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanBitFiled)1 AgentStatDataPoint (com.navercorp.pinpoint.common.server.bo.stat.AgentStatDataPoint)1 HistogramSlot (com.navercorp.pinpoint.common.trace.HistogramSlot)1 TransactionId (com.navercorp.pinpoint.common.util.TransactionId)1 TIntStringStringValue (com.navercorp.pinpoint.thrift.dto.TIntStringStringValue)1