rack-mini-profiler 2.3.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +95 -78
- data/lib/generators/rack_mini_profiler/USAGE +9 -0
- data/lib/generators/rack_mini_profiler/install_generator.rb +13 -0
- data/lib/generators/{rack_profiler/templates/rack_profiler.rb → rack_mini_profiler/templates/rack_mini_profiler.rb} +1 -1
- data/lib/generators/rack_profiler/install_generator.rb +6 -3
- data/lib/mini_profiler/client_settings.rb +2 -2
- data/lib/mini_profiler/config.rb +9 -5
- data/lib/mini_profiler/storage/abstract_store.rb +30 -57
- data/lib/mini_profiler/storage/file_store.rb +4 -0
- data/lib/mini_profiler/storage/memcache_store.rb +11 -7
- data/lib/mini_profiler/storage/memory_store.rb +56 -12
- data/lib/mini_profiler/storage/redis_store.rb +151 -62
- data/lib/mini_profiler/storage.rb +7 -0
- data/lib/mini_profiler/timer_struct/base.rb +2 -0
- data/lib/mini_profiler/timer_struct/sql.rb +2 -0
- data/lib/mini_profiler/timer_struct.rb +8 -0
- data/lib/mini_profiler/version.rb +1 -1
- data/lib/{mini_profiler/profiler.rb → mini_profiler.rb} +103 -69
- data/lib/patches/net_patches.rb +18 -17
- data/lib/rack-mini-profiler.rb +1 -24
- data/rack-mini-profiler.gemspec +2 -2
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7544df4d22f5f615b146fb0d63f18098ffd702ac9dec966d8040187f2e8302b9
|
4
|
+
data.tar.gz: 7c39c41a96205c8c7fbd69765ab5f1e0a3a3a37950055fc58d0f27f4a0591e0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e3f5f9a51fc5395dda4a7e793903f998513499d850aeb291fe036171a78617d11c3d8cd6fef57d1144359aa4992055ad54ba878075896c3d0280c426a84e3be
|
7
|
+
data.tar.gz: c4e353c8442db93f29d11d04e2724e6c3f8dacaaf082210acbbb7d47655ffc3a6b5297079750e305fe9f1cd3e7efb1d806aef0ec68bbc1a8e40a0f958de0ec52
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.1.0 - 2023-04-11
|
4
|
+
|
5
|
+
- [FEATURE] The query parameter that RMP uses (by default, pp) is now configurable [#553](https://github.com/MiniProfiler/rack-mini-profiler/pull/553)
|
6
|
+
- [FEATURE] You can now opt-out of the Net::HTTP patch by using RACK_MINI_PROFILER_PATCH_NET_HTTP="false"
|
7
|
+
- [FIX] Error responses now include header values from the app, and stackprof not installed message now has correct content [#547](https://github.com/MiniProfiler/rack-mini-profiler/pull/547)
|
8
|
+
- [FIX] RMP pages now have more valid HTML, with title elements [#562](https://github.com/MiniProfiler/rack-mini-profiler/pull/562)
|
9
|
+
- [BREAKING CHANGE] Ruby 2.4 and Ruby 2.5 are no longer supported.
|
10
|
+
- [FIX] Now works with apps that don't otherwise require erb [#531](https://github.com/MiniProfiler/rack-mini-profiler/pull/531)
|
11
|
+
- [DOCS] Added Heroku Redis instructions
|
12
|
+
- [DEPRECATION] We are changing the name of the generators to `rack_mini_profiler`, e.g. `rack_mini_profiler:install` [#550](https://github.com/MiniProfiler/rack-mini-profiler/pull/550)
|
13
|
+
|
14
|
+
## 3.0.0 - 2022-02-24
|
15
|
+
|
16
|
+
- PERF: Improve snapshots page performance (#518) (introduces breaking changes to the API of `AbstractStore`, `MemoryStore` and `RedisStore`, and removes the `snapshots_limit` config option.)
|
17
|
+
|
18
|
+
## 2.3.4 - 2022-02-23
|
19
|
+
|
20
|
+
- [FEATURE] Add cookie path support for subfolder sites
|
21
|
+
- [FIX] Remove deprecated uses of Redis#pipelined
|
22
|
+
|
3
23
|
## 2.3.3 - 2021-08-30
|
4
24
|
|
5
25
|
- [FEATURE] Introduce `pp=flamegraph_mode`
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# rack-mini-profiler
|
2
2
|
|
3
|
-
Middleware that displays speed badge for every
|
3
|
+
Middleware that displays speed badge for every HTML page, along with (optional) flamegraphs and memory profiling. Designed to work both in production and in development.
|
4
|
+
|
5
|
+
![Screenshot 2023-04-05 at 3 13 52 PM](https://user-images.githubusercontent.com/845662/229996538-0f2d9c48-23d9-4d53-a1de-8b4c84c87fbd.png)
|
4
6
|
|
5
7
|
#### Features
|
6
8
|
|
@@ -27,7 +29,7 @@ If you feel like taking on any of this start an issue and update us on your prog
|
|
27
29
|
|
28
30
|
## Installation
|
29
31
|
|
30
|
-
Install/add to Gemfile in Ruby 2.
|
32
|
+
Install/add to Gemfile in Ruby 2.6+
|
31
33
|
|
32
34
|
```ruby
|
33
35
|
gem 'rack-mini-profiler'
|
@@ -101,7 +103,7 @@ be loaded outright, and an attempt to re-initialize it manually will raise an ex
|
|
101
103
|
Then run the generator which will set up rack-mini-profiler in development:
|
102
104
|
|
103
105
|
```bash
|
104
|
-
bundle exec rails g
|
106
|
+
bundle exec rails g rack_mini_profiler:install
|
105
107
|
```
|
106
108
|
|
107
109
|
#### Rack Builder
|
@@ -164,16 +166,21 @@ export RACK_MINI_PROFILER_PATCH="false"
|
|
164
166
|
# initializers/rack_profiler.rb: SqlPatches.patch %w(mongo)
|
165
167
|
```
|
166
168
|
|
169
|
+
#### Patching Net::HTTP
|
170
|
+
|
171
|
+
Other than databases, `rack-mini-profiler` applies a patch to `Net::HTTP`. You may want to disable this patch:
|
172
|
+
|
173
|
+
```bash
|
174
|
+
export RACK_MINI_PROFILER_PATCH_NET_HTTP="false"
|
175
|
+
```
|
176
|
+
|
167
177
|
### Flamegraphs
|
168
178
|
|
169
|
-
To generate [flamegraphs](http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler)
|
179
|
+
To generate [flamegraphs](http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler), add the [**stackprof**](https://rubygems.org/gems/stackprof) gem to your Gemfile.
|
170
180
|
|
171
|
-
|
172
|
-
* visit a page in your app with `?pp=flamegraph`
|
181
|
+
Then, to view the flamegraph as a direct HTML response from your request, just visit any page in your app with `?pp=flamegraph` appended to the URL.
|
173
182
|
|
174
|
-
|
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.
|
183
|
+
Conversely, if you want your regular response instead (which is specially useful for JSON and/or XHR requests), just append the `?pp=async-flamegraph` parameter to your request/fetch URL; the request will then return as normal, and the flamegraph data will be stored for later *async* viewing, both for this request and for all subsequent requests made by this page (based on the `REFERER` header). For viewing these async flamegraphs, use the 'flamegraph' link that will appear inside the MiniProfiler UI for these requests.
|
177
184
|
|
178
185
|
Note: Mini Profiler will not record SQL timings for a request if it asks for a flamegraph. The rationale behind this is to keep
|
179
186
|
Mini Profiler's methods that are responsible for generating the timings data out of the flamegraph.
|
@@ -210,7 +217,7 @@ After enabling snapshots sampling, you can see the snapshots that have been coll
|
|
210
217
|
|
211
218
|
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.
|
212
219
|
|
213
|
-
Mini Profiler will keep a maximum of
|
220
|
+
Mini Profiler will keep a maximum of 50 snapshot groups and a maximum of 15 snapshots per group making the default maximum number of snapshots in the system 750. The default group and per group limits can be changed via the `max_snapshot_groups` and `max_snapshots_per_group` configuration options, see the configurations table below.
|
214
221
|
|
215
222
|
#### Snapshots Transporter
|
216
223
|
|
@@ -350,19 +357,41 @@ Single page applications built using Ember, Angular or other frameworks need som
|
|
350
357
|
On route transition always call:
|
351
358
|
|
352
359
|
```
|
353
|
-
window.MiniProfiler
|
360
|
+
if (window.MiniProfiler !== undefined) {
|
361
|
+
window.MiniProfiler.pageTransition();
|
362
|
+
}
|
354
363
|
```
|
355
364
|
|
356
365
|
This method will remove profiling information that was related to previous page and clear aggregate statistics.
|
357
366
|
|
358
367
|
#### MiniProfiler's speed badge on pages that are not generated via Rails
|
359
|
-
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)):
|
368
|
+
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) and [credit for the script tag](https://github.com/MiniProfiler/rack-mini-profiler/issues/479#issue-782488320) to [@ivanyv](https://github.com/ivanyv)):
|
360
369
|
|
361
370
|
```html
|
362
|
-
<script
|
363
|
-
|
364
|
-
|
365
|
-
|
371
|
+
<script type="text/javascript" id="mini-profiler"
|
372
|
+
src="/mini-profiler-resources/includes.js?v=12b4b45a3c42e6e15503d7a03810ff33"
|
373
|
+
data-css-url="/mini-profiler-resources/includes.css?v=12b4b45a3c42e6e15503d7a03810ff33"
|
374
|
+
data-version="12b4b45a3c42e6e15503d7a03810ff33"
|
375
|
+
data-path="/mini-profiler-resources/"
|
376
|
+
data-horizontal-position="left"
|
377
|
+
data-vertical-position="top"
|
378
|
+
data-ids=""
|
379
|
+
data-trivial="false"
|
380
|
+
data-children="false"
|
381
|
+
data-max-traces="20"
|
382
|
+
data-controls="false"
|
383
|
+
data-total-sql-count="false"
|
384
|
+
data-authorized="true"
|
385
|
+
data-toggle-shortcut="alt+p"
|
386
|
+
data-start-hidden="false"
|
387
|
+
data-collapse-results="true"
|
388
|
+
data-html-container="body"
|
389
|
+
data-hidden-custom-fields></script>
|
390
|
+
```
|
391
|
+
|
392
|
+
See an [example of how to do this in a React useEffect](https://gist.github.com/katelovescode/01cfc2b962c165193b160fd10af6c4d5).
|
393
|
+
|
394
|
+
_Note:_ The GUID (`data-version` and the `?v=` parameter on the `src` and `data-css-url`) 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.
|
366
395
|
|
367
396
|
#### Using MiniProfiler's built in route for apps without HTML responses
|
368
397
|
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.
|
@@ -387,37 +416,40 @@ Rack::MiniProfiler.config.start_hidden = true
|
|
387
416
|
```
|
388
417
|
The available configuration options are:
|
389
418
|
|
390
|
-
Option|Default|Description
|
391
|
-
|
392
|
-
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.
|
393
|
-
position
|
394
|
-
skip_paths
|
395
|
-
skip_schema_queries|Rails dev: `true`<br>Othwerwise: `false
|
396
|
-
auto_inject
|
397
|
-
backtrace_ignores
|
398
|
-
backtrace_includes|Rails: `[/^\/?(app\|config\|lib\|test)/]`<br>Rack: `[]
|
399
|
-
backtrace_remove|rails: `Rails.root`<br>Rack: `nil
|
400
|
-
toggle_shortcut|Alt+P|Keyboard shortcut to toggle the mini_profiler's visibility. See [jquery.hotkeys](https://github.com/jeresig/jquery.hotkeys).
|
401
|
-
start_hidden
|
402
|
-
backtrace_threshold_ms
|
403
|
-
flamegraph_sample_rate
|
404
|
-
flamegraph_mode
|
405
|
-
base_url_path
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
419
|
+
Option | Default | Description
|
420
|
+
------------------------------------|---------------------------------------------------------|------------------------
|
421
|
+
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.
|
422
|
+
position | `'top-left'` | Display mini_profiler on `'top-right'`, `'top-left'`, `'bottom-right'` or `'bottom-left'`.
|
423
|
+
skip_paths | `[]` | An array of paths that skip profiling. Both `String` and `Regexp` are acceptable in the array.
|
424
|
+
skip_schema_queries | Rails dev: `true`<br>Othwerwise: `false` | `true` to skip schema queries.
|
425
|
+
auto_inject | `true` | `true` to inject the miniprofiler script in the page.
|
426
|
+
backtrace_ignores | `[]` | Regexes of lines to be removed from backtraces.
|
427
|
+
backtrace_includes | Rails: `[/^\/?(app\|config\|lib\|test)/]`<br>Rack: `[]` | Regexes of lines to keep in backtraces.
|
428
|
+
backtrace_remove | rails: `Rails.root`<br>Rack: `nil` | A string or regex to remove part of each line in the backtrace.
|
429
|
+
toggle_shortcut | Alt+P | Keyboard shortcut to toggle the mini_profiler's visibility. See [jquery.hotkeys](https://github.com/jeresig/jquery.hotkeys).
|
430
|
+
start_hidden | `false` | `false` to make mini_profiler visible on page load.
|
431
|
+
backtrace_threshold_ms | `0` | Minimum SQL query elapsed time before a backtrace is recorded.
|
432
|
+
flamegraph_sample_rate | `0.5` | How often to capture stack traces for flamegraphs in milliseconds.
|
433
|
+
flamegraph_mode | `:wall` | The [StackProf mode](https://github.com/tmm1/stackprof#all-options) to pass to `StackProf.run`.
|
434
|
+
base_url_path | `'/mini-profiler-resources/'` | Path for assets; added as a prefix when naming assets and sought when responding to requests.
|
435
|
+
cookie_path | `'/'` | Set-Cookie header path for profile cookie
|
436
|
+
collapse_results | `true` | If multiple timing results exist in a single page, collapse them till clicked.
|
437
|
+
max_traces_to_show | 20 | Maximum number of mini profiler timing blocks to show on one page
|
438
|
+
html_container | `body` | The HTML container (as a jQuery selector) to inject the mini_profiler UI into
|
439
|
+
show_total_sql_count | `false` | Displays the total number of SQL executions.
|
440
|
+
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. Defaults to `true` in development.
|
441
|
+
assets_url | `nil` | See the "Register MiniProfiler's assets in the Rails assets pipeline" section above.
|
442
|
+
snapshot_every_n_requests | `-1` | Determines how frequently snapshots are taken. See the "Snapshots Sampling" above for more details.
|
443
|
+
max_snapshot_groups | `50` | Determines how many snapshot groups Mini Profiler is allowed to keep.
|
444
|
+
max_snapshots_per_group | `15` | Determines how many snapshots per group Mini Profiler is allowed to keep.
|
445
|
+
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.
|
446
|
+
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.
|
447
|
+
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.
|
448
|
+
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.
|
449
|
+
snapshots_transport_gzip_requests | `false` | Make the snapshots transporter gzip the requests it makes to `snapshots_transport_destination_url`.
|
450
|
+
content_security_policy_nonce | Rails: Current nonce<br>Rack: nil | Set the content security policy nonce to use when inserting MiniProfiler's script block.
|
451
|
+
enable_hotwire_turbo_drive_support | `false` | Enable support for Hotwire TurboDrive page transitions.
|
452
|
+
profile_parameter | `'pp'` | The query parameter used to interact with this gem.
|
421
453
|
|
422
454
|
### Using MiniProfiler with `Rack::Deflate` middleware
|
423
455
|
|
@@ -427,41 +459,26 @@ which means it will run after `Rack::Deflate` on response processing. To prevent
|
|
427
459
|
HTML in already compressed response body MiniProfiler will suppress compression by setting
|
428
460
|
`identity` encoding in `Accept-Encoding` request header.
|
429
461
|
|
430
|
-
|
431
|
-
|
432
|
-
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.
|
433
|
-
|
462
|
+
### Using MiniProfiler with Heroku Redis
|
434
463
|
|
435
|
-
|
436
|
-
|
437
|
-
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.
|
438
|
-
|
439
|
-
Add the following code to your environment.rb (or just in a specific environment such as development.rb) for initialization and configuration of MiniProfiler.
|
464
|
+
If you are using Heroku Redis, you may need to add the following to your `config/initializers/mini_profiler.rb`, in order to get Mini Profiler to work:
|
440
465
|
|
441
466
|
```ruby
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
tmp = Rails.root.to_s + "/tmp/miniprofiler"
|
449
|
-
FileUtils.mkdir_p(tmp) unless File.exist?(tmp)
|
450
|
-
c.storage_options = {:path => tmp}
|
451
|
-
c.storage = ::Rack::MiniProfiler::FileStore
|
452
|
-
config.middleware.use(::Rack::MiniProfiler)
|
453
|
-
::Rack::MiniProfiler.profile_method(ActionController::Base, :process) {|action| "Executing action: #{action}"}
|
454
|
-
::Rack::MiniProfiler.profile_method(ActionView::Template, :render) {|x,y| "Rendering: #{path_without_format_and_extension}"}
|
455
|
-
|
456
|
-
# monkey patch away an activesupport and json_pure incompatability
|
457
|
-
# http://pivotallabs.com/users/alex/blog/articles/1332-monkey-patch-of-the-day-activesupport-vs-json-pure-vs-ruby-1-8
|
458
|
-
if JSON.const_defined?(:Pure)
|
459
|
-
class JSON::Pure::Generator::State
|
460
|
-
include ActiveSupport::CoreExtensions::Hash::Except
|
461
|
-
end
|
467
|
+
if Rails.env.production?
|
468
|
+
Rack::MiniProfiler.config.storage_options = {
|
469
|
+
url: ENV["REDIS_URL"],
|
470
|
+
ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
|
471
|
+
}
|
472
|
+
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::RedisStore
|
462
473
|
end
|
463
474
|
```
|
464
475
|
|
476
|
+
The above code snippet is [Heroku's officially suggested workaround](https://help.heroku.com/HC0F8CUS/redis-connection-issues).
|
477
|
+
|
478
|
+
## Special query strings
|
479
|
+
|
480
|
+
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.
|
481
|
+
|
465
482
|
## Development
|
466
483
|
|
467
484
|
If you want to contribute to this project, that's great, thank you! You can run the following rake task:
|
@@ -480,8 +497,8 @@ Make sure to prepend `bundle exec` before any Rake tasks you run.
|
|
480
497
|
You need Memcached and Redis services running for the specs.
|
481
498
|
|
482
499
|
```
|
483
|
-
$ rake build
|
484
|
-
$ rake spec
|
500
|
+
$ bundle exec rake build
|
501
|
+
$ bundle exec rake spec
|
485
502
|
```
|
486
503
|
|
487
504
|
## Licence
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Description:
|
2
|
+
Generates an initializer for rack-mini-profiler. Use an initializer when manually
|
3
|
+
requiring rack-mini-profiler in your application (using require: false in your Gemfile).
|
4
|
+
|
5
|
+
Example:
|
6
|
+
`bin/rails generate rack_mini_profiler:install`
|
7
|
+
|
8
|
+
This generates a an initializer that requires and initializes
|
9
|
+
rack-mini-profiler in development mode.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RackMiniProfiler
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
|
8
|
+
def create_initializer_file
|
9
|
+
copy_file "rack_mini_profiler.rb", "config/initializers/rack_mini_profiler.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "generators/rack_mini_profiler/install_generator"
|
4
|
+
|
3
5
|
module RackProfiler
|
4
6
|
module Generators
|
5
|
-
class InstallGenerator < ::
|
6
|
-
source_root File.expand_path("templates", __dir__)
|
7
|
+
class InstallGenerator < RackMiniProfiler::Generators::InstallGenerator
|
8
|
+
source_root File.expand_path("../rack_mini_profiler/templates", __dir__)
|
7
9
|
|
8
10
|
def create_initializer_file
|
9
|
-
|
11
|
+
warn("bin/rails generate rack_profiler:install is deprecated. Please use rack_mini_profiler:install instead.")
|
12
|
+
super
|
10
13
|
end
|
11
14
|
end
|
12
15
|
end
|
@@ -74,7 +74,7 @@ module Rack
|
|
74
74
|
settings["bt"] = @backtrace_level if @backtrace_level
|
75
75
|
settings["a"] = @allowed_tokens.join("|") if @allowed_tokens && MiniProfiler.request_authorized?
|
76
76
|
settings_string = settings.map { |k, v| "#{k}=#{v}" }.join(",")
|
77
|
-
cookie = { value: settings_string, path:
|
77
|
+
cookie = { value: settings_string, path: MiniProfiler.config.cookie_path, httponly: true }
|
78
78
|
cookie[:secure] = true if @request.ssl?
|
79
79
|
cookie[:same_site] = 'Lax'
|
80
80
|
Rack::Utils.set_cookie_header!(headers, COOKIE_NAME, cookie)
|
@@ -83,7 +83,7 @@ module Rack
|
|
83
83
|
|
84
84
|
def discard_cookie!(headers)
|
85
85
|
if @cookie
|
86
|
-
Rack::Utils.delete_cookie_header!(headers, COOKIE_NAME, path:
|
86
|
+
Rack::Utils.delete_cookie_header!(headers, COOKIE_NAME, path: MiniProfiler.config.cookie_path)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
data/lib/mini_profiler/config.rb
CHANGED
@@ -17,6 +17,7 @@ module Rack
|
|
17
17
|
new.instance_eval {
|
18
18
|
@auto_inject = true # automatically inject on every html page
|
19
19
|
@base_url_path = "/mini-profiler-resources/".dup
|
20
|
+
@cookie_path = "/".dup
|
20
21
|
@disable_caching = true
|
21
22
|
# called prior to rack chain, to ensure we are allowed to profile
|
22
23
|
@pre_authorize_cb = lambda { |env| true }
|
@@ -39,7 +40,8 @@ module Rack
|
|
39
40
|
@skip_sql_param_names = /password/ # skips parameters with the name password by default
|
40
41
|
@enable_advanced_debugging_tools = false
|
41
42
|
@snapshot_every_n_requests = -1
|
42
|
-
@
|
43
|
+
@max_snapshot_groups = 50
|
44
|
+
@max_snapshots_per_group = 15
|
43
45
|
|
44
46
|
# ui parameters
|
45
47
|
@autorized = true
|
@@ -60,19 +62,21 @@ module Rack
|
|
60
62
|
@snapshots_transport_gzip_requests = false
|
61
63
|
@enable_hotwire_turbo_drive_support = false
|
62
64
|
|
65
|
+
@profile_parameter = "pp"
|
66
|
+
|
63
67
|
self
|
64
68
|
}
|
65
69
|
end
|
66
70
|
|
67
71
|
attr_accessor :authorization_mode, :auto_inject, :backtrace_ignores,
|
68
72
|
:backtrace_includes, :backtrace_remove, :backtrace_threshold_ms,
|
69
|
-
:base_url_path, :disable_caching, :enabled,
|
73
|
+
:base_url_path, :cookie_path, :disable_caching, :enabled,
|
70
74
|
:flamegraph_sample_rate, :logger, :pre_authorize_cb, :skip_paths,
|
71
75
|
:skip_schema_queries, :storage, :storage_failure, :storage_instance,
|
72
76
|
:storage_options, :user_provider, :enable_advanced_debugging_tools,
|
73
77
|
:skip_sql_param_names, :suppress_encoding, :max_sql_param_length,
|
74
78
|
:content_security_policy_nonce, :enable_hotwire_turbo_drive_support,
|
75
|
-
:flamegraph_mode
|
79
|
+
:flamegraph_mode, :profile_parameter
|
76
80
|
|
77
81
|
# ui accessors
|
78
82
|
attr_accessor :collapse_results, :max_traces_to_show, :position,
|
@@ -80,10 +84,10 @@ module Rack
|
|
80
84
|
:start_hidden, :toggle_shortcut, :html_container
|
81
85
|
|
82
86
|
# snapshot related config
|
83
|
-
attr_accessor :snapshot_every_n_requests, :
|
87
|
+
attr_accessor :snapshot_every_n_requests, :max_snapshots_per_group,
|
84
88
|
:snapshot_hidden_custom_fields, :snapshots_transport_destination_url,
|
85
89
|
:snapshots_transport_auth_key, :snapshots_redact_sql_queries,
|
86
|
-
:snapshots_transport_gzip_requests
|
90
|
+
:snapshots_transport_gzip_requests, :max_snapshot_groups
|
87
91
|
|
88
92
|
# Deprecated options
|
89
93
|
attr_accessor :use_existing_jquery
|
@@ -45,80 +45,53 @@ module Rack
|
|
45
45
|
raise NotImplementedError.new("should_take_snapshot? is not implemented")
|
46
46
|
end
|
47
47
|
|
48
|
-
def push_snapshot(page_struct, config)
|
48
|
+
def push_snapshot(page_struct, group_name, config)
|
49
49
|
raise NotImplementedError.new("push_snapshot is not implemented")
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
# returns a hash where the keys are group names and the values
|
53
|
+
# are hashes that contain 3 keys:
|
54
|
+
# 1. `:worst_score` => the duration of the worst/slowest snapshot in the group (float)
|
55
|
+
# 2. `:best_score` => the duration of the best/fastest snapshot in the group (float)
|
56
|
+
# 3. `:snapshots_count` => the number of snapshots in the group (integer)
|
57
|
+
def fetch_snapshots_overview
|
58
|
+
raise NotImplementedError.new("fetch_snapshots_overview is not implemented")
|
54
59
|
end
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
groups[group_name][:best_score] = snapshot.duration_ms
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
groups = groups.to_a
|
61
|
+
# @param group_name [String]
|
62
|
+
# @return [Array<Rack::MiniProfiler::TimerStruct::Page>] list of snapshots of the group. Blank array if the group doesn't exist.
|
63
|
+
def fetch_snapshots_group(group_name)
|
64
|
+
raise NotImplementedError.new("fetch_snapshots_group is not implemented")
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_snapshot(id, group_name)
|
68
|
+
raise NotImplementedError.new("load_snapshot is not implemented")
|
69
|
+
end
|
70
|
+
|
71
|
+
def snapshots_overview
|
72
|
+
groups = fetch_snapshots_overview.to_a
|
73
73
|
groups.sort_by! { |name, hash| hash[:worst_score] }
|
74
74
|
groups.reverse!
|
75
75
|
groups.map! { |name, hash| hash.merge(name: name) }
|
76
76
|
groups
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
79
|
+
def snapshots_group(group_name)
|
80
|
+
snapshots = fetch_snapshots_group(group_name)
|
80
81
|
data = []
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
timestamp: snapshot[:started_at],
|
90
|
-
custom_fields: snapshot[:custom_fields]
|
91
|
-
}
|
92
|
-
end
|
93
|
-
end
|
82
|
+
snapshots.each do |snapshot|
|
83
|
+
data << {
|
84
|
+
id: snapshot[:id],
|
85
|
+
duration: snapshot.duration_ms,
|
86
|
+
sql_count: snapshot[:sql_count],
|
87
|
+
timestamp: snapshot[:started_at],
|
88
|
+
custom_fields: snapshot[:custom_fields]
|
89
|
+
}
|
94
90
|
end
|
95
91
|
data.sort_by! { |s| s[:duration] }
|
96
92
|
data.reverse!
|
97
93
|
data
|
98
94
|
end
|
99
|
-
|
100
|
-
def load_snapshot(id)
|
101
|
-
raise NotImplementedError.new("load_snapshot is not implemented")
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def default_snapshot_grouping(snapshot)
|
107
|
-
group_name = rails_route_from_path(snapshot[:request_path], snapshot[:request_method])
|
108
|
-
group_name ||= snapshot[:request_path]
|
109
|
-
"#{snapshot[:request_method]} #{group_name}"
|
110
|
-
end
|
111
|
-
|
112
|
-
def rails_route_from_path(path, method)
|
113
|
-
if defined?(Rails) && defined?(ActionController::RoutingError)
|
114
|
-
hash = Rails.application.routes.recognize_path(path, method: method)
|
115
|
-
if hash && hash[:controller] && hash[:action]
|
116
|
-
"#{hash[:controller]}##{hash[:action]}"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
rescue ActionController::RoutingError
|
120
|
-
nil
|
121
|
-
end
|
122
95
|
end
|
123
96
|
end
|
124
97
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'securerandom'
|
4
|
+
|
3
5
|
module Rack
|
4
6
|
class MiniProfiler
|
5
7
|
class FileStore < AbstractStore
|
@@ -17,7 +19,9 @@ module Rack
|
|
17
19
|
def [](key)
|
18
20
|
begin
|
19
21
|
data = ::File.open(path(key), "rb") { |f| f.read }
|
22
|
+
# rubocop:disable Security/MarshalLoad
|
20
23
|
Marshal.load data
|
24
|
+
# rubocop:enable Security/MarshalLoad
|
21
25
|
rescue
|
22
26
|
nil
|
23
27
|
end
|
@@ -24,7 +24,9 @@ module Rack
|
|
24
24
|
|
25
25
|
def load(id)
|
26
26
|
raw = @client.get("#{@prefix}#{id}")
|
27
|
-
|
27
|
+
# rubocop:disable Security/MarshalLoad
|
28
|
+
Marshal.load(raw) if raw
|
29
|
+
# rubocop:enable Security/MarshalLoad
|
28
30
|
end
|
29
31
|
|
30
32
|
def set_unviewed(user, id)
|
@@ -65,14 +67,16 @@ module Rack
|
|
65
67
|
key1, key2, cycle_at = nil
|
66
68
|
|
67
69
|
if token_info
|
68
|
-
|
70
|
+
# rubocop:disable Security/MarshalLoad
|
71
|
+
key1, key2, cycle_at = Marshal.load(token_info)
|
72
|
+
# rubocop:enable Security/MarshalLoad
|
69
73
|
|
70
|
-
|
71
|
-
|
74
|
+
key1 = nil unless key1 && key1.length == 32
|
75
|
+
key2 = nil unless key2 && key2.length == 32
|
72
76
|
|
73
|
-
|
74
|
-
|
75
|
-
|
77
|
+
if key1 && cycle_at && (cycle_at > Process.clock_gettime(Process::CLOCK_MONOTONIC))
|
78
|
+
return [key1, key2].compact
|
79
|
+
end
|
76
80
|
end
|
77
81
|
|
78
82
|
timeout = Rack::MiniProfiler::AbstractStore::MAX_TOKEN_AGE
|