panjiva-rack-mini-profiler 0.10.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +228 -0
- data/README.md +422 -0
- data/lib/generators/rack_profiler/USAGE +2 -0
- data/lib/generators/rack_profiler/install_generator.rb +11 -0
- data/lib/generators/rack_profiler/templates/rack_profiler.rb +6 -0
- data/lib/html/includes.css +338 -0
- data/lib/html/includes.js +1063 -0
- data/lib/html/includes.scss +542 -0
- data/lib/html/includes.tmpl +223 -0
- data/lib/html/jquery.1.7.1.js +4 -0
- data/lib/html/jquery.tmpl.js +486 -0
- data/lib/html/list.css +9 -0
- data/lib/html/list.js +38 -0
- data/lib/html/list.tmpl +34 -0
- data/lib/html/profile_handler.js +1 -0
- data/lib/html/share.html +11 -0
- data/lib/mini_profiler/asset_version.rb +5 -0
- data/lib/mini_profiler/client_settings.rb +116 -0
- data/lib/mini_profiler/config.rb +92 -0
- data/lib/mini_profiler/context.rb +12 -0
- data/lib/mini_profiler/gc_profiler.rb +157 -0
- data/lib/mini_profiler/profiler.rb +632 -0
- data/lib/mini_profiler/profiling_methods.rb +155 -0
- data/lib/mini_profiler/storage/abstract_store.rb +44 -0
- data/lib/mini_profiler/storage/file_store.rb +172 -0
- data/lib/mini_profiler/storage/memcache_store.rb +89 -0
- data/lib/mini_profiler/storage/memory_store.rb +139 -0
- data/lib/mini_profiler/storage/redis_store.rb +127 -0
- data/lib/mini_profiler/timer_struct/base.rb +36 -0
- data/lib/mini_profiler/timer_struct/client.rb +89 -0
- data/lib/mini_profiler/timer_struct/custom.rb +22 -0
- data/lib/mini_profiler/timer_struct/page.rb +77 -0
- data/lib/mini_profiler/timer_struct/request.rb +134 -0
- data/lib/mini_profiler/timer_struct/sql.rb +79 -0
- data/lib/mini_profiler/version.rb +5 -0
- data/lib/mini_profiler_rails/railtie.rb +139 -0
- data/lib/patches/db/activerecord.rb +53 -0
- data/lib/patches/db/mongo.rb +16 -0
- data/lib/patches/db/moped.rb +12 -0
- data/lib/patches/db/mysql2.rb +28 -0
- data/lib/patches/db/neo4j.rb +14 -0
- data/lib/patches/db/nobrainer.rb +29 -0
- data/lib/patches/db/oracle_enhanced.rb +68 -0
- data/lib/patches/db/pg.rb +102 -0
- data/lib/patches/db/plucky.rb +47 -0
- data/lib/patches/db/riak.rb +103 -0
- data/lib/patches/db/rsolr.rb +24 -0
- data/lib/patches/db/sequel.rb +10 -0
- data/lib/patches/net_patches.rb +14 -0
- data/lib/patches/sql_patches.rb +64 -0
- data/lib/rack-mini-profiler.rb +36 -0
- data/rack-mini-profiler.gemspec +34 -0
- metadata +226 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 476b39e5f201ca78a3971e6b532e80a5ca2ed7a2
|
4
|
+
data.tar.gz: c4e35f88f2ce7f19188b3597d0e9648f6d0f7769
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 364b42648ba1823f776c580f704cbbe4b511d5b39e5e928b456d09ab553864e498399953b186238f4280aa8e358632f1180ab28cd790d9bdf284313910aebb54
|
7
|
+
data.tar.gz: 22d10558c3fb72ec23a9e8d46da92dbc6994241e3970b843ca85743f70631dcae0cb8ee94dda05b242e0d1d9d731a552786d42b096c17ca4f9b745a52fb49ed4
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## ?
|
4
|
+
|
5
|
+
- [FEATURE] Support for vertical positions (top/bottom)
|
6
|
+
|
7
|
+
## 0.10.5 2017-05-22
|
8
|
+
|
9
|
+
- [FIX] revert PG bind sniffing until it is properly tested
|
10
|
+
|
11
|
+
## 0.10.4 2017-05-17
|
12
|
+
|
13
|
+
- [FEATURE] log binds for pg @neznauy
|
14
|
+
- [FIX] use async exec pg monkey patch instead of exec
|
15
|
+
- [FEATURE] nuke less css and use sass instead
|
16
|
+
- [FIX] use jQuery on instead of bind
|
17
|
+
- [FIX] ensure redis get_unviewed_ids returns only ids that exist
|
18
|
+
- [FIX] correctly respect SCRIPT in env if it is sniffed by middleware
|
19
|
+
|
20
|
+
## 0.10.2 2017-02-08
|
21
|
+
|
22
|
+
- [FIX] improve turbolinks support
|
23
|
+
- [FEATURE] make location of mini_profiler injection customizable
|
24
|
+
|
25
|
+
## 0.10.1 2016-05-18
|
26
|
+
|
27
|
+
- [FEATURE] push forward the security checks so no work is ever done if a valid production
|
28
|
+
cookie is not available (@sam)
|
29
|
+
|
30
|
+
## 0.9.9.2 2016-03-06
|
31
|
+
|
32
|
+
- [FEATURE] on pageTransition collapse previously expanded timings
|
33
|
+
|
34
|
+
## 0.9.9.1 2016-03-06
|
35
|
+
|
36
|
+
- [FEATURE] expost MiniProfiler.pageTransition() for use by SPA web apps (@sam)
|
37
|
+
|
38
|
+
## 0.9.9 2016-03-06
|
39
|
+
|
40
|
+
- [FIX] removes alias_method_chain in favor of alias_method until Ruby 1.9.3 (@ayfredlund)
|
41
|
+
- [FIX] Dont block mongo when already patched for another db (@rrooding @kbrock)
|
42
|
+
- [FIX] get_profile_script when running under passenger configured with RailsBaseURI (@nspring)
|
43
|
+
- [FEATURE] Add support for neo4j (@ProGM)
|
44
|
+
- [FIX] ArgumentError: comparison of String with 200 failed (@paweljw)
|
45
|
+
- [FEATURE] Add support for Riak (@janx)
|
46
|
+
- [PERF] GC profiler much faster (@dgynn)
|
47
|
+
- [FIX] If local storage is disabled don't bomb out (@elia)
|
48
|
+
- [FIX] Create tmp directory when actually using it (@kbrock)
|
49
|
+
- [ADDED] Default collapse_results setting that collapses multiple timings on same page to a single one (@sam)
|
50
|
+
- [ADDED] Rack::MiniProfiler.profile_singleton_method (@kbrock)
|
51
|
+
- [CHANGE] Added Rack 2.0 support (and dropped support for Rack 1.1) (@dgynn)
|
52
|
+
|
53
|
+
## 0.9.8 - 2015-11-27 (Sam Saffron)
|
54
|
+
|
55
|
+
- [FEATURE] disable_env_dump config setting (@mathias)
|
56
|
+
- [FEATURE] set X-MiniProfiler-Ids for all 2XX reqs (@tymagu2)
|
57
|
+
- [FEATURE] add support for NoBrainer (rethinkdb) profiling (@niv)
|
58
|
+
- [FEATURE] add oracle enhanced adapter profiling (@rrooding)
|
59
|
+
- [FEATURE] pp=profile-memory can now parse query params (@dgynn)
|
60
|
+
|
61
|
+
|
62
|
+
## 0.9.7 - 2015-08-03 (Sam Saffron)
|
63
|
+
|
64
|
+
- [FEATURE] remove confusing pp=profile-gc-time (Nate Berkopec)
|
65
|
+
- [FEATURE] truncate strings in pp=analyze-memory (Nate Berkopec)
|
66
|
+
- [FEATURE] rename pp=profile-gc-ruby-head to pp=profile-memory (Nate Berkopec)
|
67
|
+
|
68
|
+
## 0.9.6 - 2015-07-08 (Sam Saffron)
|
69
|
+
|
70
|
+
- [FIX] incorrect truncation in pp=analyze-memory
|
71
|
+
|
72
|
+
## 0.9.5 - 2015-07-08 (Sam Saffron)
|
73
|
+
|
74
|
+
- [FEATURE] improve pp=analyze-memory
|
75
|
+
|
76
|
+
## 0.9.4 - 2015-07-08 (Sam Saffron)
|
77
|
+
- [UX] added a link to "more" actions in profiler
|
78
|
+
- [FEATURE] pp=help now displays links
|
79
|
+
- [FEATURE] simple memory report with pp=analyze-memory
|
80
|
+
|
81
|
+
## 0.9.2 - 2014-06-26 (Sam Saffron)
|
82
|
+
- [CHANGE] staging and other environments behave like production (Cedric Felizard)
|
83
|
+
- [DOC] CHANGELOG reorg (Olivier Lacan)
|
84
|
+
- [FIXED] Double calls to Rack::MiniProfilerRails.initialize! now raise an exception (Julik Tarkhanov)
|
85
|
+
- [FIXED] Add no-store header (George Mendoza)
|
86
|
+
|
87
|
+
## 0.9.1 - 2014-03-13 (Sam Saffron)
|
88
|
+
- [ADDED] Added back Ruby 1.8 support (thanks Malet)
|
89
|
+
- [IMPROVED] Amended Railstie so MiniProfiler can be launched with action view or action controller (Thanks Akira)
|
90
|
+
- [FIXED] Rails 3.0 support (thanks Zlatko)
|
91
|
+
- [FIXED] Possible XSS (admin only)
|
92
|
+
- [FIXED] Corrected Sql patching to avoid setting instance vars on nil which is frozen (thanks Andy, huoxito)
|
93
|
+
|
94
|
+
## 0.9.0.pre - 2013-12-12 (Sam Saffron)
|
95
|
+
- Bumped up version to reflect the stability of the project
|
96
|
+
- [IMPROVED] Reports for pp=profile-gc
|
97
|
+
- [IMPROVED] pp=flamegraph&flamegraph_sample_rate=1 , allow you to specify sampling rates
|
98
|
+
|
99
|
+
## 2013-09-17 (Ross Wilson)
|
100
|
+
- [IMPROVED] Instead of supressing all "/assets/" requests we now check the configured
|
101
|
+
config.assets.prefix path since developers can rename the path to serve Asset Pipeline
|
102
|
+
files from
|
103
|
+
|
104
|
+
## 2013-09-03
|
105
|
+
- [IMPROVED] Flamegraph now has much increased fidelity
|
106
|
+
- [REMOVED] Ripped out flamegraph so it can be isolated into a gem
|
107
|
+
- [REMOVED] Ripped out pp=sample it just was never really used
|
108
|
+
|
109
|
+
## 0.1.30 - 2013-08-30
|
110
|
+
- [ADDED] Rack::MiniProfiler.counter_method(klass,name) for injecting counters
|
111
|
+
- [FIXED] Counters were not shifting the table correctly
|
112
|
+
|
113
|
+
## 0.1.29 - 2013-08-20
|
114
|
+
- [ADDED] Implemented exception tracing using TracePoint see pp=trace-exceptions
|
115
|
+
- [FIXED] SOLR patching had an incorrect monkey patch
|
116
|
+
|
117
|
+
## 0.1.28 - 2013-07-30
|
118
|
+
- [FIXED] Diagnostics in abstract storage was raising not implemented killing
|
119
|
+
?pp=env and others
|
120
|
+
- [FIXED] SOLR xml unescaped by mistake
|
121
|
+
|
122
|
+
## 0.1.27 - 2013-06-26
|
123
|
+
- [ADDED] Rack::MiniProfiler.config.backtrace_threshold_ms
|
124
|
+
- [ADDED] jQuery 2.0 support
|
125
|
+
- [FIXED] Disabled global ajax handlers on MP requests @JP
|
126
|
+
|
127
|
+
## 0.1.26 - 2013-04-11
|
128
|
+
- [IMPROVED] Allow Rack::MiniProfilerRails.initialize!(Rails.application), for post config intialization
|
129
|
+
|
130
|
+
## 0.1.25 - 2013-04-08
|
131
|
+
- [FIXED] Missed flamegraph.html from build
|
132
|
+
|
133
|
+
## 0.1.24 - 2013-04-08
|
134
|
+
- [ADDED] Flame Graph Support see: http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler
|
135
|
+
- [ADDED] New toggle_shortcut and start_hidden options
|
136
|
+
- [ADDED] Mongoid support
|
137
|
+
- [ADDED] Rack::MiniProfiler.counter counter_name {}
|
138
|
+
- [ADDED] Net:HTTP profiling
|
139
|
+
- [ADDED] Ruby 1.8.7 support ... grrr
|
140
|
+
- [IMPROVED] More robust gc profiling
|
141
|
+
- [IMPROVED] Script tag initialized via data-attributes
|
142
|
+
- [IMPROVED] Allow usage of existing jQuery if its already loaded
|
143
|
+
- [IMPROVED] Pre-authorize to run in all non development? and production? modes
|
144
|
+
- [FIXED] AngularJS support and MooTools
|
145
|
+
- [FIXED] File retention leak in file_store
|
146
|
+
- [FIXED] HTML5 implicit <body> tags
|
147
|
+
- [FIXED] pp=enable
|
148
|
+
|
149
|
+
## 0.1.22 - 2012-09-20
|
150
|
+
- [FIXED] Permission issue in the gem
|
151
|
+
|
152
|
+
## 2012-09-17
|
153
|
+
- [IMPROVED] Allow rack-mini-profiler to be sourced from github
|
154
|
+
- [IMPROVED] Extracted the pp=profile-gc-time out, the object space profiler needs to disable gc
|
155
|
+
|
156
|
+
## 0.1.21 - 2012-09-17
|
157
|
+
- [ADDED] New MemchacedStore
|
158
|
+
- [ADDED] Rails 4 support
|
159
|
+
|
160
|
+
## 2012-09-12 (Sam Saffron)
|
161
|
+
- [ADDED] pp=profile-gc: allows you to profile the GC in Ruby 1.9.3
|
162
|
+
|
163
|
+
## 0.1.19 - 2012-09-10 (Sam Saffron)
|
164
|
+
- [FIXED] Compatibility issue with Ruby 1.8.7
|
165
|
+
|
166
|
+
## 0.1.17 - 2012-09-09 (Sam Saffron)
|
167
|
+
- [FIXED] pp=sample was bust unless stacktrace was installed
|
168
|
+
|
169
|
+
## 0.1.16 - 2012-09-05 (Sam Saffron)
|
170
|
+
- [IMPROVED] Implemented stacktrace properly
|
171
|
+
- [FIXED] Long standing problem specs (issue with memory store)
|
172
|
+
- [FIXED] Issue where profiler would be dumped when you got a 404 in production (and any time rails is bypassed)
|
173
|
+
|
174
|
+
## 0.1.15.pre - 2012-09-04 (Sam Saffron)
|
175
|
+
- [FIXED] Annoying bug where client settings were not sticking
|
176
|
+
- [FIXED] Long standing issue with Rack::ConditionalGet stopping MiniProfiler from working properly
|
177
|
+
|
178
|
+
## 0.1.13.pre - 2012-09-03 (Sam Saffron)
|
179
|
+
- [ADDED] Setting: config.backtrace_ignores = [] - an array of regexes that match on caller lines that get ignored
|
180
|
+
- [ADDED] Setting: config.backtrace_includes = [] - an array of regexes that get included in the trace by default
|
181
|
+
- [ADDED] pp=normal-backtrace to clear the "sticky" state
|
182
|
+
- [IMPROVED] Cleaned up the way client settings are stored
|
183
|
+
- [IMPROVED] Made pp=full-backtrace "sticky"
|
184
|
+
- [IMPROVED] Changed "pp=sample" to work with "caller" no need for stack trace gem
|
185
|
+
- [FIXED] pg gem prepared statements were not being logged correctly
|
186
|
+
|
187
|
+
## 0.1.12.pre - 2012-08-20 (Sam Saffron)
|
188
|
+
- [IMPROVED] Cap X-MiniProfiler-Ids at 10, otherwise the header can get killed
|
189
|
+
|
190
|
+
## 2012-08-10 (Sam Saffron)
|
191
|
+
- [ADDED] Basic prepared statement profiling for Postgres
|
192
|
+
|
193
|
+
## 2012-08-07 (Sam Saffron)
|
194
|
+
- [ADDED] Option to disable profiler for the current session (pp=disable / pp=enable)
|
195
|
+
- [ADDED] yajl compatability contributed by Sven Riedel
|
196
|
+
|
197
|
+
## 0.1.9 - 2012-07-30 (Sam Saffron)
|
198
|
+
- [IMPROVED] Made compliant with ancient versions of Rack (including Rack used by Rails2)
|
199
|
+
- [FIXED] Broken share link
|
200
|
+
- [FIXED] Crashes on startup (in MemoryStore and FileStore)
|
201
|
+
- [FIXED] Unicode issue
|
202
|
+
|
203
|
+
## 0.1.7 - 2012-07-18 (Sam Saffron)
|
204
|
+
- [ADDED] First Paint time for Google Chrome
|
205
|
+
- [FIXED] Ensure non Rails installs have mini profiler
|
206
|
+
|
207
|
+
## 2012-07-12 (Sam Saffron)
|
208
|
+
- [ADDED] Native PG and MySql2 interceptors, this gives way more accurate times
|
209
|
+
- [ADDED] some more client probing built in to rails
|
210
|
+
- [IMPROVED] Refactored context so its a proper class and not a hash
|
211
|
+
- [IMPROVED] More tests
|
212
|
+
- [FIXED] Incorrect profiling steps (was not indenting or measuring start time right
|
213
|
+
|
214
|
+
## 0.1.3 - 2012-07-09 (Sam Saffron)
|
215
|
+
- [ADDED] New option to display full backtraces pp=full-backtrace
|
216
|
+
- [IMPROVED] Cleaned up mechanism for profiling in production, all you need to do now
|
217
|
+
is call Rack::MiniProfiler.authorize_request to get profiling working in
|
218
|
+
production
|
219
|
+
- [IMPROVED] Cleaned up railties, got rid of the post authorize callback
|
220
|
+
|
221
|
+
## 2012-06-28 (Sam Saffron)
|
222
|
+
- [ADDED] Started change log
|
223
|
+
- [ADDED] added MemcacheStore
|
224
|
+
- [IMPROVED] Corrected profiler so it properly captures POST requests (was supressing non 200s)
|
225
|
+
- [IMPROVED] Amended Rack.MiniProfiler.config[:user_provider] to use ip addres for identity
|
226
|
+
- [IMPROVED] Supress all '/assets/' in the rails tie (makes debugging easier)
|
227
|
+
- [FIXED] Issue where unviewed missing ids never got cleared
|
228
|
+
- [FIXED] record_sql was mega buggy
|
data/README.md
ADDED
@@ -0,0 +1,422 @@
|
|
1
|
+
# rack-mini-profiler
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/MiniProfiler/rack-mini-profiler/badges/gpa.svg)](https://codeclimate.com/github/MiniProfiler/rack-mini-profiler) [![Build Status](https://travis-ci.org/MiniProfiler/rack-mini-profiler.svg)](https://travis-ci.org/MiniProfiler/rack-mini-profiler)
|
4
|
+
|
5
|
+
Middleware that displays speed badge for every html page. Designed to work both in production and in development.
|
6
|
+
|
7
|
+
#### Features
|
8
|
+
|
9
|
+
* Database profiling - Currently supports Mysql2, Postgres, Oracle (oracle_enhanced ~> 1.5.0) and Mongoid3 (with fallback support to ActiveRecord)
|
10
|
+
* Call-stack profiling - Flame graphs showing time spent by gem
|
11
|
+
* Memory profiling - Per-request memory usage, GC stats, and global allocation metrics
|
12
|
+
|
13
|
+
#### Learn more
|
14
|
+
|
15
|
+
* [Visit our community](http://community.miniprofiler.com)
|
16
|
+
* [Watch the RailsCast](http://railscasts.com/episodes/368-miniprofiler)
|
17
|
+
* [Read about Flame graphs in rack-mini-profiler](http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler)
|
18
|
+
* [Read the announcement posts from 2012](http://samsaffron.com/archive/2012/07/12/miniprofiler-ruby-edition)
|
19
|
+
|
20
|
+
## rack-mini-profiler needs your help
|
21
|
+
|
22
|
+
We have decided to restructure our repository so there is a central UI repo and the various language implementation have their own.
|
23
|
+
|
24
|
+
**WE NEED HELP.**
|
25
|
+
|
26
|
+
- Setting up a build that reuses https://github.com/MiniProfiler/ui
|
27
|
+
- Migrating the internal data structures [per the spec](https://github.com/MiniProfiler/ui)
|
28
|
+
|
29
|
+
If you feel like taking on any of this start an issue and update us on your progress.
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Install/add to Gemfile
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'rack-mini-profiler'
|
37
|
+
```
|
38
|
+
|
39
|
+
NOTE: Be sure to require rack_mini_profiler below the `pg` and `mysql` gems in your Gemfile. rack_mini_profiler will identify these gems if they are loaded to insert instrumentation. If included too early no SQL will show up.
|
40
|
+
|
41
|
+
You can also include optional libraries to enable additional features.
|
42
|
+
```ruby
|
43
|
+
# For memory profiling (requires Ruby MRI 2.1+)
|
44
|
+
gem 'memory_profiler'
|
45
|
+
|
46
|
+
# For call-stack profiling flamegraphs (requires Ruby MRI 2.0.0+)
|
47
|
+
gem 'flamegraph'
|
48
|
+
gem 'stackprof' # For Ruby MRI 2.1+
|
49
|
+
gem 'fast_stack' # For Ruby MRI 2.0
|
50
|
+
```
|
51
|
+
|
52
|
+
#### Rails
|
53
|
+
|
54
|
+
All you have to do is to include the Gem and you're good to go in development. See notes below for use in production.
|
55
|
+
|
56
|
+
#### Rails and manual initialization
|
57
|
+
|
58
|
+
In case you need to make sure rack_mini_profiler initialized is after all other gems, or you want to execute some code before rack_mini_profiler required:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem 'rack-mini-profiler', require: false
|
62
|
+
```
|
63
|
+
Note the `require: false` part - if omitted, it will cause the Railtie for the mini-profiler to
|
64
|
+
be loaded outright, and an attempt to re-initialize it manually will raise an exception.
|
65
|
+
|
66
|
+
Then run the generator which will set up rack-mini-profiler in development:
|
67
|
+
|
68
|
+
```bash
|
69
|
+
bundle exec rails g rack_profiler:install
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Rack Builder
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
require 'rack-mini-profiler'
|
76
|
+
|
77
|
+
home = lambda { |env|
|
78
|
+
[200, {'Content-Type' => 'text/html'}, ["<html><body>hello!</body></html>"]]
|
79
|
+
}
|
80
|
+
|
81
|
+
builder = Rack::Builder.new do
|
82
|
+
use Rack::MiniProfiler
|
83
|
+
map('/') { run home }
|
84
|
+
end
|
85
|
+
|
86
|
+
run builder
|
87
|
+
```
|
88
|
+
|
89
|
+
#### Sinatra
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require 'rack-mini-profiler'
|
93
|
+
class MyApp < Sinatra::Base
|
94
|
+
use Rack::MiniProfiler
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
#### Hanami
|
99
|
+
For working with hanami, you need to use rack integration. Also, you need to add `Hanami::View::Rendering::Partial#render` method for profile:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
# config.ru
|
103
|
+
require 'rack-mini-profiler'
|
104
|
+
Rack::MiniProfiler.profile_method(Hanami::View::Rendering::Partial, :render) { "Render partial #{@options[:partial]}" }
|
105
|
+
|
106
|
+
use Rack::MiniProfiler
|
107
|
+
```
|
108
|
+
|
109
|
+
#### Patching ActiveRecord
|
110
|
+
|
111
|
+
A typical web application spends a lot of time querying the database. rack_mini_profiler will detect the ORM that is available
|
112
|
+
and apply patches to properly collect query statistics.
|
113
|
+
|
114
|
+
To make this work, declare the orm's gem before declaring `rack-mini-profiler` in the `Gemfile`:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
gem 'pg'
|
118
|
+
gem 'mongoid'
|
119
|
+
gem 'rack-mini-profiler'
|
120
|
+
|
121
|
+
```
|
122
|
+
|
123
|
+
If you wish to override this behavior, the environment variable `RACK_MINI_PROFILER_PATCH` is available.
|
124
|
+
|
125
|
+
```bash
|
126
|
+
export RACK_MINI_PROFILER_PATCH="pg,mongoid"
|
127
|
+
# or
|
128
|
+
export RACK_MINI_PROFILER_PATCH="false"
|
129
|
+
# initializers/rack_profiler.rb: SqlPatches.patch %w(mongo)
|
130
|
+
```
|
131
|
+
|
132
|
+
### Flamegraphs
|
133
|
+
|
134
|
+
To generate [flamegraphs](http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler):
|
135
|
+
|
136
|
+
* add the [**flamegraph**](https://github.com/SamSaffron/flamegraph) gem to your Gemfile
|
137
|
+
* visit a page in your app with `?pp=flamegraph`
|
138
|
+
|
139
|
+
Flamegraph generation is supported in Ruby MRI 2.0+
|
140
|
+
|
141
|
+
### Memory Profiling
|
142
|
+
|
143
|
+
Memory allocations can be measured (using the [memory_profiler](https://github.com/SamSaffron/memory_profiler) gem)
|
144
|
+
which will show allocations broken down by gem, file location, and class and will also highlight `String` allocations.
|
145
|
+
(Requires Ruby MRI 2.1.0+)
|
146
|
+
|
147
|
+
Add `?pp=profile-memory` to the URL of any request while Rack::MiniProfiler is enabled to generate the report.
|
148
|
+
|
149
|
+
Additional query parameters can be used to filter the results.
|
150
|
+
|
151
|
+
* `memory_profiler_allow_files` - filename pattern to include (default is all files)
|
152
|
+
* `memory_profiler_ignore_files` - filename pattern to exclude (default is no exclusions)
|
153
|
+
* `memory_profiler_top` - number of results per section (defaults to 50)
|
154
|
+
|
155
|
+
The allow/ignore patterns will be treated as regular expressions.
|
156
|
+
|
157
|
+
Example: `?pp=profile-memory&memory_profiler_allow_files=active_record|app`
|
158
|
+
|
159
|
+
There are two additional `pp` options that can be used to analyze memory which do not require the `memory_profiler` gem
|
160
|
+
|
161
|
+
* Use `?pp=profile-gc` to report on Garbage Collection statistics (requires Ruby MRI 1.9.3+)
|
162
|
+
* Use `?pp=analyze-memory` to report on ObjectSpace statistics (requires Ruby 2.0.0+)
|
163
|
+
|
164
|
+
## Access control in non-development environments
|
165
|
+
|
166
|
+
rack-mini-profiler is designed with production profiling in mind. To enable that run `Rack::MiniProfiler.authorize_request` once you know a request is allowed to profile.
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
# inside your ApplicationController
|
170
|
+
|
171
|
+
before_action do
|
172
|
+
if current_user && current_user.is_admin?
|
173
|
+
Rack::MiniProfiler.authorize_request
|
174
|
+
end
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
> If your production application is running on more than one server (or more than one dyno) you will need to configure rack mini profiler's storage to use Redis or Memcache. See [storage](#storage) for information on changing the storage backend.
|
179
|
+
|
180
|
+
Note:
|
181
|
+
|
182
|
+
Out-of-the-box we will initialize the `autorization_mode` to `:whitelist` in production. However, in some cases we may not be able to do it:
|
183
|
+
|
184
|
+
- If you are running in development or test we will not enable whitelist mode
|
185
|
+
- If you use `require: false` on rack_mini_profiler we are unlikely to be able to run the railtie
|
186
|
+
- If you are running outside of rails we will not run the railtie
|
187
|
+
|
188
|
+
In those cases use:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
Rack::MiniProfiler.config.authorization_mode = :whitelist
|
192
|
+
```
|
193
|
+
|
194
|
+
## Configuration
|
195
|
+
|
196
|
+
Various aspects of rack-mini-profiler's behavior can be configured when your app boots.
|
197
|
+
For example in a Rails app, this should be done in an initializer:
|
198
|
+
**config/initializers/mini_profiler.rb**
|
199
|
+
|
200
|
+
### Caching behavior
|
201
|
+
|
202
|
+
To fix some nasty bugs with rack-mini-profiler showing the wrong data, the middleware
|
203
|
+
will remove headers relating to caching (Date & Etag on responses, If-Modified-Since & If-None-Match on requests).
|
204
|
+
This probably won't ever break your application, but it can cause some unexpected behavior. For
|
205
|
+
example, in a Rails app, calls to `stale?` will always return true.
|
206
|
+
|
207
|
+
To disable this behavior, use the following config setting:
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
# Do not let rack-mini-profiler disable caching
|
211
|
+
Rack::MiniProfiler.config.disable_caching = false # defaults to true
|
212
|
+
```
|
213
|
+
|
214
|
+
### Storage
|
215
|
+
|
216
|
+
rack-mini-profiler stores its results so they can be shared later and aren't lost at the end of the request.
|
217
|
+
|
218
|
+
There are 4 storage options: `MemoryStore`, `RedisStore`, `MemcacheStore`, and `FileStore`.
|
219
|
+
|
220
|
+
`FileStore` is the default in Rails environments and will write files to `tmp/miniprofiler/*`. `MemoryStore` is the default otherwise.
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
# set MemoryStore
|
224
|
+
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::MemoryStore
|
225
|
+
|
226
|
+
# set RedisStore
|
227
|
+
if Rails.env.production?
|
228
|
+
uri = URI.parse(ENV["REDIS_SERVER_URL"])
|
229
|
+
Rack::MiniProfiler.config.storage_options = { :host => uri.host, :port => uri.port, :password => uri.password }
|
230
|
+
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::RedisStore
|
231
|
+
end
|
232
|
+
```
|
233
|
+
|
234
|
+
`MemoryStore` stores results in a processes heap - something that does not work well in a multi process environment.
|
235
|
+
`FileStore` stores results in the file system - something that may not work well in a multi machine environment.
|
236
|
+
`RedisStore`/`MemcacheStore` work in multi process and multi machine environments (`RedisStore` only saves results for up to 24 hours so it won't continue to fill up Redis). You will need to add `gem redis`/`gem dalli` respectively to your `Gemfile` to use these stores.
|
237
|
+
|
238
|
+
Additionally you may implement an `AbstractStore` for your own provider.
|
239
|
+
|
240
|
+
### User result segregation
|
241
|
+
|
242
|
+
MiniProfiler will attempt to keep all user results isolated, out-of-the-box the user provider uses the ip address:
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
Rack::MiniProfiler.config.user_provider = Proc.new{|env| Rack::Request.new(env).ip}
|
246
|
+
```
|
247
|
+
|
248
|
+
You can override (something that is very important in a multi-machine production setup):
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
Rack::MiniProfiler.config.user_provider = Proc.new{ |env| CurrentUser.get(env) }
|
252
|
+
```
|
253
|
+
|
254
|
+
The string this function returns should be unique for each user on the system (for anonymous you may need to fall back to ip address)
|
255
|
+
|
256
|
+
### Profiling specific methods
|
257
|
+
|
258
|
+
You can increase the granularity of profiling by measuring the performance of specific methods. Add methods of interest to an initializer.
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
Rails.application.config.to_prepare do
|
262
|
+
::Rack::MiniProfiler.profile_singleton_method(User, :non_admins) { |a| "executing all_non_admins" }
|
263
|
+
::Rack::MiniProfiler.profile_method(User, :favorite_post) { |a| "executing favorite_post" }
|
264
|
+
end
|
265
|
+
```
|
266
|
+
|
267
|
+
### Profiling arbitrary block of code
|
268
|
+
|
269
|
+
It is also possible to profile any arbitrary block of code by passing a block to `Rack::MiniProfiler.step(name, opts=nil)`.
|
270
|
+
|
271
|
+
```ruby
|
272
|
+
Rack::MiniProfiler.step('Adding two elements') do
|
273
|
+
result = 1 + 2
|
274
|
+
end
|
275
|
+
```
|
276
|
+
|
277
|
+
### Using in SPA applications
|
278
|
+
|
279
|
+
Single page applications built using Ember, Angular or other frameworks need some special care, as routes often change without a full page load.
|
280
|
+
|
281
|
+
On route transition always call:
|
282
|
+
|
283
|
+
```
|
284
|
+
window.MiniProfiler.pageTransition();
|
285
|
+
```
|
286
|
+
|
287
|
+
This method will remove profiling information that was related to previous page and clear aggregate statistics.
|
288
|
+
|
289
|
+
#### MiniProfiler's speed badge on pages that are not generated via Rails
|
290
|
+
You need to inject the following in your SPA to load MiniProfiler's speed badge ([extra details surrounding this script](https://github.com/MiniProfiler/rack-mini-profiler/issues/139#issuecomment-192880706)):
|
291
|
+
|
292
|
+
```html
|
293
|
+
<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=12b4b45a3c42e6e15503d7a03810ff33" data-version="12b4b45a3c42e6e15503d7a03810ff33" data-path="/mini-profiler-resources/" data-current-id="redo66j4g1077kto8uh3" data-ids="redo66j4g1077kto8uh3" data-horizontal-position="left" data-vertical-position="top" data-trivial="false" data-children="false" data-max-traces="10" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false" data-collapse-results="true"></script>
|
294
|
+
```
|
295
|
+
|
296
|
+
_Note:_ The GUID (`data-version` and the `?v=` parameter on the `src`) will change with each release of `rack_mini_profiler`. The MiniProfiler's speed badge will continue to work, although you will have to change the GUID to expire the script to fetch the most recent version.
|
297
|
+
|
298
|
+
### Configuration Options
|
299
|
+
|
300
|
+
You can set configuration options using the configuration accessor on `Rack::MiniProfiler`.
|
301
|
+
For example:
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
Rack::MiniProfiler.config.position = 'bottom-right'
|
305
|
+
Rack::MiniProfiler.config.start_hidden = true
|
306
|
+
```
|
307
|
+
The available configuration options are:
|
308
|
+
|
309
|
+
Option|Default|Description
|
310
|
+
-------|---|--------
|
311
|
+
pre_authorize_cb|Rails: dev only<br>Rack: always on|A lambda callback that returns true to make mini_profiler visible on a given request.
|
312
|
+
position|`'top-left'`|Display mini_profiler on `'top-right'`, `'top-left'`, `'bottom-right'` or `'bottom-left'`.
|
313
|
+
skip_paths|`[]`|Paths that skip profiling.
|
314
|
+
skip_schema_queries|Rails dev: `'true'`<br>Othwerwise: `'false'`|`'true'` to log schema queries.
|
315
|
+
auto_inject|`true`|`true` to inject the miniprofiler script in the page.
|
316
|
+
backtrace_ignores|`[]`|Regexes of lines to be removed from backtraces.
|
317
|
+
backtrace_includes|Rails: `[/^\/?(app|config|lib|test)/]`<br>Rack: `[]`|Regexes of lines to keep in backtraces.
|
318
|
+
backtrace_remove|rails: `Rails.root`<br>Rack: `nil`|A string or regex to remove part of each line in the backtrace.
|
319
|
+
toggle_shortcut|Alt+P|Keyboard shortcut to toggle the mini_profiler's visibility. See [jquery.hotkeys](https://github.com/jeresig/jquery.hotkeys).
|
320
|
+
start_hidden|`false`|`false` to make mini_profiler visible on page load.
|
321
|
+
backtrace_threshold_ms|`0`|Minimum SQL query elapsed time before a backtrace is recorded. Backtrace recording can take a couple of milliseconds on rubies earlier than 2.0, impacting performance for very small queries.
|
322
|
+
flamegraph_sample_rate|`0.5`|How often to capture stack traces for flamegraphs in milliseconds.
|
323
|
+
disable_env_dump|`false`|`true` disables `?pp=env`, which prevents sending ENV vars over HTTP.
|
324
|
+
base_url_path|`'/mini-profiler-resources/'`|Path for assets; added as a prefix when naming assets and sought when responding to requests.
|
325
|
+
collapse_results|`true`|If multiple timing results exist in a single page, collapse them till clicked.
|
326
|
+
max_traces_to_show|20|Maximum number of mini profiler timing blocks to show on one page
|
327
|
+
html_container|`body`|The HTML container (as a jQuery selector) to inject the mini_profiler UI into
|
328
|
+
|
329
|
+
### Custom middleware ordering (required if using `Rack::Deflate` with Rails)
|
330
|
+
|
331
|
+
If you are using `Rack::Deflate` with rails and rack-mini-profiler in its default configuration,
|
332
|
+
`Rack::MiniProfiler` will be injected (as always) at position 0 in the middleware stack. This
|
333
|
+
will result in it attempting to inject html into the already-compressed response body. To fix this,
|
334
|
+
the middleware ordering must be overriden.
|
335
|
+
|
336
|
+
To do this, first add `, require: false` to the gemfile entry for rack-mini-profiler.
|
337
|
+
This will prevent the railtie from running. Then, customize the initialization
|
338
|
+
in the initializer like so:
|
339
|
+
|
340
|
+
```ruby
|
341
|
+
require 'rack-mini-profiler'
|
342
|
+
|
343
|
+
Rack::MiniProfilerRails.initialize!(Rails.application)
|
344
|
+
|
345
|
+
Rails.application.middleware.delete(Rack::MiniProfiler)
|
346
|
+
Rails.application.middleware.insert_after(Rack::Deflater, Rack::MiniProfiler)
|
347
|
+
```
|
348
|
+
|
349
|
+
Deleting the middleware and then reinserting it is a bit inelegant, but
|
350
|
+
a sufficient and costless solution. It is possible that rack-mini-profiler might
|
351
|
+
support this scenario more directly if it is found that
|
352
|
+
there is significant need for this confriguration or that
|
353
|
+
the above recipe causes problems.
|
354
|
+
|
355
|
+
|
356
|
+
## Special query strings
|
357
|
+
|
358
|
+
If you include the query string `pp=help` at the end of your request you will see the various options available. You can use these options to extend or contract the amount of diagnostics rack-mini-profiler gathers.
|
359
|
+
|
360
|
+
|
361
|
+
## Rails 2.X support
|
362
|
+
|
363
|
+
To get MiniProfiler working with Rails 2.3.X you need to do the initialization manually as well as monkey patch away an incompatibility between activesupport and json_pure.
|
364
|
+
|
365
|
+
Add the following code to your environment.rb (or just in a specific environment such as development.rb) for initialization and configuration of MiniProfiler.
|
366
|
+
|
367
|
+
```ruby
|
368
|
+
# configure and initialize MiniProfiler
|
369
|
+
require 'rack-mini-profiler'
|
370
|
+
c = ::Rack::MiniProfiler.config
|
371
|
+
c.pre_authorize_cb = lambda { |env|
|
372
|
+
Rails.env.development? || Rails.env.production?
|
373
|
+
}
|
374
|
+
tmp = Rails.root.to_s + "/tmp/miniprofiler"
|
375
|
+
FileUtils.mkdir_p(tmp) unless File.exist?(tmp)
|
376
|
+
c.storage_options = {:path => tmp}
|
377
|
+
c.storage = ::Rack::MiniProfiler::FileStore
|
378
|
+
config.middleware.use(::Rack::MiniProfiler)
|
379
|
+
::Rack::MiniProfiler.profile_method(ActionController::Base, :process) {|action| "Executing action: #{action}"}
|
380
|
+
::Rack::MiniProfiler.profile_method(ActionView::Template, :render) {|x,y| "Rendering: #{path_without_format_and_extension}"}
|
381
|
+
|
382
|
+
# monkey patch away an activesupport and json_pure incompatability
|
383
|
+
# http://pivotallabs.com/users/alex/blog/articles/1332-monkey-patch-of-the-day-activesupport-vs-json-pure-vs-ruby-1-8
|
384
|
+
if JSON.const_defined?(:Pure)
|
385
|
+
class JSON::Pure::Generator::State
|
386
|
+
include ActiveSupport::CoreExtensions::Hash::Except
|
387
|
+
end
|
388
|
+
end
|
389
|
+
```
|
390
|
+
|
391
|
+
## Running the Specs
|
392
|
+
|
393
|
+
```
|
394
|
+
$ rake build
|
395
|
+
$ rake spec
|
396
|
+
```
|
397
|
+
|
398
|
+
Additionally you can also run `autotest` if you like.
|
399
|
+
|
400
|
+
## Licence
|
401
|
+
|
402
|
+
The MIT License (MIT)
|
403
|
+
|
404
|
+
Copyright (c) 2013 Sam Saffron
|
405
|
+
|
406
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
407
|
+
of this software and associated documentation files (the "Software"), to deal
|
408
|
+
in the Software without restriction, including without limitation the rights
|
409
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
410
|
+
copies of the Software, and to permit persons to whom the Software is
|
411
|
+
furnished to do so, subject to the following conditions:
|
412
|
+
|
413
|
+
The above copyright notice and this permission notice shall be included in
|
414
|
+
all copies or substantial portions of the Software.
|
415
|
+
|
416
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
417
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
418
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
419
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
420
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
421
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
422
|
+
THE SOFTWARE.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RackProfiler
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
|
6
|
+
def create_initializer_file
|
7
|
+
copy_file "rack_profiler.rb", "config/initializers/rack_profiler.rb"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|