从SQL查询回溯到应用程序代码? [英] Backtrace from SQL query to application code?
问题描述
是否有办法在Rails开发日志中查找哪一行代码生成了MySQL语句?
Is there a way to find which line of code generated a MySQL statement in a Rails development log?
为了进行一些性能优化,我想找到我应用程序的哪个部分正在创建哪个MySQL查询.当我查看日志时,我在执行的每个Web请求中都闪烁着数百个查询,我需要找出它们的来源.
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.
我正在考虑向日志输出中添加一些变量,例如____FILE____
和____LINE____
.
I'm thinking about adding some variables like ____FILE____
and ____LINE____
to the log output.
有可能吗?
推荐答案
https://github.com/lightyear/sql-logging 为您提供了每个SQL查询的回溯以及大量有用的统计信息.
https://github.com/lightyear/sql-logging gives you a backtrace for every SQL query plus a bunch of useful statistics.
这篇关于从SQL查询回溯到应用程序代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!