Search in sources :

Example 21 with TSpanEvent

use of com.navercorp.pinpoint.thrift.dto.TSpanEvent in project pinpoint by naver.

the class SpanStreamSendDataSerializer method serializeSpanChunkStream.

public PartitionedByteBufferLocator serializeSpanChunkStream(HeaderTBaseSerializer serializer, TSpanChunk spanChunk) {
    PartitionedByteBufferLocator.Builder partitionedByteBufferLocatorBuilder = new PartitionedByteBufferLocator.Builder();
    List<TSpanEvent> spanEventList = spanChunk.getSpanEventList();
    if (spanEventList != null) {
        for (TSpanEvent spanEvent : spanEventList) {
            int bufferStartIndex = serializer.getInterBufferSize();
            try {
                byte[] buffer = serializer.continueSerialize(spanEvent);
                int bufferEndIndex = serializer.getInterBufferSize();
                partitionedByteBufferLocatorBuilder.addIndex(bufferStartIndex, bufferEndIndex);
            } catch (TException e) {
                logger.warn("Serialize fail. value:{}.", spanEvent, e);
                serializer.reset(bufferStartIndex);
            }
        }
    }
    TSpanChunk copiedSpanChunk = copySpanChunkWithoutSpanEvent(spanChunk);
    try {
        int bufferStartIndex = serializer.getInterBufferSize();
        byte[] buffer = serializer.continueSerialize(copiedSpanChunk);
        int bufferEndIndex = serializer.getInterBufferSize();
        partitionedByteBufferLocatorBuilder.addIndex(bufferStartIndex, bufferEndIndex);
        partitionedByteBufferLocatorBuilder.setBuffer(buffer);
        return partitionedByteBufferLocatorBuilder.build();
    } catch (TException e) {
        logger.warn("Serialize fail. value:{}.", copiedSpanChunk, e);
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent)

Example 22 with TSpanEvent

use of com.navercorp.pinpoint.thrift.dto.TSpanEvent in project pinpoint by naver.

the class SpanStreamSendDataSerializer method serializeSpanStream.

public PartitionedByteBufferLocator serializeSpanStream(HeaderTBaseSerializer serializer, TSpan span) {
    PartitionedByteBufferLocator.Builder partitionedByteBufferLocatorBuilder = new PartitionedByteBufferLocator.Builder();
    List<TSpanEvent> spanEventList = span.getSpanEventList();
    if (spanEventList != null) {
        for (TSpanEvent spanEvent : spanEventList) {
            int bufferStartIndex = serializer.getInterBufferSize();
            try {
                byte[] buffer = serializer.continueSerialize(spanEvent);
                int bufferEndIndex = serializer.getInterBufferSize();
                partitionedByteBufferLocatorBuilder.addIndex(bufferStartIndex, bufferEndIndex);
            } catch (TException e) {
                logger.warn("Serialize fail. value:{}.", spanEvent, e);
                serializer.reset(bufferStartIndex);
            }
        }
    }
    TSpan copiedSpan = copySpanWithoutSpanEvent(span);
    try {
        int bufferStartIndex = serializer.getInterBufferSize();
        byte[] buffer = serializer.continueSerialize(copiedSpan);
        int bufferEndIndex = serializer.getInterBufferSize();
        partitionedByteBufferLocatorBuilder.addIndex(bufferStartIndex, bufferEndIndex);
        partitionedByteBufferLocatorBuilder.setBuffer(buffer);
        return partitionedByteBufferLocatorBuilder.build();
    } catch (TException e) {
        logger.warn("Serialize fail. value:{}.", copiedSpan, e);
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent)

Example 23 with TSpanEvent

use of com.navercorp.pinpoint.thrift.dto.TSpanEvent in project pinpoint by naver.

the class SpanStreamSendDataSerializerTest method spanStreamSendDataSerializerTest1.

@Test
public void spanStreamSendDataSerializerTest1() throws InterruptedException, TException {
    int spanEventSize = 10;
    SpanStreamSendDataSerializer serializer = new SpanStreamSendDataSerializer();
    HeaderTBaseSerializerFactory factory = new HeaderTBaseSerializerFactory();
    SpanChunk spanChunk = spanChunkFactory.create(createSpanEventList(spanEventSize));
    PartitionedByteBufferLocator partitionedByteBufferLocator = serializer.serializeSpanChunkStream(factory.createSerializer(), spanChunk);
    Assert.assertEquals(spanEventSize + 1, partitionedByteBufferLocator.getPartitionedCount());
    HeaderTBaseDeserializer deserializer = new HeaderTBaseDeserializerFactory().createDeserializer();
    for (int i = 0; i < partitionedByteBufferLocator.getPartitionedCount(); i++) {
        ByteBuffer byteBuffer = partitionedByteBufferLocator.getByteBuffer(i);
        byte[] readBuffer = new byte[byteBuffer.remaining()];
        byteBuffer.get(readBuffer);
        Object o = deserializer.deserialize(readBuffer);
        if (o == null) {
            Assert.fail();
        }
        if (i < spanEventSize) {
            Assert.assertTrue(o instanceof TSpanEvent);
        } else {
            Assert.assertTrue(o instanceof TSpanChunk);
        }
    }
}
Also used : TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) HeaderTBaseSerializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory) SpanChunk(com.navercorp.pinpoint.profiler.context.SpanChunk) TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) HeaderTBaseDeserializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory) ByteBuffer(java.nio.ByteBuffer) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) Test(org.junit.Test)

Example 24 with TSpanEvent

use of com.navercorp.pinpoint.thrift.dto.TSpanEvent in project pinpoint by naver.

the class SpanStreamSendDataSerializerTest method spanStreamSendDataSerializerTest2.

@Test
public void spanStreamSendDataSerializerTest2() throws InterruptedException, TException {
    int spanEventSize = 10;
    SpanStreamSendDataSerializer serializer = new SpanStreamSendDataSerializer();
    HeaderTBaseSerializerFactory factory = new HeaderTBaseSerializerFactory();
    Span span = createSpan(createSpanEventList(spanEventSize));
    PartitionedByteBufferLocator partitionedByteBufferLocator = serializer.serializeSpanStream(factory.createSerializer(), span);
    Assert.assertEquals(spanEventSize + 1, partitionedByteBufferLocator.getPartitionedCount());
    HeaderTBaseDeserializer deserializer = new HeaderTBaseDeserializerFactory().createDeserializer();
    for (int i = 0; i < partitionedByteBufferLocator.getPartitionedCount(); i++) {
        ByteBuffer byteBuffer = partitionedByteBufferLocator.getByteBuffer(i);
        byte[] readBuffer = new byte[byteBuffer.remaining()];
        byteBuffer.get(readBuffer);
        Object o = deserializer.deserialize(readBuffer);
        if (o == null) {
            Assert.fail();
        }
        if (i < spanEventSize) {
            Assert.assertTrue(o instanceof TSpanEvent);
        } else {
            Assert.assertTrue(o instanceof TSpan);
        }
    }
}
Also used : HeaderTBaseSerializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) Span(com.navercorp.pinpoint.profiler.context.Span) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) HeaderTBaseDeserializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory) ByteBuffer(java.nio.ByteBuffer) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) Test(org.junit.Test)

Example 25 with TSpanEvent

use of com.navercorp.pinpoint.thrift.dto.TSpanEvent in project pinpoint by naver.

the class SpanChunkStreamSendDataPlanerTest method spanChunkStreamSendDataPlanerTest.

@Test
public void spanChunkStreamSendDataPlanerTest() throws Exception {
    int spanEventSize = 10;
    SpanStreamSendDataSerializer serializer = new SpanStreamSendDataSerializer();
    HeaderTBaseSerializerFactory headerTBaseSerializerFactory = new HeaderTBaseSerializerFactory();
    List<SpanEvent> originalSpanEventList = createSpanEventList(spanEventSize);
    SpanChunk spanChunk = spanChunkFactory.create(originalSpanEventList);
    PartitionedByteBufferLocator partitionedByteBufferLocator = serializer.serializeSpanChunkStream(headerTBaseSerializerFactory.createSerializer(), spanChunk);
    SpanStreamSendDataFactory factory = new SpanStreamSendDataFactory(100, 50, objectPool);
    List<TSpanEvent> spanEventList = getSpanEventList(partitionedByteBufferLocator, factory);
    partitionedByteBufferLocator = serializer.serializeSpanChunkStream(headerTBaseSerializerFactory.createSerializer(), spanChunk);
    factory = new SpanStreamSendDataFactory(objectPool);
    List<TSpanEvent> spanEventList2 = getSpanEventList(partitionedByteBufferLocator, factory);
    Assert.assertEquals(spanEventSize, spanEventList.size());
    Assert.assertEquals(spanEventSize, spanEventList2.size());
}
Also used : SpanStreamSendDataFactory(com.navercorp.pinpoint.profiler.sender.SpanStreamSendDataFactory) SpanStreamSendDataSerializer(com.navercorp.pinpoint.profiler.sender.SpanStreamSendDataSerializer) HeaderTBaseSerializerFactory(com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory) SpanChunk(com.navercorp.pinpoint.profiler.context.SpanChunk) SpanEvent(com.navercorp.pinpoint.profiler.context.SpanEvent) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) PartitionedByteBufferLocator(com.navercorp.pinpoint.profiler.sender.PartitionedByteBufferLocator) Test(org.junit.Test)

Aggregations

TSpanEvent (com.navercorp.pinpoint.thrift.dto.TSpanEvent)30 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 ByteBuffer (java.nio.ByteBuffer)8 TSpanChunk (com.navercorp.pinpoint.thrift.dto.TSpanChunk)7 TSpan (com.navercorp.pinpoint.thrift.dto.TSpan)6 HeaderTBaseDeserializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer)4 HeaderTBaseDeserializerFactory (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializerFactory)4 HeaderTBaseSerializerFactory (com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializerFactory)4 Span (com.navercorp.pinpoint.profiler.context.Span)3 SpanEvent (com.navercorp.pinpoint.profiler.context.SpanEvent)3 TransactionId (com.navercorp.pinpoint.common.util.TransactionId)2 SpanChunk (com.navercorp.pinpoint.profiler.context.SpanChunk)2 PartitionedByteBufferLocator (com.navercorp.pinpoint.profiler.sender.PartitionedByteBufferLocator)2 SpanStreamSendData (com.navercorp.pinpoint.profiler.sender.SpanStreamSendData)2 SpanStreamSendDataFactory (com.navercorp.pinpoint.profiler.sender.SpanStreamSendDataFactory)2 SpanStreamSendDataSerializer (com.navercorp.pinpoint.profiler.sender.SpanStreamSendDataSerializer)2 TBase (org.apache.thrift.TBase)2 TException (org.apache.thrift.TException)2 RandomTSpan (com.navercorp.pinpoint.common.server.bo.RandomTSpan)1