Created
November 29, 2012 00:20
-
-
Save nicholasjhenry/4165796 to your computer and use it in GitHub Desktop.
Query Trace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class QueryTrace < ActiveSupport::LogSubscriber | |
| def sql(event) | |
| return unless logger.debug? | |
| debug caller. | |
| select {|stack| stack =~ /\/app\//}. | |
| map {|stack| stack.gsub(/^.*app\//, '')}. | |
| join("\n") | |
| end | |
| def logger | |
| ActiveRecord::Base.logger | |
| end | |
| end | |
| QueryTrace.attach_to :active_record | |
| __DATA__ | |
| Example output: | |
| Feature Load (0.1ms) SELECT `features`.* FROM `features` | |
| WHERE `features`.`name` = 'Stores' LIMIT 1 | |
| models/feature.rb:16:in `to_feature' | |
| helpers/application_helper.rb:139:in `feature_available?' | |
| helpers/application_helper.rb:591:in `show_menu' | |
| helpers/application_helper.rb:582:in `each' | |
| helpers/application_helper.rb:582:in `each_with_index' | |
| helpers/application_helper.rb:582:in `show_menu' | |
| views/shared/_tabs.html.haml:2:in | |
| `_app_views_shared__tabs_html_haml__796547580_2224868320_2407870' | |
| views/layouts/application.html.haml:51:in | |
| `_app_views_layouts_application_html_haml___1975730980_2228964600_0' | |
| controllers/sites_controller.rb:32:in `show' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment