Class: Couchbase::Utils::HdrHistogramC
- Inherits:
-
Object
- Object
- Couchbase::Utils::HdrHistogramC
- Defined in:
- ext/rcb_hdr_histogram.cxx
Instance Method Summary collapse
- #bin_count ⇒ Object
- #close ⇒ Object
- #get_percentiles_and_reset(percentiles) ⇒ Object
- #initialize(lowest_discernible_value, highest_trackable_value, significant_figures) ⇒ Object constructor
- #record_value(value) ⇒ Object
Constructor Details
#initialize(lowest_discernible_value, highest_trackable_value, significant_figures) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ext/rcb_hdr_histogram.cxx', line 97
VALUE
cb_HdrHistogramC_initialize(VALUE self,
VALUE lowest_discernible_value,
VALUE highest_trackable_value,
VALUE significant_figures)
{
Check_Type(lowest_discernible_value, T_FIXNUM);
Check_Type(highest_trackable_value, T_FIXNUM);
Check_Type(significant_figures, T_FIXNUM);
std::int64_t lowest = NUM2LL(lowest_discernible_value);
std::int64_t highest = NUM2LL(highest_trackable_value);
int sigfigs = NUM2INT(significant_figures);
cb_hdr_histogram_data* hdr_histogram;
TypedData_Get_Struct(self, cb_hdr_histogram_data, &cb_hdr_histogram_type, hdr_histogram);
int res;
{
const std::unique_lock lock(hdr_histogram->mutex);
res = hdr_init(lowest, highest, sigfigs, &hdr_histogram->histogram);
}
if (res != 0) {
rb_raise(exc_couchbase_error(), "failed to initialize HDR histogram");
return self;
}
return self;
}
|
Instance Method Details
#bin_count ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'ext/rcb_hdr_histogram.cxx', line 191
VALUE
cb_HdrHistogramC_bin_count(VALUE self)
{
cb_hdr_histogram_data* hdr_histogram;
TypedData_Get_Struct(self, cb_hdr_histogram_data, &cb_hdr_histogram_type, hdr_histogram);
std::int32_t bin_count;
{
const std::unique_lock lock(hdr_histogram->mutex);
bin_count = hdr_histogram->histogram->bucket_count;
}
return LONG2NUM(bin_count);
}
|
#close ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 |
# File 'ext/rcb_hdr_histogram.cxx', line 127
VALUE
cb_HdrHistogramC_close(VALUE self)
{
cb_hdr_histogram_data* hdr_histogram;
TypedData_Get_Struct(self, cb_hdr_histogram_data, &cb_hdr_histogram_type, hdr_histogram);
{
const std::unique_lock lock(hdr_histogram->mutex);
cb_hdr_histogram_close(hdr_histogram);
}
return Qnil;
}
|
#get_percentiles_and_reset(percentiles) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'ext/rcb_hdr_histogram.cxx', line 156
VALUE
cb_HdrHistogramC_get_percentiles_and_reset(VALUE self, VALUE percentiles)
{
Check_Type(percentiles, T_ARRAY);
cb_hdr_histogram_data* hdr_histogram;
TypedData_Get_Struct(self, cb_hdr_histogram_data, &cb_hdr_histogram_type, hdr_histogram);
std::vector<std::int64_t> percentile_values{};
std::int64_t total_count;
{
const std::unique_lock lock(hdr_histogram->mutex);
total_count = hdr_histogram->histogram->total_count;
for (std::size_t i = 0; i < static_cast<std::size_t>(RARRAY_LEN(percentiles)); ++i) {
VALUE entry = rb_ary_entry(percentiles, static_cast<long>(i));
Check_Type(entry, T_FLOAT);
double perc = NUM2DBL(entry);
std::int64_t value_at_perc = hdr_value_at_percentile(hdr_histogram->histogram, perc);
percentile_values.push_back(value_at_perc);
}
hdr_reset(hdr_histogram->histogram);
}
static const VALUE sym_total_count = rb_id2sym(rb_intern("total_count"));
static const VALUE sym_percentiles = rb_id2sym(rb_intern("percentiles"));
VALUE res = rb_hash_new();
rb_hash_aset(res, sym_total_count, LL2NUM(total_count));
VALUE perc_array = rb_ary_new_capa(static_cast<long>(percentile_values.size()));
for (const auto& val : percentile_values) {
rb_ary_push(perc_array, LL2NUM(val));
}
rb_hash_aset(res, sym_percentiles, perc_array);
return res;
}
|
#record_value(value) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'ext/rcb_hdr_histogram.cxx', line 139
VALUE
cb_HdrHistogramC_record_value(VALUE self, VALUE value)
{
Check_Type(value, T_FIXNUM);
std::int64_t val = NUM2LL(value);
cb_hdr_histogram_data* hdr_histogram;
TypedData_Get_Struct(self, cb_hdr_histogram_data, &cb_hdr_histogram_type, hdr_histogram);
{
const std::shared_lock lock(hdr_histogram->mutex);
hdr_record_value_atomic(hdr_histogram->histogram, val);
}
return Qnil;
}
|