Class: HDRHistogram
- Inherits:
-
Object
- Object
- HDRHistogram
- Defined in:
- lib/HDRHistogram.rb,
lib/HDRHistogram/version.rb,
ext/ruby_hdr_histogram/ruby_hdr_histogram.c
Defined Under Namespace
Classes: HDRHistogramError
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
- #multiplier ⇒ Object readonly
- #unit ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #count ⇒ Object
- #highest_trackable_value ⇒ Object
-
#initialize(lowest, highest, sig, opt = {}) ⇒ HDRHistogram
constructor
A new instance of HDRHistogram.
- #latency_stats ⇒ Object
- #lowest_trackable_value ⇒ Object
- #max ⇒ Object
- #mean ⇒ Object
- #memsize ⇒ Object
- #merge(other) ⇒ Object
- #min ⇒ Object
- #percentile(pct) ⇒ Object
- #record(val) ⇒ Object
- #record_corrected(val) ⇒ Object
- #reset ⇒ Object
- #significant_figures ⇒ Object
- #stats(percentiles = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) ⇒ Object
- #stddev ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(lowest, highest, sig, opt = {}) ⇒ HDRHistogram
Returns a new instance of HDRHistogram.
5 6 7 8 |
# File 'lib/HDRHistogram.rb', line 5 def initialize(lowest, highest, sig, opt={}) @multiplier = opt[:multiplier] || 1 @unit = opt[:unit] || opt[:units] end |
Instance Attribute Details
#multiplier ⇒ Object (readonly)
#unit ⇒ Object (readonly)
Class Method Details
.new(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'ext/ruby_hdr_histogram/ruby_hdr_histogram.c', line 18
static VALUE histogram_new(int argc, VALUE* argv, VALUE class) {
VALUE self, lowest_value, highest_value, significant_figures;
VALUE opt;
struct hdr_histogram *hdrh;
int ret;
rb_scan_args(argc, argv, "31", &lowest_value, &highest_value, &significant_figures, &opt);
lowest_value = rb_funcall(class, rb_intern("adjusted_boundary_val"), 2, lowest_value, opt);
highest_value = rb_funcall(class, rb_intern("adjusted_boundary_val"), 2, highest_value, opt);
ret = hdr_init(NUM2INT(lowest_value), NUM2INT(highest_value), NUM2INT(significant_figures), &hdrh);
if(ret == EINVAL) {
rb_raise(HDRHistogramError, "%s", "lowest_trackable_value must be >= 1");
}
else if(ret == ENOMEM) {
rb_raise(HDRHistogramError, "%s", "no memory");
}
self = Data_Wrap_Struct(class, NULL, histogram_free, hdrh);
rb_obj_call_init(self, argc, argv);
return self;
}
|
Instance Method Details
#count ⇒ Object
55 56 57 58 |
# File 'ext/ruby_hdr_histogram/ruby_hdr_histogram.c', line 55
static VALUE histogram_count(VALUE self) {
GET_HDRHIST(hdr, self);
return INT2NUM(hdr->total_count);
}
|
#highest_trackable_value ⇒ Object
#latency_stats ⇒ Object
45 46 47 48 49 |
# File 'lib/HDRHistogram.rb', line 45 def latency_stats str = "Latency Stats\n" str << stats([ 50.0, 75.0, 90.0, 99.0, 99.9, 99.99, 99.999, 100.0 ]) end |
#lowest_trackable_value ⇒ Object
#max ⇒ Object
19 20 21 |
# File 'lib/HDRHistogram.rb', line 19 def max raw_max * @multiplier end |
#mean ⇒ Object
22 23 24 |
# File 'lib/HDRHistogram.rb', line 22 def mean raw_mean * @multiplier end |
#memsize ⇒ Object
50 51 52 53 |
# File 'ext/ruby_hdr_histogram/ruby_hdr_histogram.c', line 50 static VALUE histogram_memsize(VALUE self) { GET_HDRHIST(hdr, self); return INT2NUM(hdr_get_memory_size(hdr)); } |
#merge(other) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/HDRHistogram.rb', line 31 def merge(other) if other.multiplier != multiplier raise HDRHistogramError, "can't merge histograms with different multipliers" end if other.unit != unit raise HDRHistogramError, "can't merge histograms with different units" end raw_merge other end |
#min ⇒ Object
16 17 18 |
# File 'lib/HDRHistogram.rb', line 16 def min raw_min * @multiplier end |
#percentile(pct) ⇒ Object
28 29 30 |
# File 'lib/HDRHistogram.rb', line 28 def percentile(pct) raw_percentile(pct) * @multiplier end |
#record(val) ⇒ Object
10 11 12 |
# File 'lib/HDRHistogram.rb', line 10 def record(val) raw_record(val * 1/@multiplier) end |
#record_corrected(val) ⇒ Object
13 14 15 |
# File 'lib/HDRHistogram.rb', line 13 def record_corrected(val) raw_record_corrected(val * 1/@multiplier) end |
#reset ⇒ Object
44 45 46 47 48 |
# File 'ext/ruby_hdr_histogram/ruby_hdr_histogram.c', line 44 static VALUE histogram_reset(VALUE self) { GET_HDRHIST(hdr, self); hdr_reset(hdr); return self; } |
#significant_figures ⇒ Object
#stats(percentiles = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/HDRHistogram.rb', line 51 def stats(percentiles = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) str = "" pctf = @multiplier < 1 ? "%12.#{Math.log(0.001, 10).abs.ceil}f" : "%12u" percentiles.each do |pct| str << sprintf("%7.3f%% #{pctf}%s\n", pct, percentile(pct), unit) end str end |
#stddev ⇒ Object
25 26 27 |
# File 'lib/HDRHistogram.rb', line 25 def stddev raw_stddev * @multiplier end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/HDRHistogram.rb', line 41 def to_s stats end |