Console utility to help developers figure out why a block of code is slow:
- Show ruby usage
- Show active record usage
gem "hinter", git: "https://github.com/Oxyless/hinter.git"
result = Hinter.new.watch(binding) do
Log.count
puts 42
Brand.all.map(&:name)
a = 45
end
Because block.source
is not available from console, so you have to comment evalued code.
result = Hinter.new.watch(binding, source:
<<~RUBY
Log.count
puts 42
Brand.all.map(&:name)
a = 45
RUBY
)
result.expand(12) # sql analysis of #12
result.slow(1) # display lines > 1s
# sql only
result = Hinter.watch do
# some_code
end
result.queries # get queries sort by time
result.top_query # display slow query
result.top_queries(42) # display n slow queries
result.expand(114) # callstack of #114
result = Hinter.new(
file_pattern: nil,
warning_time: 1,
critical_time: 5,
warning_sql_call: 10,
critical_sql_call: 100,
round_time: 2,
colors: true,
watch_dir: /\/app\//,
ignored: /(\/gems\/|\(pry\)|bin\/rails|hinter)/
).watch do
# some_code
end
- "file_pattern" file_pattern to_watch as string
- "warning_time" max query time seconds before warning color
- "critical_time" max query time seconds before critical color
- "warning_sql_call" max same query call before warning color
- "critical_sql_call" max same query call before warning color
- "round_time" number of digit for time
- "colors" enable colors
- "watch_dir" path watched
- "ignored" path ignored
Rails 3, 4, 5, 6