active_record_query_trace 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -0
- data/lib/active_record_query_trace.rb +30 -0
- metadata +62 -0
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Logs the source of execution of all queries to the Rails log. Helpful to track down where queries are being executed in your application, for performance optimizations most likely.
|
2
|
+
|
3
|
+
Install
|
4
|
+
-------
|
5
|
+
|
6
|
+
`gem install active_query_record_trace`
|
7
|
+
|
8
|
+
Usage
|
9
|
+
-----
|
10
|
+
|
11
|
+
Enable it in an initializer:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
ActiveQueryRecordTrace.enabled = true
|
15
|
+
```
|
16
|
+
|
17
|
+
|
18
|
+
Requirements
|
19
|
+
------------
|
20
|
+
Rails 3+
|
21
|
+
|
22
|
+
Copyright (c) 2011 Cody Caughlan
|
23
|
+
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
25
|
+
a copy of this software and associated documentation files (the
|
26
|
+
"Software"), to deal in the Software without restriction, including
|
27
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
28
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
29
|
+
permit persons to whom the Software is furnished to do so, subject to
|
30
|
+
the following conditions:
|
31
|
+
|
32
|
+
The above copyright notice and this permission notice shall be
|
33
|
+
included in all copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
36
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
37
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
38
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
39
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
40
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
41
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_support/log_subscriber'
|
2
|
+
|
3
|
+
module ActiveRecordQueryTrace
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :enabled
|
7
|
+
end
|
8
|
+
|
9
|
+
module ActiveRecord
|
10
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
super
|
14
|
+
ActiveQueryRecordTrace.enabled = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def sql(event)
|
18
|
+
if ActiveRecordQueryTrace.enabled
|
19
|
+
debug("\e[1m\e[35m\e[1m\e[47mCalled from:\e[0m " + clean_trace(caller[2..-2]).join("\n "))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def clean_trace(trace)
|
24
|
+
Rails.respond_to?(:backtrace_cleaner) ? Rails.backtrace_cleaner.clean(trace) : trace
|
25
|
+
end
|
26
|
+
|
27
|
+
attach_to :active_record
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record_query_trace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Cody Caughlan
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2011-11-19 00:00:00 -08:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: Print stack trace of all queries to the Rails log. Helpful to find where queries are being executed in your application.
|
21
|
+
email: toolbag@gmail.com
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files: []
|
27
|
+
|
28
|
+
files:
|
29
|
+
- README.md
|
30
|
+
- lib/active_record_query_trace.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: https://github.com/ruckus/active-record-query-trace
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.6
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Print stack trace of all queries to the Rails log. Helpful to find where queries are being executed in your application.
|
61
|
+
test_files: []
|
62
|
+
|