Module: MethodBenchmarking
- Defined in:
- lib/method_benchmarking.rb
Overview
benchmark_method :my_method, tag: ‘my_custom_tag’, end
Defined Under Namespace
Modules: DefaultConfig
Instance Method Summary collapse
-
#benchmark_method(method_name, options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#benchmark_method(method_name, options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/method_benchmarking.rb', line 23 def benchmark_method(method_name, = {}) # rubocop:todo Metrics/MethodLength return if method_name.start_with?('benchmark', '_') alias_method :"benchmark_#{method_name}", :"#{method_name}" define_method(method_name) do |*args, **kwargs, &block| tag = .key?(:tag) ? [:tag] : DefaultConfig::DEFAULT_TAG loc = caller_locations(1, 1).first output = nil measure = Benchmark.measure { output = send(:"benchmark_#{method_name}", *args, **kwargs, &block) } line = "PERFORMANCE[#{tag}][#{self.class.name}][#{method_name}]: #{loc.path}:#{loc.lineno} #{measure}" Rails.logger.debug line output end end |