Class: Couchbase::Tracing::ThresholdLoggingTracer::Group
- Inherits:
-
Object
- Object
- Couchbase::Tracing::ThresholdLoggingTracer::Group
- Defined in:
- lib/couchbase/tracing/threshold_logging_tracer.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/tracing/threshold_logging_tracer.rb
Instance Method Summary collapse
-
#initialize(capacity:, floor_us:) ⇒ Group
constructor
A new instance of Group.
- #record_operation(item) ⇒ Object
- #steal_data ⇒ Object
Constructor Details
#initialize(capacity:, floor_us:) ⇒ Group
Returns a new instance of Group.
180 181 182 183 184 185 186 187 |
# File 'lib/couchbase/tracing/threshold_logging_tracer.rb', line 180 def initialize(capacity:, floor_us:) @capacity = capacity @floor_us = floor_us @total_count = 0 @top_requests = [] @mutex = Mutex.new end |
Instance Method Details
#record_operation(item) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/couchbase/tracing/threshold_logging_tracer.rb', line 189 def record_operation(item) return if item.total_duration_us < @floor_us @mutex.synchronize do @total_count += 1 return if @top_requests.size >= @capacity && item.total_duration_us < @top_requests[-1].total_duration_us idx = @top_requests.bsearch_index do |x| item.total_duration_us >= x.total_duration_us end # The item is smaller than all existing items. We will insert it at the end. idx = @top_requests.size if idx.nil? if @top_requests.size >= @capacity # We are at capacity, remove the smallest (last) item @top_requests.pop end @top_requests.insert(idx, item) end end |
#steal_data ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/couchbase/tracing/threshold_logging_tracer.rb', line 212 def steal_data top_requests, total_count = @mutex.synchronize do top_requests_tmp = @top_requests total_count_tmp = @total_count @top_requests = [] @total_count = 0 [top_requests_tmp, total_count_tmp] end return nil if total_count.zero? { total_count: total_count, top_requests: top_requests.map(&:to_h), } end |