ffmike-query_trace 0.0.2
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 +20 -0
- data/README +88 -0
- data/Rakefile +37 -0
- data/lib/query_trace.rb +45 -0
- metadata +67 -0
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,88 @@
|
|
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
|
+
Either install the QueryTrace as a plugin or as a gem. You can enable QueryTrace by setting the
|
13
|
+
QUERY_TRACE environment variable like so:
|
14
|
+
|
15
|
+
QUERY_TRACE=true script/server
|
16
|
+
|
17
|
+
If you want QueryTrace to always be enabled, create a file in config/initializers, and add the
|
18
|
+
following line:
|
19
|
+
|
20
|
+
QueryTrace.enable!
|
21
|
+
|
22
|
+
QueryTrace only outputs traces at the at the DEBUG log level, and honors your log colorization
|
23
|
+
settings.
|
24
|
+
|
25
|
+
== Example
|
26
|
+
|
27
|
+
Before:
|
28
|
+
|
29
|
+
Schedule Load (0.023687) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1
|
30
|
+
Resource Load (0.001076) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1
|
31
|
+
Schedule Load (0.011488) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1
|
32
|
+
Resource Load (0.022471) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1
|
33
|
+
|
34
|
+
|
35
|
+
After:
|
36
|
+
|
37
|
+
Schedule Load (0.023687) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1
|
38
|
+
app/models/available_work.rb:50:in `study_method'
|
39
|
+
app/helpers/plan_helper.rb:4:in `work_description'
|
40
|
+
app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule'
|
41
|
+
app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule'
|
42
|
+
app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing'
|
43
|
+
app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing'
|
44
|
+
app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing'
|
45
|
+
app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index'
|
46
|
+
vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render'
|
47
|
+
Resource Load (0.001076) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1
|
48
|
+
app/models/available_work.rb:54:in `div_type'
|
49
|
+
app/helpers/plan_helper.rb:6:in `work_description'
|
50
|
+
app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule'
|
51
|
+
app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule'
|
52
|
+
app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing'
|
53
|
+
app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing'
|
54
|
+
app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing'
|
55
|
+
app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index'
|
56
|
+
vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render'
|
57
|
+
Schedule Load (0.011488) SELECT * FROM schedules WHERE (schedules.id = 3) LIMIT 1
|
58
|
+
app/models/available_work.rb:50:in `study_method'
|
59
|
+
app/helpers/plan_helper.rb:4:in `work_description'
|
60
|
+
app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule'
|
61
|
+
app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule'
|
62
|
+
app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing'
|
63
|
+
app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing'
|
64
|
+
app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing'
|
65
|
+
app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index'
|
66
|
+
vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render'
|
67
|
+
Resource Load (0.022471) SELECT * FROM resources WHERE (resources.id = 328) LIMIT 1
|
68
|
+
app/models/available_work.rb:54:in `div_type'
|
69
|
+
app/helpers/plan_helper.rb:6:in `work_description'
|
70
|
+
app/views/plan/_resource_schedule.rhtml:27:in `_run_rhtml_plan__resource_schedule'
|
71
|
+
app/views/plan/_resource_schedule.rhtml:24:in `_run_rhtml_plan__resource_schedule'
|
72
|
+
app/views/plan/_schedule_listing.rhtml:5:in `_run_rhtml_plan__schedule_listing'
|
73
|
+
app/views/plan/_schedule_listing.rhtml:3:in `_run_rhtml_plan__schedule_listing'
|
74
|
+
app/views/plan/_schedule_listing.rhtml:1:in `_run_rhtml_plan__schedule_listing'
|
75
|
+
app/views/plan/index.rhtml:6:in `_run_rhtml_plan_index'
|
76
|
+
vendor/plugins/textmate_footnotes/lib/textmate_footnotes.rb:60:in `render'
|
77
|
+
|
78
|
+
|
79
|
+
== Additional Info
|
80
|
+
|
81
|
+
Author: Nathaniel Talbott (for Terralien)
|
82
|
+
Contact: nathaniel@talbott.ws
|
83
|
+
License: MIT
|
84
|
+
Home: http://github.com/ntalbott/query_trace/
|
85
|
+
Subversion mirror: https://terralien.devguard.com/svn/projects/plugins/query_trace
|
86
|
+
|
87
|
+
|
88
|
+
Copyright (c) 2006 Nathaniel Talbott. All Rights Reserved.
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
GEM_NAME = "query_trace"
|
5
|
+
GEM_VERSION = "0.0.1"
|
6
|
+
AUTHOR = "Nathaniel Talbott"
|
7
|
+
EMAIL = "nathaniel@terralien.com"
|
8
|
+
HOMEPAGE = "http://github.com/ntalbott/query_trace/tree/master"
|
9
|
+
SUMMARY = "Adds query origin tracing to your logs."
|
10
|
+
|
11
|
+
spec = Gem::Specification.new do |s|
|
12
|
+
s.rubyforge_project = 'query_trace'
|
13
|
+
s.name = GEM_NAME
|
14
|
+
s.version = GEM_VERSION
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.extra_rdoc_files = ["README", "MIT-LICENSE"]
|
18
|
+
s.summary = SUMMARY
|
19
|
+
s.description = s.summary
|
20
|
+
s.author = AUTHOR
|
21
|
+
s.email = EMAIL
|
22
|
+
s.homepage = HOMEPAGE
|
23
|
+
s.add_dependency('activerecord')
|
24
|
+
s.require_path = 'lib'
|
25
|
+
s.files = %w(MIT-LICENSE README Rakefile) + Dir.glob("{lib}/**/*")
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
29
|
+
pkg.gem_spec = spec
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Create a gemspec file"
|
33
|
+
task :gemspec do
|
34
|
+
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
35
|
+
file.puts spec.to_ruby
|
36
|
+
end
|
37
|
+
end
|
data/lib/query_trace.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module QueryTrace
|
2
|
+
|
3
|
+
def self.enable!
|
4
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, QueryTrace)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.append_features(klass)
|
8
|
+
super
|
9
|
+
klass.class_eval do
|
10
|
+
unless method_defined?(:log_info_without_trace)
|
11
|
+
alias_method :log_info_without_trace, :log_info
|
12
|
+
alias_method :log_info, :log_info_with_trace
|
13
|
+
end
|
14
|
+
end
|
15
|
+
klass.class_eval %(
|
16
|
+
def row_even
|
17
|
+
@@row_even
|
18
|
+
end
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def log_info_with_trace(sql, name, runtime)
|
23
|
+
log_info_without_trace(sql, name, runtime)
|
24
|
+
|
25
|
+
return unless @logger and @logger.debug?
|
26
|
+
return if / Columns$/ =~ name
|
27
|
+
|
28
|
+
@logger.debug(format_trace(Rails.backtrace_cleaner.clean(caller)))
|
29
|
+
end
|
30
|
+
|
31
|
+
def format_trace(trace)
|
32
|
+
if ActiveRecord::Base.colorize_logging
|
33
|
+
if row_even
|
34
|
+
message_color = "35;2"
|
35
|
+
else
|
36
|
+
message_color = "36;2"
|
37
|
+
end
|
38
|
+
trace.collect{|t| " \e[#{message_color}m#{t}\e[0m"}.join("\n")
|
39
|
+
else
|
40
|
+
trace.join("\n ")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
QueryTrace.enable! if ENV["QUERY_TRACE"]
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffmike-query_trace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathaniel Talbott
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-03 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Adds query origin tracing to your logs.
|
26
|
+
email: nathaniel@terralien.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
- MIT-LICENSE
|
34
|
+
files:
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README
|
37
|
+
- Rakefile
|
38
|
+
- lib/query_trace.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/ntalbott/query_trace/tree/master
|
41
|
+
licenses:
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project: query_trace
|
62
|
+
rubygems_version: 1.3.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 2
|
65
|
+
summary: Adds query origin tracing to your logs.
|
66
|
+
test_files: []
|
67
|
+
|