Class: OpenTelemetry::SDK::Metrics::Aggregation::ExponentialHistogram::Buckets
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Metrics::Aggregation::ExponentialHistogram::Buckets
- Defined in:
- lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb
Overview
Buckets is the fundamental building block of exponential histogram that store bucket/boundary value
Instance Attribute Summary collapse
-
#index_base ⇒ Object
Returns the value of attribute index_base.
-
#index_end ⇒ Object
Returns the value of attribute index_end.
-
#index_start ⇒ Object
Returns the value of attribute index_start.
Instance Method Summary collapse
- #copy_empty ⇒ Object
- #downscale(amount) ⇒ Object
- #get_bucket(key) ⇒ Object
-
#grow(needed, max_size) ⇒ Object
grow simply expand the @counts size.
- #increment_bucket(bucket_index, increment = 1) ⇒ Object
-
#initialize ⇒ Buckets
constructor
A new instance of Buckets.
- #length ⇒ Object
- #offset ⇒ Object
- #offset_counts ⇒ Object (also: #counts)
Constructor Details
#initialize ⇒ Buckets
Returns a new instance of Buckets.
16 17 18 19 20 21 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 16 def initialize @counts = [0] @index_base = 0 @index_start = 0 @index_end = 0 end |
Instance Attribute Details
#index_base ⇒ Object
Returns the value of attribute index_base.
14 15 16 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 14 def index_base @index_base end |
#index_end ⇒ Object
Returns the value of attribute index_end.
14 15 16 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 14 def index_end @index_end end |
#index_start ⇒ Object
Returns the value of attribute index_start.
14 15 16 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 14 def index_start @index_start end |
Instance Method Details
#copy_empty ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 108 def copy_empty new_buckets = self.class.new new_buckets.instance_variable_set(:@counts, Array.new(@counts.size, 0)) new_buckets.instance_variable_set(:@index_base, @index_base) new_buckets.instance_variable_set(:@index_start, @index_start) new_buckets.instance_variable_set(:@index_end, @index_end) new_buckets end |
#downscale(amount) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 64 def downscale(amount) bias = @index_base - @index_start if bias != 0 @index_base = @index_start @counts.reverse! @counts = @counts[0...bias].reverse + @counts[bias..].reverse end size = 1 + @index_end - @index_start each = 1 << amount inpos = 0 outpos = 0 pos = @index_start while pos <= @index_end mod = pos % each mod += each if mod < 0 inds = mod while inds < each && inpos < size if outpos != inpos @counts[outpos] += @counts[inpos] @counts[inpos] = 0 end inpos += 1 pos += 1 inds += 1 end outpos += 1 end @index_start >>= amount @index_end >>= amount @index_base = @index_start end |
#get_bucket(key) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 55 def get_bucket(key) bias = @index_base - @index_start key += @counts.size if key < bias key -= bias @counts[key] end |
#grow(needed, max_size) ⇒ Object
grow simply expand the @counts size
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 24 def grow(needed, max_size) size = @counts.size bias = @index_base - @index_start old_positive_limit = size - bias new_size = [2**Math.log2(needed).ceil, max_size].min new_positive_limit = new_size - bias tmp = Array.new(new_size, 0) tmp[new_positive_limit..-1] = @counts[old_positive_limit..] tmp[0...old_positive_limit] = @counts[0...old_positive_limit] @counts = tmp end |
#increment_bucket(bucket_index, increment = 1) ⇒ Object
104 105 106 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 104 def increment_bucket(bucket_index, increment = 1) @counts[bucket_index] += increment end |
#length ⇒ Object
48 49 50 51 52 53 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 48 def length return 0 if @counts.empty? return 0 if @index_end == @index_start && counts[0] == 0 @index_end - @index_start + 1 end |
#offset ⇒ Object
38 39 40 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 38 def offset @index_start end |
#offset_counts ⇒ Object Also known as: counts
42 43 44 45 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/exponential_histogram/buckets.rb', line 42 def offset_counts bias = @index_base - @index_start @counts[-bias..] + @counts[0...-bias] end |