class OneApm::Metrics::Stats
Attributes
apdex_f[RW]
apdex_s[RW]
apdex_t[RW]
call_count[RW]
max_call_time[RW]
min_call_time[RW]
sum_of_squares[RW]
total_call_time[RW]
total_exclusive_time[RW]
Public Class Methods
create_from_hash(hash_value)
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 13 def self.create_from_hash hash_value stats = Stats.new stats.call_count = hash_value[:count] if hash_value[:count] stats.total_call_time = hash_value[:total] if hash_value[:total] stats.total_exclusive_time = hash_value[:total] if hash_value[:total] stats.min_call_time = hash_value[:min] if hash_value[:min] stats.max_call_time = hash_value[:max] if hash_value[:max] stats.sum_of_squares = hash_value[:sum_of_squares] if hash_value[:sum_of_squares] stats end
new()
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 24 def initialize reset end
Public Instance Methods
==(other)
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 121 def ==(other) other.class == self.class && ( @min_call_time == other.min_call_time && @max_call_time == other.max_call_time && @total_call_time == other.total_call_time && @total_exclusive_time == other.total_exclusive_time && @sum_of_squares == other.sum_of_squares && @call_count == other.call_count ) end
increment_count(value = 1)
click to toggle source
increments the call_count
by one
# File lib/one_apm/metrics/stats.rb, line 104 def increment_count(value = 1) @call_count += value end
inspect()
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 108 def inspect "#<OneApm::Metrics::Stats #{to_s} >" end
inspect_full()
click to toggle source
Concerned about implicit usage of inspect relying on stats format, so putting back a version to get full inspection as separate method
# File lib/one_apm/metrics/stats.rb, line 114 def inspect_full variables = instance_variables.map do |ivar| "#{ivar.to_s}=#{instance_variable_get(ivar).inspect}" end.join(" ") "#<OneApm::Metrics::Stats #{variables}>" end
is_reset?()
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 37 def is_reset? call_count == 0 && total_call_time == 0.0 && total_exclusive_time == 0.0 end
merge(other_stats)
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 41 def merge(other_stats) stats = self.clone stats.merge!(other_stats) end
merge!(other)
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 46 def merge!(other) @min_call_time = other.min_call_time if min_time_less?(other) @max_call_time = other.max_call_time if other.max_call_time > max_call_time @total_call_time += other.total_call_time @total_exclusive_time += other.total_exclusive_time @sum_of_squares += other.sum_of_squares @call_count += other.call_count self end
record(value=nil, aux=nil) { |self| ... }
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 71 def record(value=nil, aux=nil, &blk) if blk yield self else case value when Numeric aux ||= value self.record_data_point(value, aux) when :apdex_s, :apdex_t, :apdex_f self.record_apdex(value, aux) when OneApm::Metrics::Stats self.merge!(value) end end end
record_apdex(bucket, apdex_t)
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 138 def record_apdex(bucket, apdex_t) case bucket when :apdex_s then @call_count += 1 when :apdex_t then @total_call_time += 1 when :apdex_f then @total_exclusive_time += 1 end if apdex_t @min_call_time = apdex_t @max_call_time = apdex_t else OneApm::Manager.logger.warn("Attempted to set apdex_t to #{apdex_t.inspect}, backtrace = #{caller.join("\n")}") end end
record_data_point(value, exclusive_time = value)
click to toggle source
record a single data point into the statistical gatherer. The gatherer will aggregate all data points collected over a specified period and upload its data to the OneApm
server
# File lib/one_apm/metrics/stats.rb, line 90 def record_data_point(value, exclusive_time = value) @call_count += 1 @min_call_time = value if value < @min_call_time || @call_count == 1 @max_call_time = value if value > @max_call_time @total_call_time += value @total_exclusive_time += exclusive_time @sum_of_squares += (value * value) self end
Also aliased as: trace_call
reset()
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 28 def reset @call_count = 0 @total_call_time = 0.0 @total_exclusive_time = 0.0 @min_call_time = 0.0 @max_call_time = 0.0 @sum_of_squares = 0.0 end
to_json(*_)
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 60 def to_json(*_) { 'call_count' => call_count.to_i, 'min_call_time' => min_call_time.to_f, 'max_call_time' => max_call_time.to_f, 'total_call_time' => total_call_time.to_f, 'total_exclusive_time' => total_exclusive_time.to_f, 'sum_of_squares' => sum_of_squares.to_f }.to_json(*_) end
to_s()
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 56 def to_s "[#{'%2i' % call_count.to_i} calls #{'%.4f' % total_call_time.to_f}s / #{'%.4f' % total_exclusive_time.to_f}s ex]" end
Protected Instance Methods
min_time_less?(other)
click to toggle source
# File lib/one_apm/metrics/stats.rb, line 154 def min_time_less?(other) (other.min_call_time < min_call_time && other.call_count > 0) || call_count == 0 end