Home > Software design >  How to measure the execution time of the ruby code inside API controller's action when query is
How to measure the execution time of the ruby code inside API controller's action when query is

Time:04-13

There is an api query that response takes 6 seconds. I am looking in Datadog, and that looks like all SQL queries take an exec time of 2 seconds. What the rest of the time is not clear. Maybe do you know some gems or tools how can I measure the execution time? Many thanks for any advice.

CodePudding user response:

You can use Benchmark

require 'benchmark'

puts Benchmark.measure { #code_you_want_to_measure }

CodePudding user response:

Consider rack-mini-profiler.

Features

  • Database profiling - Currently supports Mysql2, Postgres, Oracle (oracle_enhanced ~> 1.5.0) and Mongoid3 (with fallback support to ActiveRecord)
  • Call-stack profiling - Flame graphs showing time spent by gem
  • Memory profiling - Per-request memory usage, GC stats, and global allocation metrics
  • Related