pager-query_trace 1.0.20080506

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 Nathaniel Talbott. All Rights Reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,80 @@
1
+ = QueryTrace plugin for Rails
2
+
3
+ It's nice that ActiveRecord logs the queries that are performed when your actions are executed,
4
+ since it makes it easy to see when you have serious inefficiencies in your application. The next
5
+ question, though, is always, "OK, so where are those being run from?" Before QueryTrace, that
6
+ question could be a real pain to answer, since you'd have to go trawling through your code looking
7
+ for the culprit. Once you have QueryTrace installed, though, your logs won't just tell you that you
8
+ have a problem, they will pinpoint the location of that problem for you.
9
+
10
+ == Usage
11
+
12
+ All you have to do is have the plugin installed - QueryTrace takes care of the rest, including:
13
+
14
+ * Only displaying when at the DEBUG log level
15
+ * Honoring your log colorization settings
16
+
17
+ == Example
18
+
19
+ Before:
20
+
21
+ Schedule Load (0.023687) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1
22
+ Resource Load (0.001076) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1
23
+ Schedule Load (0.011488) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1
24
+ Resource Load (0.022471) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1
25
+
26
+
27
+ After:
28
+
29
+ Schedule Load (0.023687) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1
30
+ app/models/available_work.rb:50:in `study_method'
31
+ app/helpers/plan_helper.rb:4:in `work_description'
32
+ app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule'
33
+ app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule'
34
+ app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing'
35
+ app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing'
36
+ app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing'
37
+ app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index'
38
+ vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render'
39
+ Resource Load (0.001076) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1
40
+ app/models/available_work.rb:54:in `div_type'
41
+ app/helpers/plan_helper.rb:6:in `work_description'
42
+ app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule'
43
+ app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule'
44
+ app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing'
45
+ app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing'
46
+ app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing'
47
+ app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index'
48
+ vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render'
49
+ Schedule Load (0.011488) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1
50
+ app/models/available_work.rb:50:in `study_method'
51
+ app/helpers/plan_helper.rb:4:in `work_description'
52
+ app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule'
53
+ app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule'
54
+ app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing'
55
+ app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing'
56
+ app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing'
57
+ app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index'
58
+ vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render'
59
+ Resource Load (0.022471) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1
60
+ app/models/available_work.rb:54:in `div_type'
61
+ app/helpers/plan_helper.rb:6:in `work_description'
62
+ app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule'
63
+ app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule'
64
+ app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing'
65
+ app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing'
66
+ app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing'
67
+ app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index'
68
+ vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render'
69
+
70
+
71
+ == Additional Info
72
+
73
+ Author: Nathaniel Talbott (for Terralien)
74
+ Contact: nathaniel@talbott.ws
75
+ License: MIT
76
+ Home: http://github.com/ntalbott/query_trace/
77
+ Subversion mirror: https://terralien.devguard.com/svn/projects/plugins/query_trace
78
+
79
+
80
+ Copyright (c) 2006 Nathaniel Talbott. All Rights Reserved.
@@ -0,0 +1,5 @@
1
+ require 'query_trace'
2
+
3
+ class ::ActiveRecord::ConnectionAdapters::AbstractAdapter
4
+ include QueryTrace
5
+ end
@@ -0,0 +1,46 @@
1
+ module QueryTrace
2
+ def self.append_features(klass)
3
+ super
4
+ klass.class_eval do
5
+ unless method_defined?(:log_info_without_trace)
6
+ alias_method :log_info_without_trace, :log_info
7
+ alias_method :log_info, :log_info_with_trace
8
+ end
9
+ end
10
+ klass.class_eval %(
11
+ def row_even
12
+ @@row_even
13
+ end
14
+ )
15
+ end
16
+
17
+ def log_info_with_trace(sql, name, runtime)
18
+ log_info_without_trace(sql, name, runtime)
19
+
20
+ return unless @logger and @logger.debug?
21
+ return if / Columns$/ =~ name
22
+
23
+ trace = clean_trace(caller[2..-1])
24
+ @logger.debug(format_trace(trace))
25
+ end
26
+
27
+ def format_trace(trace)
28
+ if ActiveRecord::Base.colorize_logging
29
+ if row_even
30
+ message_color = "35;2"
31
+ else
32
+ message_color = "36;2"
33
+ end
34
+ trace.collect{|t| " \e[#{message_color}m#{t}\e[0m"}.join("\n")
35
+ else
36
+ trace.join("\n ")
37
+ end
38
+ end
39
+
40
+ VENDOR_RAILS_REGEXP = %r(([\\/:])vendor\1rails\1)
41
+ def clean_trace(trace)
42
+ return trace unless defined?(RAILS_ROOT)
43
+
44
+ trace.select{|t| /#{Regexp.escape(File.expand_path(RAILS_ROOT))}/ =~ t}.reject{|t| VENDOR_RAILS_REGEXP =~ t}.collect{|t| t.gsub(RAILS_ROOT + '/', '')}
45
+ end
46
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'pager-query_trace'
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pager-query_trace
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.20080506
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel Talbott (for Terralien)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-06 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: avanie@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - MIT-LICENSE
25
+ files:
26
+ - lib/pager-query_trace.rb
27
+ - lib/query_trace.rb
28
+ - MIT-LICENSE
29
+ - rails/init.rb
30
+ - README
31
+ has_rdoc: true
32
+ homepage: http://github.com/pager/query_trace
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --main
36
+ - README
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.0.1
55
+ signing_key:
56
+ specification_version: 2
57
+ summary: Gemified query_trace plugin
58
+ test_files: []
59
+