mysqlruby-on-railsloggingperformance-testingbacktrace

Backtrace from SQL query to application code?


Is there a way to find which line of code generated a MySQL statement in a Rails development log?

In order to do some performance optimization, I would like to find which part of my app is creating which MySQL queries. When I take a look at my log, I see hundres of queries flashing around on each web request I do, and I need to find out where they come from.

I'm thinking about adding some variables like ____FILE____ and ____LINE____ to the log output.

Is that possible?


Solution

  • https://github.com/lightyear/sql-logging gives you a backtrace for every SQL query plus a bunch of useful statistics.