cache-query-trace 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/cache-query-trace.gemspec +25 -0
- data/lib/cache-query-trace.rb +78 -0
- data/lib/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f072d1436d53f066103e1d61caf3cd10e1d2b9d
|
4
|
+
data.tar.gz: 6c5b4d41d5034e25869a6f81eb6da7301097dfe7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb6061b4d66b94d81a6cf346a8439c693db5531da97f87f8de5021508f395196b11f3914c10f66602561b9d8e2be540b11dcc0eda0803577e0083f0797f83c12
|
7
|
+
data.tar.gz: cc61635c99c762b01f606f61f3a367b4d925e85d8551f84b56aa86231b0c266f5414ecef7704a9a332f42e37da4a8beeb63f175cbf7d9ef724076dee7464aaf2
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Oleg Dashevskii
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
Logs the source of execution of cache queries to the Rails log. Helpful to
|
2
|
+
track down where queries are being executed in your application, for
|
3
|
+
performance optimizations most likely.
|
4
|
+
|
5
|
+
This gem is basically a modified version of
|
6
|
+
[active_record_query_trace](https://github.com/ruckus/active-record-query-trace).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'cache-query-trace'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install cache-query-trace
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Enable it in an initializer:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
CacheQueryTrace.enabled = true
|
30
|
+
```
|
31
|
+
|
32
|
+
## Options
|
33
|
+
|
34
|
+
There are three levels of debug.
|
35
|
+
|
36
|
+
1. app - includes only files in your app/ directory.
|
37
|
+
2. full - includes files in your app as well as rails.
|
38
|
+
3. rails - alternate output of full backtrace, useful for debugging gems.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
CacheQueryTrace.level = :app # default
|
42
|
+
```
|
43
|
+
|
44
|
+
Additionally, if you are working with a large app, you may wish to limit the number of lines displayed for each query.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
CacheQueryTrace.lines = 10 # Default is 5. Setting to 0 includes entire trace.
|
48
|
+
```
|
49
|
+
|
50
|
+
## Output
|
51
|
+
|
52
|
+
When enabled cache queries will be logged like:
|
53
|
+
|
54
|
+
```
|
55
|
+
Cache read: posts_count
|
56
|
+
↳ app/controllers/posts_controller.rb:3:in `index'
|
57
|
+
Read fragment views/posts/4-20151210094737092778000/8837ab4e4a7592addd66bce7a312e0e6 (3.1ms)
|
58
|
+
Cache write: views/posts/4-20151210094737092778000/8837ab4e4a7592addd66bce7a312e0e6
|
59
|
+
↳ app/views/posts/index.html.erb:5:in `block in _app_views_posts_index_html_erb__3444413509721278033_69855962868040'
|
60
|
+
from app/views/posts/index.html.erb:4:in `_app_views_posts_index_html_erb__3444413509721278033_69855962868040'
|
61
|
+
↳ app/views/posts/index.html.erb:5:in `block in _app_views_posts_index_html_erb__3444413509721278033_69855962868040'
|
62
|
+
from app/views/posts/index.html.erb:4:in `_app_views_posts_index_html_erb__3444413509721278033_69855962868040'
|
63
|
+
Write fragment views/posts/4-20151210094737092778000/8837ab4e4a7592addd66bce7a312e0e6 (16.4ms)
|
64
|
+
Rendered posts/index.html.erb within layouts/application (184.0ms)
|
65
|
+
```
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cache-query-trace. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
70
|
+
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cache-query-trace"
|
8
|
+
spec.version = CacheQueryTrace::VERSION
|
9
|
+
spec.authors = ["Oleg Dashevskii"]
|
10
|
+
spec.email = ["olegdashevskii@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Print stack trace of all cache queries to the Rails log. Helpful to find where cache queries are being executed in your application"}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/be9/cache-query-trace"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "activesupport", ">= 3.0"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'active_support/log_subscriber'
|
3
|
+
|
4
|
+
module CacheQueryTrace
|
5
|
+
class <<self
|
6
|
+
attr_accessor :enabled
|
7
|
+
attr_accessor :level
|
8
|
+
attr_reader :lines
|
9
|
+
attr_reader :trace_slice
|
10
|
+
|
11
|
+
def lines=(lines)
|
12
|
+
@lines = lines
|
13
|
+
|
14
|
+
@trace_slice = if CacheQueryTrace.lines == 0
|
15
|
+
0..-1
|
16
|
+
else
|
17
|
+
0..(CacheQueryTrace.lines - 1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
23
|
+
def initialize
|
24
|
+
super
|
25
|
+
|
26
|
+
CacheQueryTrace.enabled = false
|
27
|
+
CacheQueryTrace.level = :app
|
28
|
+
CacheQueryTrace.lines = 5
|
29
|
+
|
30
|
+
if CacheQueryTrace.level != :app
|
31
|
+
# Rails by default silences all backtraces that match Rails::BacktraceCleaner::APP_DIRS_PATTERN
|
32
|
+
Rails.backtrace_cleaner.remove_silencers!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def cache_read(event)
|
37
|
+
if CacheQueryTrace.enabled
|
38
|
+
cleaned_trace = clean_trace(caller)[CacheQueryTrace.trace_slice].join("\n from ")
|
39
|
+
debug(" ↳ " + cleaned_trace) unless cleaned_trace.blank?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
alias cache_write cache_read
|
44
|
+
alias cache_delete cache_read
|
45
|
+
alias cache_exist? cache_read
|
46
|
+
|
47
|
+
alias read_fragment cache_read
|
48
|
+
alias write_fragment cache_read
|
49
|
+
alias exist_fragment? cache_read
|
50
|
+
alias expire_fragment cache_read
|
51
|
+
|
52
|
+
def clean_trace(trace)
|
53
|
+
# Rails relies on backtrace cleaner to set the application root directory
|
54
|
+
# filter. The problem is that the backtrace cleaner is initialized
|
55
|
+
# before the application. This ensures that the value of `root` used by
|
56
|
+
# the filter is set to the application root
|
57
|
+
if Rails.backtrace_cleaner.instance_variable_get(:@root) == '/'
|
58
|
+
Rails.backtrace_cleaner.instance_variable_set :@root, Rails.root.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
case CacheQueryTrace.level
|
62
|
+
when :full
|
63
|
+
trace
|
64
|
+
when :rails
|
65
|
+
Rails.respond_to?(:backtrace_cleaner) ? Rails.backtrace_cleaner.clean(trace) : trace
|
66
|
+
when :app
|
67
|
+
Rails.backtrace_cleaner.remove_silencers!
|
68
|
+
Rails.backtrace_cleaner.add_silencer { |line| line !~ /^(app|lib|engines)\// }
|
69
|
+
Rails.backtrace_cleaner.clean(trace)
|
70
|
+
else
|
71
|
+
raise ArgumentError, "Invalid CacheQueryTrace.level value '#{CacheQueryTrace.level}' - should be :full, :rails, or :app"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
attach_to :active_support
|
76
|
+
attach_to :action_controller
|
77
|
+
end
|
78
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cache-query-trace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleg Dashevskii
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Print stack trace of all cache queries to the Rails log. Helpful to find
|
56
|
+
where cache queries are being executed in your application"
|
57
|
+
email:
|
58
|
+
- olegdashevskii@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- cache-query-trace.gemspec
|
70
|
+
- lib/cache-query-trace.rb
|
71
|
+
- lib/version.rb
|
72
|
+
homepage: https://github.com/be9/cache-query-trace
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5.1
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Print stack trace of all cache queries to the Rails log. Helpful to find
|
96
|
+
where cache queries are being executed in your application"
|
97
|
+
test_files: []
|