Search in sources :

Example 56 with AutomaticBuffer

use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.

the class EncodingStrategyTestBase method getBufferSizes.

private Map<EncodingStrategy<T>, Integer> getBufferSizes(List<T> values) {
    Map<EncodingStrategy<T>, Integer> bufferSizes = new HashMap<>();
    for (EncodingStrategy<T> strategy : getEncodingStrategies()) {
        Buffer encodedBuffer = new AutomaticBuffer();
        codec.encodeValues(encodedBuffer, strategy, values);
        int encodedBufferSize = encodedBuffer.getBuffer().length;
        bufferSizes.put(strategy, encodedBufferSize);
    }
    logger.debug("Strategies : {}", bufferSizes);
    return bufferSizes;
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) HashMap(java.util.HashMap) EncodingStrategy(com.navercorp.pinpoint.common.server.bo.codec.strategy.EncodingStrategy) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer)

Example 57 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 58 with AutomaticBuffer

use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.

the class ApplicationMapStatisticsUtils method makeRowKey.

/**
 * <pre>
 * rowkey format = "APPLICATIONNAME(max 24bytes)" + apptype(2byte) + "TIMESTAMP(8byte)"
 * </pre>
 *
 * @param applicationName
 * @param timestamp
 * @return
 */
public static byte[] makeRowKey(String applicationName, short applicationType, long timestamp) {
    Objects.requireNonNull(applicationName, "applicationName");
    final byte[] applicationNameBytes = BytesUtils.toBytes(applicationName);
    final Buffer buffer = new AutomaticBuffer(2 + applicationNameBytes.length + 2 + 8);
    // buffer.put2PrefixedString(applicationName);
    buffer.putShort((short) applicationNameBytes.length);
    buffer.putBytes(applicationNameBytes);
    buffer.putShort(applicationType);
    long reverseTimeMillis = TimeUtils.reverseTimeMillis(timestamp);
    buffer.putLong(reverseTimeMillis);
    return buffer.getBuffer();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer)

Example 59 with AutomaticBuffer

use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.

the class ApplicationMapStatisticsUtils method makeColumnName.

public static byte[] makeColumnName(short serviceType, String applicationName, String destHost, short slotNumber) {
    Objects.requireNonNull(applicationName, "applicationName");
    destHost = StringUtils.defaultString(destHost, "");
    // approximate size of destHost
    final Buffer buffer = new AutomaticBuffer(BytesUtils.SHORT_BYTE_LENGTH + PinpointConstants.APPLICATION_NAME_MAX_LEN + destHost.length() + BytesUtils.SHORT_BYTE_LENGTH);
    buffer.putShort(serviceType);
    buffer.putShort(slotNumber);
    buffer.put2PrefixedString(applicationName);
    buffer.putBytes(BytesUtils.toBytes(destHost));
    return buffer.getBuffer();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer)

Example 60 with AutomaticBuffer

use of com.navercorp.pinpoint.common.buffer.AutomaticBuffer in project pinpoint by naver.

the class TransactionCodecTest method encodeValuesTest.

@Test
public void encodeValuesTest() {
    final String id = "test_app";
    final long currentTime = new Date().getTime();
    TransactionCodec transactionCodec = new TransactionCodec(new AgentStatDataPointCodec());
    final Buffer encodedValueBuffer = new AutomaticBuffer();
    final List<JoinStatBo> joinTransactionBoList = createJoinTransactionBoList(currentTime);
    encodedValueBuffer.putByte(transactionCodec.getVersion());
    transactionCodec.encodeValues(encodedValueBuffer, joinTransactionBoList);
    final Buffer valueBuffer = new FixedBuffer(encodedValueBuffer.getBuffer());
    final long baseTimestamp = AgentStatUtils.getBaseTimestamp(currentTime);
    final long timestampDelta = currentTime - baseTimestamp;
    final ApplicationStatDecodingContext decodingContext = new ApplicationStatDecodingContext();
    decodingContext.setApplicationId(id);
    decodingContext.setBaseTimestamp(baseTimestamp);
    decodingContext.setTimestampDelta(timestampDelta);
    assertEquals(valueBuffer.readByte(), transactionCodec.getVersion());
    List<JoinStatBo> decodedJoinTransactionBoList = transactionCodec.decodeValues(valueBuffer, decodingContext);
    for (int i = 0; i < decodedJoinTransactionBoList.size(); i++) {
        assertEquals(decodedJoinTransactionBoList.get(i), joinTransactionBoList.get(i));
    }
}
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) ApplicationStatDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.stat.ApplicationStatDecodingContext) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) JoinStatBo(com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo) Date(java.util.Date) AgentStatDataPointCodec(com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec) Test(org.junit.Test)

Aggregations

AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)68 Buffer (com.navercorp.pinpoint.common.buffer.Buffer)68 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)30 Test (org.junit.Test)16 ByteBuffer (java.nio.ByteBuffer)15 AgentStatDataPointCodec (com.navercorp.pinpoint.common.server.bo.codec.stat.AgentStatDataPointCodec)10 ApplicationStatDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.stat.ApplicationStatDecodingContext)10 JoinStatBo (com.navercorp.pinpoint.common.server.bo.stat.join.JoinStatBo)10 Date (java.util.Date)10 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)4 Put (org.apache.hadoop.hbase.client.Put)4 AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)3 IntStringStringValue (com.navercorp.pinpoint.common.util.IntStringStringValue)3 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)2 BasicSpan (com.navercorp.pinpoint.common.server.bo.BasicSpan)2 StringStringValue (com.navercorp.pinpoint.common.util.StringStringValue)2 TableName (org.apache.hadoop.hbase.TableName)2 VisibleForTesting (com.navercorp.pinpoint.common.annotations.VisibleForTesting)1 TransactionId (com.navercorp.pinpoint.common.profiler.util.TransactionId)1 ApiMetaDataBo (com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo)1