Alex
Alex

Reputation: 392

How to measure the execution time of the ruby code inside API controller's action when query is calling

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.

Upvotes: 1

Views: 1458

Answers (2)

Daniel Moskowitz
Daniel Moskowitz

Reputation: 1

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

Upvotes: 0

Danilo Veloso
Danilo Veloso

Reputation: 68

You can use Benchmark

require 'benchmark'

puts Benchmark.measure { #code_you_want_to_measure }

Upvotes: 2

Related Questions