def encode_traces(self, traces): normalized_traces = [[span.to_dict() for span in trace] for trace in traces] return self.encode(normalized_traces) @staticmethod def encode(obj): return Packer().pack(obj) @staticmethod def decode(data): return msgpack.unpackb(data, raw=True) trace_large = gen_trace(nspans=1000) trace_small = gen_trace(nspans=50, key_size=10, ntags=5, nmetrics=4) @allencodings @pytest.mark.benchmark(group="encoding", min_time=0.005) def test_encode_1000_span_trace(benchmark, encoding): benchmark(REF_MSGPACK_ENCODERS[encoding]().encode_traces, [trace_large]) @allencodings @pytest.mark.benchmark(group="encoding.small", min_time=0.005) def test_encode_trace_small(benchmark, encoding): benchmark(REF_MSGPACK_ENCODERS[encoding]().encode_traces, [trace_small])
import sys from ddtrace.internal.encoding import MSGPACK_ENCODERS as ENCODERS from tests.tracer.test_encoders import gen_trace encoder = ENCODERS[sys.argv[1]](8 << 20, 8 << 20) trace = gen_trace(nspans=1000) for i in range(200): encoder.put(trace) encoder.encode()