Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 273
Florian Eck Avatar asked Sep 27 '12 23:09

Florian Eck


1 Answers

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

like image 77
Bryan Larsen Avatar answered Sep 19 '22 19:09

Bryan Larsen