Skip to content

Encoded Histogram format

Lee Campbell edited this page May 10, 2016 · 5 revisions

The Encoded Histogram format is a binary format of a histogram header and its count values. The format is used as part of the V2-Log-Encoding to allow histograms to be persisted or shared.

File format

[cookie][lengthOfCompressedContents][CompressedHeader]

CompressedHeader format

DEFALTE(
	[Cookie][payloadLengthInBytes][normalizingIndexOffset][numberOfSignificantValueDigits][lowestTrackableUnitValue][highestTrackableValue][integerToDoubleValueConversionRatio][CompressedContents]		
)

The Zlib compressed payload of an HdrHistogram. The uncompressed payload is stored in binary in the following format

01234567890123456789012345678901
[A ][B ][C ][D ][E     ][F     ][G....>
  • A. Cookie value. 32bit integer (4bytes) that stores a code for the type of Histogram.
  • B. Payload length as a 32bit integer (4bytes).
  • C. NomalizingIndex offset as an 32bit integer (4bytes). Currently not implemented in HdrHistogram.NET
  • D. Lowest Trackable Unit value as a 64bit integer (8bytes).
  • E. Highest Trackable Unit value as a 64bit integer (8bytes).
  • F. Integer to double conversion ratio as a double floating point number (8bytes)
  • G. Compressed contents

CompressedContents

ZigZaggedEncoding(
	[count]*
)

A ZigZag encoded (LEB128-64b9B-variant format) compression of the counts for an HdrHistogram. The LEB128-64b9B-variant format is

  • Little Endian Base128 Encoding
  • 64bit values store as a maximum of 9Bytes. The standard LEB128 can use 10Bytes.
  • Zig Zagged so that common/small positive and negative values use the least amount of space.
  • Only supports values up to 2^63 (not 2^64) i.e. HdrHistogram only support positive signed long values for counts.

Consecutive 0 counts will be compressed into a single negative number indicating the span of the zero count sequence. Positive counts will be represented as the actual number. Counts are recorded as 64bit integers.

See also

  • ZLIB RCF-1950 compression - [https://en.wikipedia.org/wiki/Zlib], [https://www.ietf.org/rfc/rfc1950.txt]
  • Base64 Encoding - [https://en.wikipedia.org/wiki/Base64], [https://www.base64encode.org/]
  • ZigZag LEB128 compression - [https://en.wikipedia.org/wiki/LEB128]

Clone this wiki locally