Class: Couchbase::Utils::HdrHistogram

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/utils/hdr_histogram.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/utils/hdr_histogram.rb

Instance Method Summary collapse

Constructor Details

#initialize(lowest_discernible_value:, highest_trackable_value:, significant_figures:, percentiles: nil) ⇒ HdrHistogram

Returns a new instance of HdrHistogram.



20
21
22
23
24
25
26
27
28
# File 'lib/couchbase/utils/hdr_histogram.rb', line 20

def initialize(
  lowest_discernible_value:,
  highest_trackable_value:,
  significant_figures:,
  percentiles: nil
)
  @histogram_backend = HdrHistogramC.new(lowest_discernible_value, highest_trackable_value, significant_figures)
  @percentiles = percentiles || [50.0, 90.0, 99.0, 99.9, 100.0]
end

Instance Method Details

#closeObject



34
35
36
# File 'lib/couchbase/utils/hdr_histogram.rb', line 34

def close
  @histogram_backend.close
end

#record_value(value) ⇒ Object



30
31
32
# File 'lib/couchbase/utils/hdr_histogram.rb', line 30

def record_value(value)
  @histogram_backend.record_value(value)
end

#report_and_resetObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/couchbase/utils/hdr_histogram.rb', line 38

def report_and_reset
  backend_report = @histogram_backend.get_percentiles_and_reset(@percentiles)
  total_count = backend_report[:total_count]

  return nil if total_count.zero?

  report = {
    total_count: total_count,
    percentiles_us: {},
  }
  @percentiles.zip(backend_report[:percentiles]).each do |percentile, percentile_value|
    report[:percentiles_us][percentile.to_s] = percentile_value
  end
  report
end