#protobuf #profiling #encode #datadog #varint #value-type #pprof #string-table #happen #int32

libdd-profiling-protobuf

Protobuf utils for Datadog's continuous profiling library

2 stable releases

new 2.0.0 Apr 15, 2026
1.0.0 Nov 17, 2025

#2905 in Encoding


Used in libdd-profiling

Apache-2.0

46KB
902 lines

This crate implements Protobuf encoders for profiles which write to a Write. It has encoders for:

  • [Function]
  • [Label]
  • [Location] and [Line]
  • [Mapping]
  • [Sample]
  • [ValueType]

There is no encoder for a Profile message. It would require borrowing a lot of data, which becomes unwieldy. It also isn't very compatible with writing a streaming serializer to lower peak memory usage.

Encoding often happens one byte at a time, so a buffered writer should probably be used.

Indices into the string table are represented by [StringOffset], which uses a 32-bit number. ID fields are still 64-bit, so the user can control their values, potentially using a 64-bit address for its value.

The types are generally #[repr(C)] so they can be used in FFI one day.

Here is a condensed reference for the parts of protobuf used by profiles:

message    := (tag value)*
tag        := (field << 3) bit-or wire_type;
                encoded as uint32 varint
value      := varint      for wire_type == VARINT,
              len-prefix  for wire_type == LEN,
varint     := int64 | uint64
len-prefix := size (message | string | packed);
                size encoded as int32 varint
string     := valid UTF-8 string;
                max 2GB of bytes
packed     := varint*
                consecutive values of the type specified in `.proto`

A Record represents a [Tag] and Value pair, where the WireType comes from Value::WIRE_TYPE.

Protos must be smaller than 2 GiB when encoded. Many proto implementations will refuse to encode or decode messages that exceed this limit.


libdd-profiling-protobuf

Protocol buffer definitions and implementations for the profiling pprof format.

Overview

libdd-profiling-protobuf provides Rust types and serialization support for Google's pprof protocol buffer format, used for representing profiling data.

Dependencies

~0–0.8MB
~18K SLoC