.
Copyright (c) 2014 Darach Ennis
Version: 0.2.0
Authors: Darach Ennis (darach@gmail.com
).
The HDR histogram library is an Erlang native interface function wrapper of Mike Barker's C port of Gil Tene's HDR Histogram utility.
A high dynamic range histogram is one that supports recording and analyzing sampled data points across a configurable range with configurable precision within that range. The precision is expressed as a number of significant figures in the recording.
This HDR histogram implementation is designed for recording histograms of value measurements in latency sensitive environments. Although the native recording times can be as low as single digit nanoseconds there is added overhead in this wrapper/binding due to both the frontend overhead of converting from native C to the NIF interface, and the erlang overhead incurred calling into the NIFs. C'est la vie, I suppose.
A distinct advantage of this histogram implementation is constant space and recording (time) overhead with an ability to recycle and reset instances whilst reclaiming already allocated space for reuse thereby reducing allocation cost and garbage collection overhead in the BEAM where repeated or continuous usage is likely. For example, a gen_server recording metrics continuously and resetting and logging histogram dumps on a periodic or other windowed basis.
The code is released to the public domain, under the same terms as its sibling projects, as explained in the LICENSE.txt and COPYING.txt in the root of this repository, but normatively at:
http://creativecommons.org/publicdomain/zero/1.0/
For users of this code who wish to consume it under the "BSD" license rather than under the public domain or CC0 contribution text mentioned above, the code found under this directory is also provided under the following license (commonly referred to as the BSD 2-Clause License). This license does not detract from the above stated release of the code into the public domain, and simply represents an additional license granted by http://creativecommons.org/publicdomain/zero/1.0/
** Beginning of "BSD 2-Clause License" text. **
Copyright (c) 2012, 2013, 2014 Gil Tene Copyright (c) 2014 Michael Barker Copyright (c) 2014 Darach Ennis All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ref() = binary()
NIF private data (looks like empty binary)
add/2 | Contribute the data points from a HDR histogram to another. |
close/1 | Close this HDR histogram instance and free any system resources. |
count_at/2 | Get the count of values at a given at a given value. |
from_binary/1 | Take a snapshot of HDR histogram internal state as a compressed binary and hydrate/open a reference. |
get_memory_size/1 | Get memory footprint of an HDR histogram. |
get_total_count/1 | Get total count of record values. |
log/3 | Log the histogram to a file in classic or CSV format. |
lowest_at/2 | Get the lowest equivalent value. |
max/1 | Get the maximum recorded data point value. |
mean/1 | Get the mean data point value to a significant figure. |
median/1 | Get the median data point value to a significant figure. |
min/1 | Get the minimum recorded data point value. |
open/2 | Open a fresh instance of a high dynamic range (HDR) histogram. |
percentile/2 | Get the specified percentile data point value to a significant figure. |
print/2 | Print the histogram to standard output in classic or CSV format. |
record/2 | Record an uncorrected histogram data point value in a HDR histogram. |
record_corrected/3 | Record a histogram data point value in a HDR histogram with expected interval for correction for coordinated ommission. |
record_many/3 | Record a histogram data point value and number of occurances. |
reset/1 | Reset the memory backing this HDR histogram instance and zero results. |
rotate/2 | Copy data from Ref to To and return the difference as binary. |
same/3 | Are two data point values considered to be equivalent. |
stddev/1 | Get the standard deviation data point value to a significant figure. |
to_binary/1 | Take a snapshot of HDR histogram internal state as a compressed binary. |
to_binary/2 | Take a snapshot of HDR histogram internal state as an (optionally) compressed binary. |
add(To, From) -> integer() | {error, Reason}
Contribute the data points from a HDR histogram to another.
Return the number of dropped data point values.
That is, the values from From
that are higher than the
HighestTrackableValue
of To
.
close(Ref) -> ok | {error, term()}
Ref = ref()
Close this HDR histogram instance and free any system resources
count_at(Ref, Value) -> CountAt
Ref = ref()
Value = integer()
CountAt = integer()
Get the count of values at a given at a given value
from_binary(Binary) -> {ok, Ref} | {error, term()}
Binary = binary()
Ref = ref()
Take a snapshot of HDR histogram internal state as a compressed binary and hydrate/open a reference. The reference SHOULD be closed when no longer needed to reclaim the memory used
get_memory_size(Ref) -> Size
Ref = ref()
Size = integer()
Get memory footprint of an HDR histogram
get_total_count(Ref) -> Count
Ref = ref()
Count = integer()
Get total count of record values
log(Ref, Format, FileName::file:name()) -> ok | {error, Reason}
Ref = ref()
Format = classic | csv
Reason = term()
Log the histogram to a file in classic or CSV format
lowest_at(Ref, Value) -> LowestValueAt
Ref = ref()
Value = integer()
LowestValueAt = float()
Get the lowest equivalent value
max(Ref) -> MaxValue
Ref = ref()
MaxValue = integer()
Get the maximum recorded data point value
mean(Ref) -> MeanValue
Ref = ref()
MeanValue = float()
Get the mean data point value to a significant figure
median(Ref) -> MedianValue
Ref = ref()
MedianValue = float()
Get the median data point value to a significant figure
min(Ref) -> MinValue
Ref = ref()
MinValue = integer()
Get the minimum recorded data point value
open(HighestTrackableValue, SignificantFigures) -> {ok, Ref} | {error, Reason}
HighestTrackableValue = integer()
SignificantFigures = 1..5
Ref = ref()
Reason = term()
Open a fresh instance of a high dynamic range (HDR) histogram
percentile(Ref, Percentile) -> PercentileValue
Ref = ref()
Percentile = float()
PercentileValue = float()
Get the specified percentile data point value to a significant figure
print(Ref, Format) -> ok | {error, Reason}
Ref = ref()
Format = classic | csv
Reason = term()
Print the histogram to standard output in classic or CSV format
record(Ref, Value) -> ok | {error, Reason}
Ref = ref()
Value = integer()
Reason = term()
Record an uncorrected histogram data point value in a HDR histogram
record_corrected(Ref, Value, ExpectedInterval) -> ok | {error, Reason}
Ref = ref()
Value = integer()
ExpectedInterval = integer()
Reason = term()
Record a histogram data point value in a HDR histogram with expected interval for correction for coordinated ommission
record_many(Ref, Value, Count) -> ok | {error, Reason}
Ref = ref()
Value = integer()
Count = integer()
Reason = term()
Record a histogram data point value and number of occurances
reset(Ref) -> ok | {error, term()}
Ref = ref()
Reset the memory backing this HDR histogram instance and zero results
rotate(Ref, To) -> Diff::binary() | {error, term()}
Copy data from Ref to To and return the difference as binary
same(Ref, A, B) -> AreEquivalent
Ref = ref()
A = integer()
B = integer()
AreEquivalent = boolean()
Are two data point values considered to be equivalent
stddev(Ref) -> StddevValue
Ref = ref()
StddevValue = float()
Get the standard deviation data point value to a significant figure
to_binary(Ref) -> binary() | {error, term()}
Ref = ref()
Take a snapshot of HDR histogram internal state as a compressed binary. The reference HDR instance can be modified after a snapshot is taken in the usual way with no restrictions.
to_binary(Ref, X2::[{compression, none} | {compression, zlib}]) -> binary() | {error, term()}
Ref = ref()
Take a snapshot of HDR histogram internal state as an (optionally) compressed binary. The reference HDR instance can be modified after a snapshot is taken in the usual way with no restrictions.