views:

127

answers:

3

I'm reading through a open source Rails project code and I see SQL statements in the development log that I can't map to the Rails code, i.e., I have no idea where it is called from. I tried ruby-debug but it seems to be out of sync with the log file output and the code itself, so it hasn't been too useful. Any suggestions on how to debug this?

Someone asked which open source project, it's Insoshi and here's a snippet of the SQL statements I'm trying to map to Rails code.

←[4;36;1mForum Columns (0.0ms)←[0m   ←[0;1mSHOW FIELDS FROM `forums`←[0m
←[4;35;1mSQL (15.0ms)←[0m   ←[0mSELECT count(*) AS count_all FROM `forums` ←[0m
←[4;36;1mForum Load (0.0ms)←[0m   ←[0;1mSELECT * FROM `forums` LIMIT 1←[0m

I don't think the above info is helpful unless you already know the code but here it is anyway. I didn't show any Rails code because I don't know where it's called from. This is a generic debugging problem that I'm going to have all through the code as I'm figuring out how it works.

+3  A: 

Try query-reviewer. It gives an in browser trace of sql queries and related application backtraces.

cwninja
Outstanding, it gives me the information I need. This is going to be very helpful for anyone else trying to understand someone else's code. Thank you!
Bob
+1  A: 

I use New Relic's plugin, in developer mode, to track down where queries come from. Just install the plugin and browse to /newrelic (in dev environment) and it will show you the last 10 requests and you can drill down from tehre.

BJ Clark
+1  A: 

The rails-footnotes plugin is pretty handy for development. It will tell you what queries were used to generate the page as well provide a list of files accessed. Which by the way can be tweaked to open in your favourite editor when clicked in the browser.

EmFi