module FFWD::Reporter
$LICENSE Copyright 2013-2014 Spotify AB. All rights reserved.
The contents of this file are licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Public Class Methods
build_meta(instance, k)
click to toggle source
# File lib/ffwd/reporter.rb, line 21 def self.build_meta instance, k meta = instance.class.reporter_meta || {} if instance.respond_to?(:reporter_meta) meta = meta.merge(instance.send(:reporter_meta)) end meta = meta.merge(k[:meta]) meta[:unit] = "#{meta[:unit] || 'n'}/s" return meta end
included(mod)
click to toggle source
# File lib/ffwd/reporter.rb, line 64 def self.included mod mod.extend ClassMethods end
map_meta(meta)
click to toggle source
# File lib/ffwd/reporter.rb, line 17 def self.map_meta meta Hash[meta.map{|k, v| [k.to_s, v]}] end
Public Instance Methods
increment(n, c=1)
click to toggle source
# File lib/ffwd/reporter.rb, line 72 def increment n, c=1 reporter_data[n] += c end
report!(diff) { |:key => k, :value => rate, :meta => meta| ... }
click to toggle source
# File lib/ffwd/reporter.rb, line 76 def report! diff self.class.reporter_keys.each do |key| k = key[:key] v = reporter_data[k] reporter_data[k] = 0 meta = ((@_reporter_meta ||= {})[k] ||= FFWD::Reporter.build_meta(self, key)) rate = (v / diff).round(3) yield(:key => k, :value => rate, :meta => meta) end end
reporter_data()
click to toggle source
# File lib/ffwd/reporter.rb, line 68 def reporter_data @_reporter_data ||= Hash[self.class.reporter_keys.map{|k| [k[:key], 0]}] end