rack-mini-profiler 0.10.6 → 2.3.0
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +129 -16
- data/README.md +116 -63
- data/lib/enable_rails_patches.rb +5 -0
- data/lib/generators/rack_profiler/install_generator.rb +2 -0
- data/lib/generators/rack_profiler/templates/rack_profiler.rb +2 -0
- data/lib/html/dot.1.1.2.min.js +2 -0
- data/lib/html/includes.css +141 -40
- data/lib/html/includes.js +1398 -970
- data/lib/html/includes.scss +547 -442
- data/lib/html/includes.tmpl +227 -142
- data/lib/html/pretty-print.js +810 -0
- data/lib/html/profile_handler.js +1 -1
- data/lib/html/rack-mini-profiler.css +3 -0
- data/lib/html/rack-mini-profiler.js +2 -0
- data/lib/html/share.html +0 -1
- data/lib/html/speedscope/LICENSE +21 -0
- data/lib/html/speedscope/README.md +3 -0
- data/lib/html/speedscope/demangle-cpp.1768f4cc.js +4 -0
- data/lib/html/speedscope/favicon-16x16.f74b3187.png +0 -0
- data/lib/html/speedscope/favicon-32x32.bc503437.png +0 -0
- data/lib/html/speedscope/file-format-schema.json +324 -0
- data/lib/html/speedscope/import.cf0fa83f.js +115 -0
- data/lib/html/speedscope/index.html +2 -0
- data/lib/html/speedscope/release.txt +3 -0
- data/lib/html/speedscope/reset.8c46b7a1.css +2 -0
- data/lib/html/speedscope/source-map.438fa06b.js +24 -0
- data/lib/html/speedscope/speedscope.44364064.js +200 -0
- data/lib/html/vendor.js +848 -0
- data/lib/mini_profiler/asset_version.rb +3 -2
- data/lib/mini_profiler/client_settings.rb +27 -16
- data/lib/mini_profiler/config.rb +73 -46
- data/lib/mini_profiler/context.rb +5 -3
- data/lib/mini_profiler/gc_profiler.rb +17 -16
- data/lib/mini_profiler/profiler.rb +332 -94
- data/lib/mini_profiler/profiling_methods.rb +20 -15
- data/lib/mini_profiler/snapshots_transporter.rb +109 -0
- data/lib/mini_profiler/storage/abstract_store.rb +80 -0
- data/lib/mini_profiler/storage/file_store.rb +18 -13
- data/lib/mini_profiler/storage/memcache_store.rb +10 -7
- data/lib/mini_profiler/storage/memory_store.rb +63 -13
- data/lib/mini_profiler/storage/redis_store.rb +143 -7
- data/lib/mini_profiler/timer_struct/base.rb +4 -2
- data/lib/mini_profiler/timer_struct/client.rb +9 -8
- data/lib/mini_profiler/timer_struct/custom.rb +8 -5
- data/lib/mini_profiler/timer_struct/page.rb +79 -24
- data/lib/mini_profiler/timer_struct/request.rb +83 -38
- data/lib/mini_profiler/timer_struct/sql.rb +25 -22
- data/lib/mini_profiler/version.rb +3 -1
- data/lib/mini_profiler_rails/railtie.rb +91 -8
- data/lib/mini_profiler_rails/railtie_methods.rb +61 -0
- data/lib/patches/db/activerecord.rb +5 -14
- data/lib/patches/db/mongo.rb +3 -1
- data/lib/patches/db/moped.rb +5 -3
- data/lib/patches/db/mysql2.rb +8 -6
- data/lib/patches/db/neo4j.rb +3 -1
- data/lib/patches/db/nobrainer.rb +4 -2
- data/lib/patches/db/oracle_enhanced.rb +4 -2
- data/lib/patches/db/pg.rb +41 -21
- data/lib/patches/db/plucky.rb +7 -5
- data/lib/patches/db/riak.rb +15 -13
- data/lib/patches/db/rsolr.rb +6 -4
- data/lib/patches/db/sequel.rb +2 -0
- data/lib/patches/net_patches.rb +20 -8
- data/lib/patches/sql_patches.rb +17 -7
- data/lib/prepend_net_http_patch.rb +5 -0
- data/lib/rack-mini-profiler.rb +3 -3
- data/rack-mini-profiler.gemspec +23 -9
- metadata +146 -31
- data/lib/html/jquery.1.7.1.js +0 -4
- data/lib/html/jquery.tmpl.js +0 -486
- data/lib/html/list.css +0 -9
- data/lib/html/list.js +0 -38
- data/lib/html/list.tmpl +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a6623d4a4a1ebc226653d3eee4ed81b531df40ec8a70c953e1bb0778fc73f5dd
|
4
|
+
data.tar.gz: f474a7073db63180736a495694e2690bc39a07fb6a70c2759eabc4dc67cf16e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6737435d523ea5b7b284072c29a9326bbe45ca0b95ce994077af6f8b8000d8f67ec1c8d306c0b027b346a7a0165f5730d96928d341e2d251e3f7488340212350
|
7
|
+
data.tar.gz: 7c2788fb818b599c0ca429f7e2416a5bcba624581dfeda4d31aca8a5e5809769a7daec2aefebdf8b80ef5a186619d27dafc4fd0bcc0befbd66aec910fe3c3d18
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,119 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
##
|
3
|
+
## 2.3.0 - 2020-12-29
|
4
|
+
|
5
|
+
- [FEATURE] flamegraphs are now based off speedscope
|
6
|
+
|
7
|
+
## 2.2.1 - 2020-12-23
|
8
|
+
|
9
|
+
- [FIX] Turbolinks integration causing increasing number of GET requests
|
10
|
+
- [FEATURE] enahanced log transporter with compression and exponential backoff
|
11
|
+
- [FEATURE] sameSite=Lax added to MiniProfiler cookie
|
12
|
+
|
13
|
+
## 2.2.0 - 2020-10-19
|
14
|
+
|
15
|
+
- [UX] Enhancements to snapshots UI
|
16
|
+
- [FEATURE] Mini Profiler cookie is now sameSite=lax
|
17
|
+
- [FEATURE] Snapshots transporter
|
18
|
+
- [FEATURE] Redact SQL queries in snapshots by default
|
19
|
+
|
20
|
+
## 2.1.0 - 2020-09-17
|
21
|
+
|
22
|
+
- [FEATURE] Allow assets to be precompiled with Sprockets
|
23
|
+
- [FEATURE] Snapshots sampling (see README in repo)
|
24
|
+
- [FEATURE] Allow `skip_paths` config to contain regular expressions
|
25
|
+
|
26
|
+
## 2.0.4 - 2020-08-04
|
27
|
+
|
28
|
+
- [FIX] webpacker may exist with no config, allow for that
|
29
|
+
|
30
|
+
## 2.0.3 - 2020-07-29
|
31
|
+
|
32
|
+
- [FIX] support for deprecation free Redis 4.2
|
33
|
+
- [FEATURE] skip /packs when serving static assets
|
34
|
+
- [FEATURE] allow Net::HTTP patch to be applied with either prerpend or alias
|
35
|
+
|
36
|
+
## 2.0.2 - 2020-05-25
|
37
|
+
|
38
|
+
- [FIX] client timings were not showing up when you clicked show trivial
|
39
|
+
|
40
|
+
## 2.0.1 - 2020-03-17
|
41
|
+
|
42
|
+
- [REVERT] Prepend Net::HTTP patch instead of class_eval and aliasing (#429) (technique clashes with New Relic and Skylight agents)
|
43
|
+
|
44
|
+
## 2.0.0 - 2020-03-11
|
45
|
+
|
46
|
+
- [FEATURE] Prepend Net::HTTP patch instead of class_eval and aliasing (#429)
|
47
|
+
- [FEATURE] Stop patching Rails and use `ActiveSupport::Notifications` by default (see README.md for details)
|
48
|
+
|
49
|
+
## 1.1.6 - 2020-01-30
|
50
|
+
|
51
|
+
- [FIX] edge condition on page transition function could lead to exceptions
|
52
|
+
|
53
|
+
## 1.1.5 - 2020-01-28
|
54
|
+
|
55
|
+
- [FIX] correct custom counter regression
|
56
|
+
- [FIX] respect max_traces_to_show
|
57
|
+
- [FIX] handle storage engine failures in whitelist mode
|
58
|
+
|
59
|
+
## 1.1.4 - 2019-12-12
|
60
|
+
|
61
|
+
- [SECURITY] carefully crafted SQL could cause an XSS on sites that do not use CSPs
|
62
|
+
|
63
|
+
## 1.1.3 - 2019-10-28
|
64
|
+
|
65
|
+
- [FEATURE] precompile all templates to avoid need for unsafe-eval
|
66
|
+
|
67
|
+
## 1.1.2 - 2019-10-24
|
68
|
+
|
69
|
+
- [FIX] JS payload was not working on IE11 and leading to errors
|
70
|
+
- [FIX] Remove global singleton_class which was injected
|
71
|
+
- [FIX] Regressions post removal of jQuery
|
72
|
+
|
73
|
+
## 1.1.1 - 2019-10-22
|
74
|
+
|
75
|
+
- [FIX] correct JavaScript fetch support header iteration (Jorge Manrubia)
|
76
|
+
|
77
|
+
## 1.1.0 - 2019-10-01
|
78
|
+
|
79
|
+
- [FEATURE] remove jQuery dependency, switch template library to dot.js
|
80
|
+
- [FEATURE] disable all sensitive debugging methods by default (env, memory profiling) can be enabled with enable_advanced_debugging_tools.
|
81
|
+
- [FIX] when conditionally requiring rack mini profiler, asset precompile could fail
|
82
|
+
- [FEATURE] `/rack-mini-profiler/requests` can be used to monitor all requests for apps that do not have a UI (like API apps)
|
83
|
+
- [SECURITY] XSS injection in `?pp=help` via rogue uri
|
84
|
+
|
85
|
+
## 1.0.2 - 2019-02-05
|
86
|
+
|
87
|
+
- [FIX] correct script injection to work with Rails 6 and above
|
88
|
+
|
89
|
+
## 1.0.1 - 2018-12-10
|
90
|
+
|
91
|
+
- [FIX] add support for exec_params instrumentation in PG, this method as of PG 1.1.0 no longer
|
92
|
+
routes calls to exec / async_exec
|
93
|
+
- [FIX] add missing started_at on requests
|
94
|
+
- [UX] amend colors so we pass lighthouse
|
95
|
+
- [FEATURE] fetch API support
|
96
|
+
- [FIX] getEntriesByName is missing in iOS, workaround
|
97
|
+
- [FEATURE] drop support for Ruby 2.2.0 we require 2.3.0 and up (EOL Ruby no longer supported)
|
98
|
+
|
99
|
+
## 1.0.0 - 2018-03-29
|
100
|
+
|
101
|
+
- [BREAKING CHANGE] Ruby version 2.2.0 or later is required
|
102
|
+
- [FEATURE] use new web performance API to avoid warning @MikeRogers0
|
103
|
+
- [FEATURE] store hidden pref regarding showing mini profiler in session @MikeRogers0
|
104
|
+
- [FIX] correct jQuery 3.0 deprecations @TiSer
|
105
|
+
- [FIX] JS in IFRAME @naiyt
|
106
|
+
|
107
|
+
## 0.10.8 - 2017-12-01
|
108
|
+
|
109
|
+
- [FEATURE] Add `# frozen_string_literal: true` to all `lib/**/*.rb` files
|
110
|
+
|
111
|
+
## 0.10.7 - 2017-11-24
|
112
|
+
|
113
|
+
- [FEATURE] Replace Time.now with Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
114
|
+
- [FIX] Error with webrick and empty cache control
|
115
|
+
|
116
|
+
## 0.10.6 - 2017-10-30
|
4
117
|
|
5
118
|
- [FEATURE] Support for vertical positions (top/bottom)
|
6
119
|
- [FEATURE] Suppress profiler results in print media @Mike Dillon
|
@@ -8,11 +121,11 @@
|
|
8
121
|
- [FEATURE] install generator @yhirano
|
9
122
|
- [FEATURE] store initial cache control headers in X-MiniProfiler-Original-Cache-Control @mrasu
|
10
123
|
|
11
|
-
## 0.10.5 2017-05-22
|
124
|
+
## 0.10.5 - 2017-05-22
|
12
125
|
|
13
126
|
- [FIX] revert PG bind sniffing until it is properly tested
|
14
127
|
|
15
|
-
## 0.10.4 2017-05-17
|
128
|
+
## 0.10.4 - 2017-05-17
|
16
129
|
|
17
130
|
- [FEATURE] log binds for pg @neznauy
|
18
131
|
- [FIX] use async exec pg monkey patch instead of exec
|
@@ -21,25 +134,25 @@
|
|
21
134
|
- [FIX] ensure redis get_unviewed_ids returns only ids that exist
|
22
135
|
- [FIX] correctly respect SCRIPT in env if it is sniffed by middleware
|
23
136
|
|
24
|
-
## 0.10.2 2017-02-08
|
137
|
+
## 0.10.2 - 2017-02-08
|
25
138
|
|
26
139
|
- [FIX] improve turbolinks support
|
27
140
|
- [FEATURE] make location of mini_profiler injection customizable
|
28
141
|
|
29
|
-
## 0.10.1 2016-05-18
|
142
|
+
## 0.10.1 - 2016-05-18
|
30
143
|
|
31
144
|
- [FEATURE] push forward the security checks so no work is ever done if a valid production
|
32
145
|
cookie is not available (@sam)
|
33
146
|
|
34
|
-
## 0.9.9.2 2016-03-06
|
147
|
+
## 0.9.9.2 - 2016-03-06
|
35
148
|
|
36
149
|
- [FEATURE] on pageTransition collapse previously expanded timings
|
37
150
|
|
38
|
-
## 0.9.9.1 2016-03-06
|
151
|
+
## 0.9.9.1 - 2016-03-06
|
39
152
|
|
40
153
|
- [FEATURE] expost MiniProfiler.pageTransition() for use by SPA web apps (@sam)
|
41
154
|
|
42
|
-
## 0.9.9 2016-03-06
|
155
|
+
## 0.9.9 - 2016-03-06
|
43
156
|
|
44
157
|
- [FIX] removes alias_method_chain in favor of alias_method until Ruby 1.9.3 (@ayfredlund)
|
45
158
|
- [FIX] Dont block mongo when already patched for another db (@rrooding @kbrock)
|
@@ -95,7 +208,7 @@
|
|
95
208
|
- [FIXED] Possible XSS (admin only)
|
96
209
|
- [FIXED] Corrected Sql patching to avoid setting instance vars on nil which is frozen (thanks Andy, huoxito)
|
97
210
|
|
98
|
-
## 0.9.0.pre - 2013-12-
|
211
|
+
## 0.9.0.pre - 2013-12-05 (Sam Saffron)
|
99
212
|
- Bumped up version to reflect the stability of the project
|
100
213
|
- [IMPROVED] Reports for pp=profile-gc
|
101
214
|
- [IMPROVED] pp=flamegraph&flamegraph_sample_rate=1 , allow you to specify sampling rates
|
@@ -105,7 +218,7 @@
|
|
105
218
|
config.assets.prefix path since developers can rename the path to serve Asset Pipeline
|
106
219
|
files from
|
107
220
|
|
108
|
-
## 2013-09-03
|
221
|
+
## 0.1.31 - 2013-09-03
|
109
222
|
- [IMPROVED] Flamegraph now has much increased fidelity
|
110
223
|
- [REMOVED] Ripped out flamegraph so it can be isolated into a gem
|
111
224
|
- [REMOVED] Ripped out pp=sample it just was never really used
|
@@ -161,13 +274,13 @@
|
|
161
274
|
- [ADDED] New MemchacedStore
|
162
275
|
- [ADDED] Rails 4 support
|
163
276
|
|
164
|
-
## 2012-09-12 (Sam Saffron)
|
277
|
+
## 0.1.20 - 2012-09-12 (Sam Saffron)
|
165
278
|
- [ADDED] pp=profile-gc: allows you to profile the GC in Ruby 1.9.3
|
166
279
|
|
167
280
|
## 0.1.19 - 2012-09-10 (Sam Saffron)
|
168
281
|
- [FIXED] Compatibility issue with Ruby 1.8.7
|
169
282
|
|
170
|
-
## 0.1.17 - 2012-09-
|
283
|
+
## 0.1.17 - 2012-09-07 (Sam Saffron)
|
171
284
|
- [FIXED] pp=sample was bust unless stacktrace was installed
|
172
285
|
|
173
286
|
## 0.1.16 - 2012-09-05 (Sam Saffron)
|
@@ -191,10 +304,10 @@
|
|
191
304
|
## 0.1.12.pre - 2012-08-20 (Sam Saffron)
|
192
305
|
- [IMPROVED] Cap X-MiniProfiler-Ids at 10, otherwise the header can get killed
|
193
306
|
|
194
|
-
## 2012-08-10 (Sam Saffron)
|
307
|
+
## 0.1.11.pre - 2012-08-10 (Sam Saffron)
|
195
308
|
- [ADDED] Basic prepared statement profiling for Postgres
|
196
309
|
|
197
|
-
## 2012-08-07 (Sam Saffron)
|
310
|
+
## 0.1.10 - 2012-08-07 (Sam Saffron)
|
198
311
|
- [ADDED] Option to disable profiler for the current session (pp=disable / pp=enable)
|
199
312
|
- [ADDED] yajl compatability contributed by Sven Riedel
|
200
313
|
|
@@ -208,7 +321,7 @@
|
|
208
321
|
- [ADDED] First Paint time for Google Chrome
|
209
322
|
- [FIXED] Ensure non Rails installs have mini profiler
|
210
323
|
|
211
|
-
## 2012-07-12 (Sam Saffron)
|
324
|
+
## 0.1.6 - 2012-07-12 (Sam Saffron)
|
212
325
|
- [ADDED] Native PG and MySql2 interceptors, this gives way more accurate times
|
213
326
|
- [ADDED] some more client probing built in to rails
|
214
327
|
- [IMPROVED] Refactored context so its a proper class and not a hash
|
@@ -222,7 +335,7 @@
|
|
222
335
|
production
|
223
336
|
- [IMPROVED] Cleaned up railties, got rid of the post authorize callback
|
224
337
|
|
225
|
-
## 2012-06-28 (Sam Saffron)
|
338
|
+
## 0.1.1 - 2012-06-28 (Sam Saffron)
|
226
339
|
- [ADDED] Started change log
|
227
340
|
- [ADDED] added MemcacheStore
|
228
341
|
- [IMPROVED] Corrected profiler so it properly captures POST requests (was supressing non 200s)
|
data/README.md
CHANGED
@@ -1,20 +1,7 @@
|
|
1
1
|
# rack-mini-profiler
|
2
2
|
|
3
|
-
[](https://codeclimate.com/github/MiniProfiler/rack-mini-profiler) [](https://travis-ci.org/MiniProfiler/rack-mini-profiler)
|
4
|
-
|
5
3
|
Middleware that displays speed badge for every html page. Designed to work both in production and in development.
|
6
4
|
|
7
|
-
# URGENT HELP NEEDED!!!
|
8
|
-
|
9
|
-
Well, not exactly mega urgent, but nice to see you are reading this.
|
10
|
-
|
11
|
-
There are 2 very simple changes I would like to see ASAP
|
12
|
-
|
13
|
-
1. Stop using Time.now EVERYWHERE in rack-mini-profiler and replace with `Process.clock_gettime(Process::CLOCK_MONOTONIC)`
|
14
|
-
2. I would like to see `# frozen_string_literal: true` on every file we ship
|
15
|
-
|
16
|
-
If you pick up either of these, be sure to amend the README in your PR AND add a Changelog.
|
17
|
-
|
18
5
|
#### Features
|
19
6
|
|
20
7
|
* Database profiling - Currently supports Mysql2, Postgres, Oracle (oracle_enhanced ~> 1.5.0) and Mongoid3 (with fallback support to ActiveRecord)
|
@@ -30,18 +17,17 @@ If you pick up either of these, be sure to amend the README in your PR AND add a
|
|
30
17
|
|
31
18
|
## rack-mini-profiler needs your help
|
32
19
|
|
33
|
-
We have decided to restructure our repository so there is a central UI repo and the various language
|
20
|
+
We have decided to restructure our repository so there is a central UI repo and the various language implementations have their own.
|
34
21
|
|
35
22
|
**WE NEED HELP.**
|
36
23
|
|
37
|
-
-
|
38
|
-
- Migrating the internal data structures [per the spec](https://github.com/MiniProfiler/ui)
|
24
|
+
- Help [triage issues](https://www.codetriage.com/miniprofiler/rack-mini-profiler) [](https://www.codetriage.com/miniprofiler/rack-mini-profiler)
|
39
25
|
|
40
26
|
If you feel like taking on any of this start an issue and update us on your progress.
|
41
27
|
|
42
28
|
## Installation
|
43
29
|
|
44
|
-
Install/add to Gemfile
|
30
|
+
Install/add to Gemfile in Ruby 2.4+
|
45
31
|
|
46
32
|
```ruby
|
47
33
|
gem 'rack-mini-profiler'
|
@@ -51,22 +37,50 @@ NOTE: Be sure to require rack_mini_profiler below the `pg` and `mysql` gems in y
|
|
51
37
|
|
52
38
|
You can also include optional libraries to enable additional features.
|
53
39
|
```ruby
|
54
|
-
# For memory profiling
|
40
|
+
# For memory profiling
|
55
41
|
gem 'memory_profiler'
|
56
42
|
|
57
|
-
# For call-stack profiling flamegraphs
|
58
|
-
gem '
|
59
|
-
gem 'stackprof' # For Ruby MRI 2.1+
|
60
|
-
gem 'fast_stack' # For Ruby MRI 2.0
|
43
|
+
# For call-stack profiling flamegraphs
|
44
|
+
gem 'stackprof'
|
61
45
|
```
|
62
46
|
|
63
47
|
#### Rails
|
64
48
|
|
65
49
|
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.
|
66
50
|
|
51
|
+
#### Upgrading to version 2.0.0
|
52
|
+
|
53
|
+
Prior to version 2.0.0, Mini Profiler patched various Rails methods to get the information it needed such as template rendering time. Starting from version 2.0.0, Mini Profiler doesn't patch any Rails methods by default and relies on `ActiveSupport::Notifications` to get the information it needs from Rails. If you want Mini Profiler to keep using its patches in version 2.0.0 and later, change the gem line in your `Gemfile` to the following:
|
54
|
+
|
55
|
+
If you want to manually require Mini Profiler:
|
56
|
+
```ruby
|
57
|
+
gem 'rack-mini-profiler', require: ['enable_rails_patches']
|
58
|
+
```
|
59
|
+
|
60
|
+
If you don't want to manually require Mini Profiler:
|
61
|
+
```ruby
|
62
|
+
gem 'rack-mini-profiler', require: ['enable_rails_patches', 'rack-mini-profiler']
|
63
|
+
```
|
64
|
+
|
65
|
+
#### `Net::HTTP` stack level too deep errors
|
66
|
+
|
67
|
+
If you start seeing `SystemStackError: stack level too deep` errors from `Net::HTTP` after installing Mini Profiler, this means there is another patch for `Net::HTTP#request` that conflicts with Mini Profiler's patch in your application. To fix this, change `rack-mini-profiler` gem line in your `Gemfile` to the following:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
gem 'rack-mini-profiler', require: ['prepend_net_http_patch', 'rack-mini-profiler']
|
71
|
+
```
|
72
|
+
|
73
|
+
If you currently have `require: false`, remove the `'rack-mini-profiler'` string from the `require` array above so the gem line becomes like this:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
gem 'rack-mini-profiler', require: ['prepend_net_http_patch']
|
77
|
+
```
|
78
|
+
|
79
|
+
This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this [ruby issue](https://bugs.ruby-lang.org/issues/11120) for details. The fix is to apply all patches the same way. Mini Profiler by default will apply its patch using method aliasing, but you can change that to module prepend by adding `require: ['prepend_net_http_patch']` to the gem line as shown above.
|
80
|
+
|
67
81
|
#### Rails and manual initialization
|
68
82
|
|
69
|
-
In case you need to make sure rack_mini_profiler initialized
|
83
|
+
In case you need to make sure rack_mini_profiler is initialized after all other gems, or you want to execute some code before rack_mini_profiler required:
|
70
84
|
|
71
85
|
```ruby
|
72
86
|
gem 'rack-mini-profiler', require: false
|
@@ -144,16 +158,13 @@ export RACK_MINI_PROFILER_PATCH="false"
|
|
144
158
|
|
145
159
|
To generate [flamegraphs](http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler):
|
146
160
|
|
147
|
-
* add the [**
|
161
|
+
* add the [**stackprof**](https://rubygems.org/gems/stackprof) gem to your Gemfile
|
148
162
|
* visit a page in your app with `?pp=flamegraph`
|
149
163
|
|
150
|
-
Flamegraph generation is supported in Ruby MRI 2.0+
|
151
|
-
|
152
164
|
### Memory Profiling
|
153
165
|
|
154
166
|
Memory allocations can be measured (using the [memory_profiler](https://github.com/SamSaffron/memory_profiler) gem)
|
155
167
|
which will show allocations broken down by gem, file location, and class and will also highlight `String` allocations.
|
156
|
-
(Requires Ruby MRI 2.1.0+)
|
157
168
|
|
158
169
|
Add `?pp=profile-memory` to the URL of any request while Rack::MiniProfiler is enabled to generate the report.
|
159
170
|
|
@@ -169,8 +180,32 @@ Example: `?pp=profile-memory&memory_profiler_allow_files=active_record|app`
|
|
169
180
|
|
170
181
|
There are two additional `pp` options that can be used to analyze memory which do not require the `memory_profiler` gem
|
171
182
|
|
172
|
-
* Use `?pp=profile-gc` to report on Garbage Collection statistics
|
173
|
-
* Use `?pp=analyze-memory` to report on ObjectSpace statistics
|
183
|
+
* Use `?pp=profile-gc` to report on Garbage Collection statistics
|
184
|
+
* Use `?pp=analyze-memory` to report on ObjectSpace statistics
|
185
|
+
|
186
|
+
### Snapshots Sampling
|
187
|
+
|
188
|
+
In a complex web application, it's possible for a request to trigger rare conditions that result in poor performance. Mini Profiler ships with a feature to help detect those rare conditions and fix them. It works by enabling invisible profiling on one request every N requests, and saving the performance metrics that are collected during the request (a.k.a snapshot of the request) so that they can be viewed later. To turn this feature on, set the `snapshot_every_n_requests` config to a value larger than 0. The larger the value is, the less frequently requests are profiled.
|
189
|
+
|
190
|
+
Mini Profiler will exclude requests that are made to skippd paths (see `skip_paths` config below) from being sampled. Additionally, if profiling is enabled for a request that later finishes with a non-2xx status code, Mini Profiler will discard the snapshot and not save it (this behavior may change in the future).
|
191
|
+
|
192
|
+
After enabling snapshots sampling, you can see the snapshots that have been collected at `/mini-profiler-resources/snapshots` (or if you changed the `base_url_path` config, substitute `mini-profiler-resources` with your value of the config). You'll see on that page a table where each row represents a group of snapshots with the duration of the worst snapshot in that group. The worst snapshot in a group is defined as the snapshot whose request took longer than all of the snapshots in the same group. Snapshots grouped by HTTP method and path of the request, and if your application is a Rails app, Mini Profiler will try to convert the path to `controller#action` and group by that instead of request path. Clicking on a group will display the snapshots of that group sorted from worst to best. From there, you can click on a snapshot's ID to see the snapshot with all the performance metrics that were collected.
|
193
|
+
|
194
|
+
Access to the snapshots page is restricted to only those who can see the speed badge on their own requests, see the section below this one about access control.
|
195
|
+
|
196
|
+
Mini Profiler will keep a maximum of 1000 snapshots by default, and you can change that via the `snapshots_limit` config. When snapshots reach the configured limit, Mini Profiler will save a new snapshot only if it's worse than at least one of the existing snapshots and delete the best one (i.e. the snapshot whose request took the least time compared to other snapshots).
|
197
|
+
|
198
|
+
#### Snapshots Transporter
|
199
|
+
|
200
|
+
Mini Profiler can be configured so that it sends snapshots over HTTP using the snapshots transporter. The main use-case of the transporter is to allow the aggregation of snapshots from multiple applications/sources in a single place. To enable the snapshots transporter, you need to provide a destination URL to the `snapshots_transport_destination_url` config, and a secure key to the `snapshots_transport_auth_key` config (will be used for authorization). Both of these configs are required for the transporter to be enabled.
|
201
|
+
|
202
|
+
The transporter uses a buffer to temporarily hold snapshots in memory with a limit of 100 snapshots. Every 30 seconds, *if* the buffer is not empty, the transporter will make a `POST` request with the buffer content to the destination URL. Requests made by the transporter will have a `Mini-Profiler-Transport-Auth` header with the value of the `snapshots_transport_auth_key` config. The destination should only accept requests that include this header AND the header's value matches the key you set to the `snapshots_transport_auth_key` config.
|
203
|
+
|
204
|
+
If the specified destination responds with a non-200 status code, the transporter will increase the interval between requests by `2^n` seconds where `n` is the number of failed requests since the last successful request. The base interval between requests is 30 seconds. So if a request fails, the next request will be `30 + 2^1 = 32` seconds later. If the next request fails too, the next one will be `30 + 2^2 = 34` seconds later and so on until a request succeeds at which point the interval will return to 30 seconds. The interval will not go beyond 1 hour.
|
205
|
+
|
206
|
+
Requests made by the transporter can be optionally gzip-compressed by setting the `snapshots_transport_gzip_requests` config to true. The body of the requests (after decompression, if you opt for compression) is a JSON string with a single top-level key called `snapshots` and it has an array of snapshots. The structure of a snapshot is too complex to be explained here, but it has the same structure that Mini Profiler client expects. So if your use-case is to simply be able to view snapshots from multiple sources in one place, you should simply store the snapshots as-is, and then serve them to Mini Profiler client to consume. If the destination application also has Mini Profiler, you can simply use the API of the storage backends to store the incoming snapshots and Mini Profiler will treat them the same as local snapshots (e.g. they'll be grouped and displayed in the same manner described in the previous section).
|
207
|
+
|
208
|
+
Mini Profiler offers an API to add extra fields (a.k.a custom fields) to snapshots. For example, you may want to add whether the request was made by a logged-in or anonymous user, the version of your application or any other things that are specific to your application. To add custom fields to a snapshot, call the `Rack::MiniProfiler.add_snapshot_custom_field(<key>, <value>)` method anywhere during the lifetime of a request, and the snapshot of that request will include the fields you added. If you have a Rails app, you can call that method in an `after_action` callback. Custom fields are cleared between requests.
|
174
209
|
|
175
210
|
## Access control in non-development environments
|
176
211
|
|
@@ -202,6 +237,13 @@ In those cases use:
|
|
202
237
|
Rack::MiniProfiler.config.authorization_mode = :whitelist
|
203
238
|
```
|
204
239
|
|
240
|
+
When deciding to fully profile a page mini profiler consults with the `authorization_mode`
|
241
|
+
|
242
|
+
By default in production we attempt to set the authorization mode to `:whitelist` meaning that end user will only be able to see requests where somewhere `Rack::MiniProfiler.authorize_request` is invoked.
|
243
|
+
|
244
|
+
In development we run in the `:allow_all` authorization mode meaning every request is profiled and displayed to the end user.
|
245
|
+
|
246
|
+
|
205
247
|
## Configuration
|
206
248
|
|
207
249
|
Various aspects of rack-mini-profiler's behavior can be configured when your app boots.
|
@@ -236,8 +278,7 @@ Rack::MiniProfiler.config.storage = Rack::MiniProfiler::MemoryStore
|
|
236
278
|
|
237
279
|
# set RedisStore
|
238
280
|
if Rails.env.production?
|
239
|
-
|
240
|
-
Rack::MiniProfiler.config.storage_options = { :host => uri.host, :port => uri.port, :password => uri.password }
|
281
|
+
Rack::MiniProfiler.config.storage_options = { url: ENV["REDIS_SERVER_URL"] }
|
241
282
|
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::RedisStore
|
242
283
|
end
|
243
284
|
```
|
@@ -306,6 +347,18 @@ You need to inject the following in your SPA to load MiniProfiler's speed badge
|
|
306
347
|
|
307
348
|
_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.
|
308
349
|
|
350
|
+
#### Using MiniProfiler's built in route for apps without HTML responses
|
351
|
+
MiniProfiler also ships with a `/rack-mini-profiler/requests` route that displays the speed badge on a blank HTML page. This can be useful when profiling an application that does not render HTML.
|
352
|
+
|
353
|
+
#### Register MiniProfiler's assets in the Rails assets pipeline
|
354
|
+
MiniProfiler can be configured so it registers its assets in the assets pipeline. To do that, you'll need to provide a lambda (or proc) to the `assets_url` config (see the below section). The callback will receive 3 arguments which are: `name` represents asset name (currently it's either `rack-mini-profiling.js` or `rack-mini-profiling.css`), `assets_version` is a 32 characters long hash of MiniProfiler's assets, and `env` which is the `env` object of the request. MiniProfiler expects the `assets_url` callback to return a URL from which the asset can be loaded (the return value will be used as a `href`/`src` attribute in the DOM). If the `assets_url` callback is not set (the default) or it returns a non-truthy value, MiniProfiler will fallback to loading assets from its own middleware (`/mini-profiler-resources/*`). The following callback should work for most applications:
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
Rack::MiniProfiler.config.assets_url = ->(name, version, env) {
|
358
|
+
ActionController::Base.helpers.asset_path(name)
|
359
|
+
}
|
360
|
+
```
|
361
|
+
|
309
362
|
### Configuration Options
|
310
363
|
|
311
364
|
You can set configuration options using the configuration accessor on `Rack::MiniProfiler`.
|
@@ -321,48 +374,38 @@ Option|Default|Description
|
|
321
374
|
-------|---|--------
|
322
375
|
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.
|
323
376
|
position|`'top-left'`|Display mini_profiler on `'top-right'`, `'top-left'`, `'bottom-right'` or `'bottom-left'`.
|
324
|
-
skip_paths|`[]`|
|
325
|
-
skip_schema_queries|Rails dev: `
|
377
|
+
skip_paths|`[]`|An array of paths that skip profiling. Both `String` and `Regexp` are acceptable in the array.
|
378
|
+
skip_schema_queries|Rails dev: `true`<br>Othwerwise: `false`|`true` to skip schema queries.
|
326
379
|
auto_inject|`true`|`true` to inject the miniprofiler script in the page.
|
327
380
|
backtrace_ignores|`[]`|Regexes of lines to be removed from backtraces.
|
328
|
-
backtrace_includes|Rails: `[/^\/?(app
|
381
|
+
backtrace_includes|Rails: `[/^\/?(app\|config\|lib\|test)/]`<br>Rack: `[]`|Regexes of lines to keep in backtraces.
|
329
382
|
backtrace_remove|rails: `Rails.root`<br>Rack: `nil`|A string or regex to remove part of each line in the backtrace.
|
330
383
|
toggle_shortcut|Alt+P|Keyboard shortcut to toggle the mini_profiler's visibility. See [jquery.hotkeys](https://github.com/jeresig/jquery.hotkeys).
|
331
384
|
start_hidden|`false`|`false` to make mini_profiler visible on page load.
|
332
|
-
backtrace_threshold_ms|`0`|Minimum SQL query elapsed time before a backtrace is recorded.
|
385
|
+
backtrace_threshold_ms|`0`|Minimum SQL query elapsed time before a backtrace is recorded.
|
333
386
|
flamegraph_sample_rate|`0.5`|How often to capture stack traces for flamegraphs in milliseconds.
|
334
|
-
disable_env_dump|`false`|`true` disables `?pp=env`, which prevents sending ENV vars over HTTP.
|
335
387
|
base_url_path|`'/mini-profiler-resources/'`|Path for assets; added as a prefix when naming assets and sought when responding to requests.
|
336
388
|
collapse_results|`true`|If multiple timing results exist in a single page, collapse them till clicked.
|
337
389
|
max_traces_to_show|20|Maximum number of mini profiler timing blocks to show on one page
|
338
390
|
html_container|`body`|The HTML container (as a jQuery selector) to inject the mini_profiler UI into
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
will
|
345
|
-
the
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
Rack::
|
355
|
-
|
356
|
-
|
357
|
-
Rails.application.middleware.insert_after(Rack::Deflater, Rack::MiniProfiler)
|
358
|
-
```
|
359
|
-
|
360
|
-
Deleting the middleware and then reinserting it is a bit inelegant, but
|
361
|
-
a sufficient and costless solution. It is possible that rack-mini-profiler might
|
362
|
-
support this scenario more directly if it is found that
|
363
|
-
there is significant need for this confriguration or that
|
364
|
-
the above recipe causes problems.
|
365
|
-
|
391
|
+
show_total_sql_count|`false`|Displays the total number of SQL executions.
|
392
|
+
enable_advanced_debugging_tools|`false`|Enables sensitive debugging tools that can be used via the UI. In production we recommend keeping this disabled as memory and environment debugging tools can expose contents of memory that may contain passwords.
|
393
|
+
assets_url|`nil`|See the "Register MiniProfiler's assets in the Rails assets pipeline" section above.
|
394
|
+
snapshot_every_n_requests|`-1`|Determines how frequently snapshots are taken. See the "Snapshots Sampling" above for more details.
|
395
|
+
snapshots_limit|`1000`|Determines how many snapshots Mini Profiler is allowed to keep.
|
396
|
+
snapshot_hidden_custom_fields|`[]`|Each snapshot custom field will have a dedicated column in the UI by default. Use this config to exclude certain custom fields from having their own columns.
|
397
|
+
snapshots_transport_destination_url|`nil`|Set this config to a valid URL to enable snapshots transporter which will `POST` snapshots to the given URL. The transporter requires `snapshots_transport_auth_key` config to be set as well.
|
398
|
+
snapshots_transport_auth_key|`nil`|`POST` requests made by the snapshots transporter to the destination URL will have a `Mini-Profiler-Transport-Auth` header with the value of this config. Make sure you use a secure and random key for this config.
|
399
|
+
snapshots_redact_sql_queries|`true`|When this is true, SQL queries will be redacted from sampling snapshots, but the backtrace and duration of each SQL query will be saved with the snapshot to keep debugging performance issues possible.
|
400
|
+
snapshots_transport_gzip_requests|`false`|Make the snapshots transporter gzip the requests it makes to `snapshots_transport_destination_url`.
|
401
|
+
|
402
|
+
### Using MiniProfiler with `Rack::Deflate` middleware
|
403
|
+
|
404
|
+
If you are using `Rack::Deflate` with Rails and `rack-mini-profiler` in its default configuration,
|
405
|
+
`Rack::MiniProfiler` will be injected (as always) at position 0 in the middleware stack,
|
406
|
+
which means it will run after `Rack::Deflate` on response processing. To prevent attempting to inject
|
407
|
+
HTML in already compressed response body MiniProfiler will suppress compression by setting
|
408
|
+
`identity` encoding in `Accept-Encoding` request header.
|
366
409
|
|
367
410
|
## Special query strings
|
368
411
|
|
@@ -399,6 +442,16 @@ if JSON.const_defined?(:Pure)
|
|
399
442
|
end
|
400
443
|
```
|
401
444
|
|
445
|
+
## Development
|
446
|
+
|
447
|
+
If you want to contribute to this project, that's great, thank you! You can run the following rake task:
|
448
|
+
|
449
|
+
```
|
450
|
+
$ bundle exec rake client_dev
|
451
|
+
```
|
452
|
+
|
453
|
+
which will start a local Sinatra server at `http://localhost:9292` where you'll be able to preview your changes. Refreshing the page should be enough to see any changes you make to files in the `lib/html` directory.
|
454
|
+
|
402
455
|
## Running the Specs
|
403
456
|
|
404
457
|
```
|
@@ -0,0 +1,2 @@
|
|
1
|
+
/* Laura Doktorova https://github.com/olado/doT */
|
2
|
+
!function(){"use strict";function e(n,t,r){return("string"==typeof t?t:t.toString()).replace(n.define||a,function(e,t,o,a){return 0===t.indexOf("def.")&&(t=t.substring(4)),t in r||(":"===o?(n.defineParams&&a.replace(n.defineParams,function(e,n,o){r[t]={arg:n,text:o}}),t in r||(r[t]=a)):new Function("def","def['"+t+"']="+a)(r)),""}).replace(n.use||a,function(t,o){n.useParams&&(o=o.replace(n.useParams,function(e,n,t,o){if(r[t]&&r[t].arg&&o){var a=(t+":"+o).replace(/'|\\/g,"_");return r.__exp=r.__exp||{},r.__exp[a]=r[t].text.replace(new RegExp("(^|[^\\w$])"+r[t].arg+"([^\\w$])","g"),"$1"+o+"$2"),n+"def.__exp['"+a+"']"}}));var a=new Function("def","return "+o)(r);return a?e(n,a,r):a})}function n(e){return e.replace(/\\('|\\)/g,"$1").replace(/[\r\t\n]/g," ")}var t,r={engine:"doT",version:"1.1.1",templateSettings:{evaluate:/\{\{([\s\S]+?(\}?)+)\}\}/g,interpolate:/\{\{=([\s\S]+?)\}\}/g,encode:/\{\{!([\s\S]+?)\}\}/g,use:/\{\{#([\s\S]+?)\}\}/g,useParams:/(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,define:/\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,defineParams:/^\s*([\w$]+):([\s\S]+)/,conditional:/\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,iterate:/\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,varname:"it",strip:!0,append:!0,selfcontained:!1,doNotSkipEncoded:!1},template:void 0,compile:void 0,log:!0};r.encodeHTMLSource=function(e){var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},t=e?/[&<>"'\/]/g:/&(?!#?\w+;)|<|>|"|'|\//g;return function(e){return e?e.toString().replace(t,function(e){return n[e]||e}):""}},t=function(){return this||(0,eval)("this")}(),"undefined"!=typeof module&&module.exports?module.exports=r:"function"==typeof define&&define.amd?define(function(){return r}):t.doT=r;var o={append:{start:"'+(",end:")+'",startencode:"'+encodeHTML("},split:{start:"';out+=(",end:");out+='",startencode:"';out+=encodeHTML("}},a=/$^/;r.template=function(c,i,u){i=i||r.templateSettings;var d,s,p=i.append?o.append:o.split,l=0,f=i.use||i.define?e(i,c,u||{}):c;f=("var out='"+(i.strip?f.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g," ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,""):f).replace(/'|\\/g,"\\$&").replace(i.interpolate||a,function(e,t){return p.start+n(t)+p.end}).replace(i.encode||a,function(e,t){return d=!0,p.startencode+n(t)+p.end}).replace(i.conditional||a,function(e,t,r){return t?r?"';}else if("+n(r)+"){out+='":"';}else{out+='":r?"';if("+n(r)+"){out+='":"';}out+='"}).replace(i.iterate||a,function(e,t,r,o){return t?(l+=1,s=o||"i"+l,t=n(t),"';var arr"+l+"="+t+";if(arr"+l+"){var "+r+","+s+"=-1,l"+l+"=arr"+l+".length-1;while("+s+"<l"+l+"){"+r+"=arr"+l+"["+s+"+=1];out+='"):"';} } out+='"}).replace(i.evaluate||a,function(e,t){return"';"+n(t)+"out+='"})+"';return out;").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r").replace(/(\s|;|\}|^|\{)out\+='';/g,"$1").replace(/\+''/g,""),d&&(i.selfcontained||!t||t._encodeHTML||(t._encodeHTML=r.encodeHTMLSource(i.doNotSkipEncoded)),f="var encodeHTML = typeof _encodeHTML !== 'undefined' ? _encodeHTML : ("+r.encodeHTMLSource.toString()+"("+(i.doNotSkipEncoded||"")+"));"+f);try{return new Function(i.varname,f)}catch(e){throw"undefined"!=typeof console&&console.log("Could not create a template function: "+f),e}},r.compile=function(e,n){return r.template(e,null,n)}}();
|