rack-mini-profiler 1.0.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +115 -20
  3. data/README.md +126 -45
  4. data/lib/enable_rails_patches.rb +5 -0
  5. data/lib/html/dot.1.1.2.min.js +2 -0
  6. data/lib/html/includes.css +136 -35
  7. data/lib/html/includes.js +1400 -1009
  8. data/lib/html/includes.scss +546 -441
  9. data/lib/html/includes.tmpl +231 -148
  10. data/lib/html/pretty-print.js +810 -0
  11. data/lib/html/profile_handler.js +1 -1
  12. data/lib/html/rack-mini-profiler.css +3 -0
  13. data/lib/html/rack-mini-profiler.js +2 -0
  14. data/lib/html/share.html +0 -1
  15. data/lib/html/speedscope/LICENSE +21 -0
  16. data/lib/html/speedscope/README.md +3 -0
  17. data/lib/html/speedscope/demangle-cpp.1768f4cc.js +4 -0
  18. data/lib/html/speedscope/favicon-16x16.f74b3187.png +0 -0
  19. data/lib/html/speedscope/favicon-32x32.bc503437.png +0 -0
  20. data/lib/html/speedscope/file-format-schema.json +324 -0
  21. data/lib/html/speedscope/fonts/source-code-pro-regular.css +8 -0
  22. data/lib/html/speedscope/fonts/source-code-pro-v13-regular.woff +0 -0
  23. data/lib/html/speedscope/fonts/source-code-pro-v13-regular.woff2 +0 -0
  24. data/lib/html/speedscope/import.cf0fa83f.js +115 -0
  25. data/lib/html/speedscope/index.html +2 -0
  26. data/lib/html/speedscope/release.txt +3 -0
  27. data/lib/html/speedscope/reset.8c46b7a1.css +2 -0
  28. data/lib/html/speedscope/source-map.438fa06b.js +24 -0
  29. data/lib/html/speedscope/speedscope.44364064.js +200 -0
  30. data/lib/html/vendor.js +848 -0
  31. data/lib/mini_profiler/asset_version.rb +3 -2
  32. data/lib/mini_profiler/client_settings.rb +13 -5
  33. data/lib/mini_profiler/config.rb +43 -5
  34. data/lib/mini_profiler/gc_profiler.rb +1 -1
  35. data/lib/mini_profiler/profiler.rb +310 -42
  36. data/lib/mini_profiler/profiling_methods.rb +13 -8
  37. data/lib/mini_profiler/snapshots_transporter.rb +109 -0
  38. data/lib/mini_profiler/storage/abstract_store.rb +79 -1
  39. data/lib/mini_profiler/storage/file_store.rb +3 -3
  40. data/lib/mini_profiler/storage/memcache_store.rb +2 -0
  41. data/lib/mini_profiler/storage/memory_store.rb +54 -5
  42. data/lib/mini_profiler/storage/redis_store.rb +136 -2
  43. data/lib/mini_profiler/timer_struct/custom.rb +1 -0
  44. data/lib/mini_profiler/timer_struct/page.rb +60 -4
  45. data/lib/mini_profiler/timer_struct/request.rb +53 -11
  46. data/lib/mini_profiler/timer_struct/sql.rb +4 -2
  47. data/lib/mini_profiler/version.rb +1 -1
  48. data/lib/mini_profiler_rails/railtie.rb +88 -7
  49. data/lib/mini_profiler_rails/railtie_methods.rb +61 -0
  50. data/lib/patches/db/activerecord.rb +1 -12
  51. data/lib/patches/db/mongo.rb +1 -1
  52. data/lib/patches/db/moped.rb +1 -1
  53. data/lib/patches/db/mysql2.rb +4 -27
  54. data/lib/patches/db/mysql2/alias_method.rb +30 -0
  55. data/lib/patches/db/mysql2/prepend.rb +34 -0
  56. data/lib/patches/db/plucky.rb +4 -4
  57. data/lib/patches/net_patches.rb +18 -8
  58. data/lib/patches/sql_patches.rb +13 -5
  59. data/lib/prepend_mysql2_patch.rb +5 -0
  60. data/lib/prepend_net_http_patch.rb +5 -0
  61. data/lib/rack-mini-profiler.rb +1 -1
  62. data/rack-mini-profiler.gemspec +15 -6
  63. metadata +150 -31
  64. data/lib/html/jquery.1.7.1.js +0 -4
  65. data/lib/html/jquery.tmpl.js +0 -486
  66. data/lib/html/list.css +0 -9
  67. data/lib/html/list.js +0 -38
  68. data/lib/html/list.tmpl +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7c0f5a071d07b17ed627b9c25ca3fa6a60f9670178e990fa8d84e7f826c05ff
4
- data.tar.gz: 94c852d1876cf526cf1f771bb609d6f6993f5d1827da16861128351b59ee0f83
3
+ metadata.gz: 2984e9dec3cda4d5b86a4ed3b8300725207ba826b6a064402b23dcf04b0d5a51
4
+ data.tar.gz: 4a05074c124ac23085c08f4ae5389b71ef7b85687c40c5e5594dee4884d87632
5
5
  SHA512:
6
- metadata.gz: f53c37831ae521bfc0f79dc375595f76165499b76ca60191f5ba88cf811f68abe2c787e548010c68fd209b0b156e06ba6f54b40d10dd24b1297622aefeb80c58
7
- data.tar.gz: 471f7506b95eefc6e9f182a88baa8ef9bd8f613557619d3c34ce7f4d1831026f48ba61da7160dcb3ae7adca4dbf5d33766bbba48880a84633ee7692a2ae9ad1f
6
+ metadata.gz: b29d4a47e99d03489251752bfe57a2b64235400b5ffb9f867738bfb9d165f63ddeeb559fc4edf9a60c91fe2d579b04ee473db1b2c7846ab823580d8b9b5e88c1
7
+ data.tar.gz: 3a0768401c048801bf4adb22792fbdb2643d5b5e0174f92149df96c8ae2ab79d0c504e9e2146d72cc45068df6b88ebc675ef11431d47c17a5b929f375a1e6d74
data/CHANGELOG.md CHANGED
@@ -1,6 +1,101 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 1.0.1 2018-12-10
3
+ ## 2.3.2 - 2021-04-30
4
+
5
+ - [FEATURE] Introduce `pp=async-flamegraph` for asynchronous flamegraphs
6
+
7
+ ## 2.3.1 - 2021-01-29
8
+
9
+ - [FIX] compatability with Ruby 3.0
10
+ - [FIX] compatability with peek-mysql2
11
+
12
+ ## 2.3.0 - 2020-12-29
13
+
14
+ - [FEATURE] flamegraphs are now based off speedscope
15
+
16
+ ## 2.2.1 - 2020-12-23
17
+
18
+ - [FIX] Turbolinks integration causing increasing number of GET requests
19
+ - [FEATURE] enahanced log transporter with compression and exponential backoff
20
+ - [FEATURE] sameSite=Lax added to MiniProfiler cookie
21
+
22
+ ## 2.2.0 - 2020-10-19
23
+
24
+ - [UX] Enhancements to snapshots UI
25
+ - [FEATURE] Mini Profiler cookie is now sameSite=lax
26
+ - [FEATURE] Snapshots transporter
27
+ - [FEATURE] Redact SQL queries in snapshots by default
28
+
29
+ ## 2.1.0 - 2020-09-17
30
+
31
+ - [FEATURE] Allow assets to be precompiled with Sprockets
32
+ - [FEATURE] Snapshots sampling (see README in repo)
33
+ - [FEATURE] Allow `skip_paths` config to contain regular expressions
34
+
35
+ ## 2.0.4 - 2020-08-04
36
+
37
+ - [FIX] webpacker may exist with no config, allow for that
38
+
39
+ ## 2.0.3 - 2020-07-29
40
+
41
+ - [FIX] support for deprecation free Redis 4.2
42
+ - [FEATURE] skip /packs when serving static assets
43
+ - [FEATURE] allow Net::HTTP patch to be applied with either prerpend or alias
44
+
45
+ ## 2.0.2 - 2020-05-25
46
+
47
+ - [FIX] client timings were not showing up when you clicked show trivial
48
+
49
+ ## 2.0.1 - 2020-03-17
50
+
51
+ - [REVERT] Prepend Net::HTTP patch instead of class_eval and aliasing (#429) (technique clashes with New Relic and Skylight agents)
52
+
53
+ ## 2.0.0 - 2020-03-11
54
+
55
+ - [FEATURE] Prepend Net::HTTP patch instead of class_eval and aliasing (#429)
56
+ - [FEATURE] Stop patching Rails and use `ActiveSupport::Notifications` by default (see README.md for details)
57
+
58
+ ## 1.1.6 - 2020-01-30
59
+
60
+ - [FIX] edge condition on page transition function could lead to exceptions
61
+
62
+ ## 1.1.5 - 2020-01-28
63
+
64
+ - [FIX] correct custom counter regression
65
+ - [FIX] respect max_traces_to_show
66
+ - [FIX] handle storage engine failures in whitelist mode
67
+
68
+ ## 1.1.4 - 2019-12-12
69
+
70
+ - [SECURITY] carefully crafted SQL could cause an XSS on sites that do not use CSPs
71
+
72
+ ## 1.1.3 - 2019-10-28
73
+
74
+ - [FEATURE] precompile all templates to avoid need for unsafe-eval
75
+
76
+ ## 1.1.2 - 2019-10-24
77
+
78
+ - [FIX] JS payload was not working on IE11 and leading to errors
79
+ - [FIX] Remove global singleton_class which was injected
80
+ - [FIX] Regressions post removal of jQuery
81
+
82
+ ## 1.1.1 - 2019-10-22
83
+
84
+ - [FIX] correct JavaScript fetch support header iteration (Jorge Manrubia)
85
+
86
+ ## 1.1.0 - 2019-10-01
87
+
88
+ - [FEATURE] remove jQuery dependency, switch template library to dot.js
89
+ - [FEATURE] disable all sensitive debugging methods by default (env, memory profiling) can be enabled with enable_advanced_debugging_tools.
90
+ - [FIX] when conditionally requiring rack mini profiler, asset precompile could fail
91
+ - [FEATURE] `/rack-mini-profiler/requests` can be used to monitor all requests for apps that do not have a UI (like API apps)
92
+ - [SECURITY] XSS injection in `?pp=help` via rogue uri
93
+
94
+ ## 1.0.2 - 2019-02-05
95
+
96
+ - [FIX] correct script injection to work with Rails 6 and above
97
+
98
+ ## 1.0.1 - 2018-12-10
4
99
 
5
100
  - [FIX] add support for exec_params instrumentation in PG, this method as of PG 1.1.0 no longer
6
101
  routes calls to exec / async_exec
@@ -10,7 +105,7 @@
10
105
  - [FIX] getEntriesByName is missing in iOS, workaround
11
106
  - [FEATURE] drop support for Ruby 2.2.0 we require 2.3.0 and up (EOL Ruby no longer supported)
12
107
 
13
- ## 1.0.0 2017-03-29
108
+ ## 1.0.0 - 2018-03-29
14
109
 
15
110
  - [BREAKING CHANGE] Ruby version 2.2.0 or later is required
16
111
  - [FEATURE] use new web performance API to avoid warning @MikeRogers0
@@ -18,16 +113,16 @@
18
113
  - [FIX] correct jQuery 3.0 deprecations @TiSer
19
114
  - [FIX] JS in IFRAME @naiyt
20
115
 
21
- ## 0.10.8 2017-12-01
116
+ ## 0.10.8 - 2017-12-01
22
117
 
23
118
  - [FEATURE] Add `# frozen_string_literal: true` to all `lib/**/*.rb` files
24
119
 
25
- ## 0.10.7 2017-11-24
120
+ ## 0.10.7 - 2017-11-24
26
121
 
27
122
  - [FEATURE] Replace Time.now with Process.clock_gettime(Process::CLOCK_MONOTONIC)
28
123
  - [FIX] Error with webrick and empty cache control
29
124
 
30
- ## 0.10.6 2017-10-30
125
+ ## 0.10.6 - 2017-10-30
31
126
 
32
127
  - [FEATURE] Support for vertical positions (top/bottom)
33
128
  - [FEATURE] Suppress profiler results in print media @Mike Dillon
@@ -35,11 +130,11 @@
35
130
  - [FEATURE] install generator @yhirano
36
131
  - [FEATURE] store initial cache control headers in X-MiniProfiler-Original-Cache-Control @mrasu
37
132
 
38
- ## 0.10.5 2017-05-22
133
+ ## 0.10.5 - 2017-05-22
39
134
 
40
135
  - [FIX] revert PG bind sniffing until it is properly tested
41
136
 
42
- ## 0.10.4 2017-05-17
137
+ ## 0.10.4 - 2017-05-17
43
138
 
44
139
  - [FEATURE] log binds for pg @neznauy
45
140
  - [FIX] use async exec pg monkey patch instead of exec
@@ -48,25 +143,25 @@
48
143
  - [FIX] ensure redis get_unviewed_ids returns only ids that exist
49
144
  - [FIX] correctly respect SCRIPT in env if it is sniffed by middleware
50
145
 
51
- ## 0.10.2 2017-02-08
146
+ ## 0.10.2 - 2017-02-08
52
147
 
53
148
  - [FIX] improve turbolinks support
54
149
  - [FEATURE] make location of mini_profiler injection customizable
55
150
 
56
- ## 0.10.1 2016-05-18
151
+ ## 0.10.1 - 2016-05-18
57
152
 
58
153
  - [FEATURE] push forward the security checks so no work is ever done if a valid production
59
154
  cookie is not available (@sam)
60
155
 
61
- ## 0.9.9.2 2016-03-06
156
+ ## 0.9.9.2 - 2016-03-06
62
157
 
63
158
  - [FEATURE] on pageTransition collapse previously expanded timings
64
159
 
65
- ## 0.9.9.1 2016-03-06
160
+ ## 0.9.9.1 - 2016-03-06
66
161
 
67
162
  - [FEATURE] expost MiniProfiler.pageTransition() for use by SPA web apps (@sam)
68
163
 
69
- ## 0.9.9 2016-03-06
164
+ ## 0.9.9 - 2016-03-06
70
165
 
71
166
  - [FIX] removes alias_method_chain in favor of alias_method until Ruby 1.9.3 (@ayfredlund)
72
167
  - [FIX] Dont block mongo when already patched for another db (@rrooding @kbrock)
@@ -122,7 +217,7 @@
122
217
  - [FIXED] Possible XSS (admin only)
123
218
  - [FIXED] Corrected Sql patching to avoid setting instance vars on nil which is frozen (thanks Andy, huoxito)
124
219
 
125
- ## 0.9.0.pre - 2013-12-12 (Sam Saffron)
220
+ ## 0.9.0.pre - 2013-12-05 (Sam Saffron)
126
221
  - Bumped up version to reflect the stability of the project
127
222
  - [IMPROVED] Reports for pp=profile-gc
128
223
  - [IMPROVED] pp=flamegraph&flamegraph_sample_rate=1 , allow you to specify sampling rates
@@ -132,7 +227,7 @@
132
227
  config.assets.prefix path since developers can rename the path to serve Asset Pipeline
133
228
  files from
134
229
 
135
- ## 2013-09-03
230
+ ## 0.1.31 - 2013-09-03
136
231
  - [IMPROVED] Flamegraph now has much increased fidelity
137
232
  - [REMOVED] Ripped out flamegraph so it can be isolated into a gem
138
233
  - [REMOVED] Ripped out pp=sample it just was never really used
@@ -188,13 +283,13 @@
188
283
  - [ADDED] New MemchacedStore
189
284
  - [ADDED] Rails 4 support
190
285
 
191
- ## 2012-09-12 (Sam Saffron)
286
+ ## 0.1.20 - 2012-09-12 (Sam Saffron)
192
287
  - [ADDED] pp=profile-gc: allows you to profile the GC in Ruby 1.9.3
193
288
 
194
289
  ## 0.1.19 - 2012-09-10 (Sam Saffron)
195
290
  - [FIXED] Compatibility issue with Ruby 1.8.7
196
291
 
197
- ## 0.1.17 - 2012-09-09 (Sam Saffron)
292
+ ## 0.1.17 - 2012-09-07 (Sam Saffron)
198
293
  - [FIXED] pp=sample was bust unless stacktrace was installed
199
294
 
200
295
  ## 0.1.16 - 2012-09-05 (Sam Saffron)
@@ -218,10 +313,10 @@
218
313
  ## 0.1.12.pre - 2012-08-20 (Sam Saffron)
219
314
  - [IMPROVED] Cap X-MiniProfiler-Ids at 10, otherwise the header can get killed
220
315
 
221
- ## 2012-08-10 (Sam Saffron)
316
+ ## 0.1.11.pre - 2012-08-10 (Sam Saffron)
222
317
  - [ADDED] Basic prepared statement profiling for Postgres
223
318
 
224
- ## 2012-08-07 (Sam Saffron)
319
+ ## 0.1.10 - 2012-08-07 (Sam Saffron)
225
320
  - [ADDED] Option to disable profiler for the current session (pp=disable / pp=enable)
226
321
  - [ADDED] yajl compatability contributed by Sven Riedel
227
322
 
@@ -235,7 +330,7 @@
235
330
  - [ADDED] First Paint time for Google Chrome
236
331
  - [FIXED] Ensure non Rails installs have mini profiler
237
332
 
238
- ## 2012-07-12 (Sam Saffron)
333
+ ## 0.1.6 - 2012-07-12 (Sam Saffron)
239
334
  - [ADDED] Native PG and MySql2 interceptors, this gives way more accurate times
240
335
  - [ADDED] some more client probing built in to rails
241
336
  - [IMPROVED] Refactored context so its a proper class and not a hash
@@ -249,7 +344,7 @@
249
344
  production
250
345
  - [IMPROVED] Cleaned up railties, got rid of the post authorize callback
251
346
 
252
- ## 2012-06-28 (Sam Saffron)
347
+ ## 0.1.1 - 2012-06-28 (Sam Saffron)
253
348
  - [ADDED] Started change log
254
349
  - [ADDED] added MemcacheStore
255
350
  - [IMPROVED] Corrected profiler so it properly captures POST requests (was supressing non 200s)
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # rack-mini-profiler
2
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
3
  Middleware that displays speed badge for every html page. Designed to work both in production and in development.
6
4
 
7
5
  #### Features
@@ -19,18 +17,17 @@ Middleware that displays speed badge for every html page. Designed to work both
19
17
 
20
18
  ## rack-mini-profiler needs your help
21
19
 
22
- We have decided to restructure our repository so there is a central UI repo and the various language implementation have their own.
20
+ We have decided to restructure our repository so there is a central UI repo and the various language implementations have their own.
23
21
 
24
22
  **WE NEED HELP.**
25
23
 
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)
24
+ - Help [triage issues](https://www.codetriage.com/miniprofiler/rack-mini-profiler) [![Open Source Helpers](https://www.codetriage.com/miniprofiler/rack-mini-profiler/badges/users.svg)](https://www.codetriage.com/miniprofiler/rack-mini-profiler)
28
25
 
29
26
  If you feel like taking on any of this start an issue and update us on your progress.
30
27
 
31
28
  ## Installation
32
29
 
33
- Install/add to Gemfile in Ruby 2.3+
30
+ Install/add to Gemfile in Ruby 2.4+
34
31
 
35
32
  ```ruby
36
33
  gem 'rack-mini-profiler'
@@ -44,7 +41,6 @@ You can also include optional libraries to enable additional features.
44
41
  gem 'memory_profiler'
45
42
 
46
43
  # For call-stack profiling flamegraphs
47
- gem 'flamegraph'
48
44
  gem 'stackprof'
49
45
  ```
50
46
 
@@ -52,9 +48,49 @@ gem 'stackprof'
52
48
 
53
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.
54
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
+
81
+ #### `peek-mysql2` stack level too deep errors
82
+
83
+ If you use peek-mysql2 with Rails >= 5, you'll need to use this gem spec in your Gemfile:
84
+
85
+ ```ruby
86
+ gem 'rack-mini-profiler', require: ['prepend_mysql2_patch', 'rack-mini-profiler']
87
+ ```
88
+
89
+ This should not be necessary with Rails < 5 because peek-mysql2 hooks into mysql2 gem in different ways depending on your Rails version.
90
+
55
91
  #### Rails and manual initialization
56
92
 
57
- 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:
93
+ 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:
58
94
 
59
95
  ```ruby
60
96
  gem 'rack-mini-profiler', require: false
@@ -132,9 +168,13 @@ export RACK_MINI_PROFILER_PATCH="false"
132
168
 
133
169
  To generate [flamegraphs](http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler):
134
170
 
135
- * add the [**flamegraph**](https://github.com/SamSaffron/flamegraph) gem to your Gemfile
171
+ * add the [**stackprof**](https://rubygems.org/gems/stackprof) gem to your Gemfile
136
172
  * visit a page in your app with `?pp=flamegraph`
137
173
 
174
+ To store flamegraph data for later viewing, append the `?pp=async-flamegraph` parameter. The request will return as normal.
175
+ Flamegraph data for this request, and all subsequent requests made by this page (based on the `REFERER` header) will be stored.
176
+ 'flamegraph' links will appear for these requests in the MiniProfiler UI.
177
+
138
178
  ### Memory Profiling
139
179
 
140
180
  Memory allocations can be measured (using the [memory_profiler](https://github.com/SamSaffron/memory_profiler) gem)
@@ -157,6 +197,30 @@ There are two additional `pp` options that can be used to analyze memory which d
157
197
  * Use `?pp=profile-gc` to report on Garbage Collection statistics
158
198
  * Use `?pp=analyze-memory` to report on ObjectSpace statistics
159
199
 
200
+ ### Snapshots Sampling
201
+
202
+ 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.
203
+
204
+ Mini Profiler will exclude requests that are made to skipped 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).
205
+
206
+ 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.
207
+
208
+ 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.
209
+
210
+ 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).
211
+
212
+ #### Snapshots Transporter
213
+
214
+ 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.
215
+
216
+ 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.
217
+
218
+ 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.
219
+
220
+ 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).
221
+
222
+ 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.
223
+
160
224
  ## Access control in non-development environments
161
225
 
162
226
  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.
@@ -175,18 +239,25 @@ rack-mini-profiler is designed with production profiling in mind. To enable that
175
239
 
176
240
  Note:
177
241
 
178
- Out-of-the-box we will initialize the `authorization_mode` to `:whitelist` in production. However, in some cases we may not be able to do it:
242
+ Out-of-the-box we will initialize the `authorization_mode` to `:allow_authorized` in production. However, in some cases we may not be able to do it:
179
243
 
180
- - If you are running in development or test we will not enable whitelist mode
244
+ - If you are running in development or test we will not enable the explicit authorization mode
181
245
  - If you use `require: false` on rack_mini_profiler we are unlikely to be able to run the railtie
182
246
  - If you are running outside of rails we will not run the railtie
183
247
 
184
248
  In those cases use:
185
249
 
186
250
  ```ruby
187
- Rack::MiniProfiler.config.authorization_mode = :whitelist
251
+ Rack::MiniProfiler.config.authorization_mode = :allow_authorized
188
252
  ```
189
253
 
254
+ When deciding to fully profile a page mini profiler consults with the `authorization_mode`
255
+
256
+ By default in production we attempt to set the authorization mode to `:allow_authorized` meaning that end user will only be able to see requests where somewhere `Rack::MiniProfiler.authorize_request` is invoked.
257
+
258
+ In development we run in the `:allow_all` authorization mode meaning every request is profiled and displayed to the end user.
259
+
260
+
190
261
  ## Configuration
191
262
 
192
263
  Various aspects of rack-mini-profiler's behavior can be configured when your app boots.
@@ -221,8 +292,7 @@ Rack::MiniProfiler.config.storage = Rack::MiniProfiler::MemoryStore
221
292
 
222
293
  # set RedisStore
223
294
  if Rails.env.production?
224
- uri = URI.parse(ENV["REDIS_SERVER_URL"])
225
- Rack::MiniProfiler.config.storage_options = { :host => uri.host, :port => uri.port, :password => uri.password }
295
+ Rack::MiniProfiler.config.storage_options = { url: ENV["REDIS_SERVER_URL"] }
226
296
  Rack::MiniProfiler.config.storage = Rack::MiniProfiler::RedisStore
227
297
  end
228
298
  ```
@@ -291,6 +361,18 @@ You need to inject the following in your SPA to load MiniProfiler's speed badge
291
361
 
292
362
  _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.
293
363
 
364
+ #### Using MiniProfiler's built in route for apps without HTML responses
365
+ 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.
366
+
367
+ #### Register MiniProfiler's assets in the Rails assets pipeline
368
+ 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:
369
+
370
+ ```ruby
371
+ Rack::MiniProfiler.config.assets_url = ->(name, version, env) {
372
+ ActionController::Base.helpers.asset_path(name)
373
+ }
374
+ ```
375
+
294
376
  ### Configuration Options
295
377
 
296
378
  You can set configuration options using the configuration accessor on `Rack::MiniProfiler`.
@@ -306,49 +388,38 @@ Option|Default|Description
306
388
  -------|---|--------
307
389
  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.
308
390
  position|`'top-left'`|Display mini_profiler on `'top-right'`, `'top-left'`, `'bottom-right'` or `'bottom-left'`.
309
- skip_paths|`[]`|Paths that skip profiling.
310
- skip_schema_queries|Rails dev: `'true'`<br>Othwerwise: `'false'`|`'true'` to log schema queries.
391
+ skip_paths|`[]`|An array of paths that skip profiling. Both `String` and `Regexp` are acceptable in the array.
392
+ skip_schema_queries|Rails dev: `true`<br>Othwerwise: `false`|`true` to skip schema queries.
311
393
  auto_inject|`true`|`true` to inject the miniprofiler script in the page.
312
394
  backtrace_ignores|`[]`|Regexes of lines to be removed from backtraces.
313
- backtrace_includes|Rails: `[/^\/?(app|config|lib|test)/]`<br>Rack: `[]`|Regexes of lines to keep in backtraces.
395
+ backtrace_includes|Rails: `[/^\/?(app\|config\|lib\|test)/]`<br>Rack: `[]`|Regexes of lines to keep in backtraces.
314
396
  backtrace_remove|rails: `Rails.root`<br>Rack: `nil`|A string or regex to remove part of each line in the backtrace.
315
397
  toggle_shortcut|Alt+P|Keyboard shortcut to toggle the mini_profiler's visibility. See [jquery.hotkeys](https://github.com/jeresig/jquery.hotkeys).
316
398
  start_hidden|`false`|`false` to make mini_profiler visible on page load.
317
399
  backtrace_threshold_ms|`0`|Minimum SQL query elapsed time before a backtrace is recorded.
318
400
  flamegraph_sample_rate|`0.5`|How often to capture stack traces for flamegraphs in milliseconds.
319
- disable_env_dump|`false`|`true` disables `?pp=env`, which prevents sending ENV vars over HTTP.
320
401
  base_url_path|`'/mini-profiler-resources/'`|Path for assets; added as a prefix when naming assets and sought when responding to requests.
321
402
  collapse_results|`true`|If multiple timing results exist in a single page, collapse them till clicked.
322
403
  max_traces_to_show|20|Maximum number of mini profiler timing blocks to show on one page
323
404
  html_container|`body`|The HTML container (as a jQuery selector) to inject the mini_profiler UI into
324
405
  show_total_sql_count|`false`|Displays the total number of SQL executions.
325
-
326
- ### Custom middleware ordering (required if using `Rack::Deflate` with Rails)
327
-
328
- If you are using `Rack::Deflate` with rails and rack-mini-profiler in its default configuration,
329
- `Rack::MiniProfiler` will be injected (as always) at position 0 in the middleware stack. This
330
- will result in it attempting to inject html into the already-compressed response body. To fix this,
331
- the middleware ordering must be overriden.
332
-
333
- To do this, first add `, require: false` to the gemfile entry for rack-mini-profiler.
334
- This will prevent the railtie from running. Then, customize the initialization
335
- in the initializer like so:
336
-
337
- ```ruby
338
- require 'rack-mini-profiler'
339
-
340
- Rack::MiniProfilerRails.initialize!(Rails.application)
341
-
342
- Rails.application.middleware.delete(Rack::MiniProfiler)
343
- Rails.application.middleware.insert_after(Rack::Deflater, Rack::MiniProfiler)
344
- ```
345
-
346
- Deleting the middleware and then reinserting it is a bit inelegant, but
347
- a sufficient and costless solution. It is possible that rack-mini-profiler might
348
- support this scenario more directly if it is found that
349
- there is significant need for this confriguration or that
350
- the above recipe causes problems.
351
-
406
+ 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.
407
+ assets_url|`nil`|See the "Register MiniProfiler's assets in the Rails assets pipeline" section above.
408
+ snapshot_every_n_requests|`-1`|Determines how frequently snapshots are taken. See the "Snapshots Sampling" above for more details.
409
+ snapshots_limit|`1000`|Determines how many snapshots Mini Profiler is allowed to keep.
410
+ 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.
411
+ 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.
412
+ 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.
413
+ 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.
414
+ snapshots_transport_gzip_requests|`false`|Make the snapshots transporter gzip the requests it makes to `snapshots_transport_destination_url`.
415
+
416
+ ### Using MiniProfiler with `Rack::Deflate` middleware
417
+
418
+ If you are using `Rack::Deflate` with Rails and `rack-mini-profiler` in its default configuration,
419
+ `Rack::MiniProfiler` will be injected (as always) at position 0 in the middleware stack,
420
+ which means it will run after `Rack::Deflate` on response processing. To prevent attempting to inject
421
+ HTML in already compressed response body MiniProfiler will suppress compression by setting
422
+ `identity` encoding in `Accept-Encoding` request header.
352
423
 
353
424
  ## Special query strings
354
425
 
@@ -385,6 +456,16 @@ if JSON.const_defined?(:Pure)
385
456
  end
386
457
  ```
387
458
 
459
+ ## Development
460
+
461
+ If you want to contribute to this project, that's great, thank you! You can run the following rake task:
462
+
463
+ ```
464
+ $ bundle exec rake client_dev
465
+ ```
466
+
467
+ 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.
468
+
388
469
  ## Running the Specs
389
470
 
390
471
  ```