25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/track_method.rb', line 25
def track_method(method_name, method_arguments = {})
TrackMethod.console.notice "Tracking: #{self.name}.#{method_name}"
wrap_method(method_name) do |org_method, args, block|
benchmark_start = Time.now
result = org_method.call(*args, &block)
benchmark_end = Time.now
benchmark_at = ((benchmark_end.to_f * 1000.0) - (benchmark_start.to_f * 1000.0))
argument_mapping = {}
method_arguments.each do |method_label, method_needle|
argument_mapping[method_label] = args[method_needle]
end
benchmark_output = "#{(benchmark_at).to_s.rjust(20, ' ')} #{self.name}.#{method_name}(#{argument_mapping.inspect})"
case
when benchmark_at > 500
TrackMethod.console.error benchmark_output
when benchmark_at > 200
TrackMethod.console.warn benchmark_output
when benchmark_at > 100
TrackMethod.console.notice benchmark_output
else
TrackMethod.console.log benchmark_output
end
result
end
end
|