简体   繁体   中英

Profiling ruby/rails method Names

I am using ruby/rails Benchmark module for quite some time.

Every time I have to benchmark a method I have to write code like this:

Class BenchMarkTest
  def self.method_to_benchmark()
       # code here
  end  
end

Usage:

t1 = Benchmark.realtime {
  BenchMarkTest.method_to_benchmark()
}

puts "Time Taken:#{t1.inspect}"

I always have to wrap method/block inside Benchmark module.

Is there any way, gem or library, I can provide method names and get the benchmark output without disturbing/writing any code?

For example:

I have an array of method names:

methods_to_benchmark = ["method_to_benchmark", "method2"]

Whichever method names are in above array will be benchmarked at runtime.

We are using newrelic so newrelic method tracers solved my problem.

https://docs.newrelic.com/docs/ruby/ruby-custom-metric-collection#method_tracers

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM