HdrHistogram_c: 'C' port of High Dynamic Range (HDR) Histogram
This port contains a subset of the functionality supported by the Java implementation. The current supported features are:
- Standard histogram with 64 bit counts (32/16 bit counts not supported)
- All iterator types (all values, recorded, percentiles, linear, logarithmic)
- Histogram serialisation (encoding version 1.2, decoding 1.0-1.2)
- Reader/writer phaser and interval recorder
- Sparse histogram (
hdr_packed_histogram, seeinclude/hdr/hdr_packed_histogram.h): a separate, opt-in type whose storage grows with the number of populated buckets, with counts kept in 1, 2, 4 or 8 bytes as needed. Much smaller when you hold many sparsely populated histograms, at the cost of slower recording and no atomic recording; it serialises to the standard compressed format
Features not supported, but planned
- Auto-resizing of histograms
Features unlikely to be implemented
- Double histograms
- Atomic/Concurrent histograms
- 16/32 bit histograms
Embedding the library (minimal static core without zlib/threads, custom allocator, disabling the AVX2 scan): see docs/EMBEDDING.md.
To vendor the library as a few generated files instead of the whole tree, an amalgamation is
attached to each release and generated by script/amalgamate.py: the core on its own
(hdr_histogram.c and hdr_histogram.h), or with the log codec (--with-log), and for trees
that keep the headers in a hdr/ directory (--include-prefix hdr/); see
docs/AMALGAMATION.md.
#include <hdr_histogram.h>
struct hdr_histogram* histogram;
// Initialise the histogram
hdr_init(
1, // Minimum value
INT64_C(3600000000), // Maximum value
3, // Number of significant figures
&histogram) // Pointer to initialise
// Record value
hdr_record_value(
histogram, // Histogram to record to
value) // Value to record
// Record value n times
hdr_record_values(
histogram, // Histogram to record to
value, // Value to record
10) // Record value 10 times
// Record value with correction for co-ordinated omission.
hdr_record_corrected_value(
histogram, // Histogram to record to
value, // Value to record
1000) // Record with expected interval of 1000.
// Print out the values of the histogram
hdr_percentiles_print(
histogram,
stdout, // File to write to
5, // Granularity of printed values
1.0, // Multiplier for results
CLASSIC); // Format CLASSIC/CSV supported.For more detailed examples of recording and logging results look at the hdr_decoder and hiccup examples. You can run hiccup and decoder and pipe the results of one into the other.
$ ./examples/hiccup | ./examples/hdr_decoder
