rack-mini-profiler 2.3.3 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +33 -13
- data/lib/mini_profiler/client_settings.rb +2 -2
- data/lib/mini_profiler/config.rb +2 -1
- data/lib/mini_profiler/profiler.rb +1 -1
- data/lib/mini_profiler/storage/file_store.rb +2 -0
- data/lib/mini_profiler/storage/memcache_store.rb +11 -7
- data/lib/mini_profiler/storage/redis_store.rb +18 -12
- data/lib/mini_profiler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6021effb717c193c4c70b3ac7a3550fd99c9abfd19432ac0ab9db63f62b11321
|
4
|
+
data.tar.gz: 8bce19855d2f6d908339e3108201282c519b4d8ad99b8e7e90dad9d3f718c929
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c4354c194a6fa6018c57162e24e1cee85de7f296e45cd6182360b39abeb803b29a14674e2dfe93b3ba5d9bcb192814de8d091ad6b7db20d71af95e2cddcf4eb
|
7
|
+
data.tar.gz: e3c7f4da5fd5c79bfdb4c3582b50a38346d38784bfd92c6e7ce3fa41713104c74b6ad5622084d42624011ef850533c403002664f44ad7f6e1b1ac16a245c633b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -166,14 +166,11 @@ export RACK_MINI_PROFILER_PATCH="false"
|
|
166
166
|
|
167
167
|
### Flamegraphs
|
168
168
|
|
169
|
-
To generate [flamegraphs](http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler)
|
169
|
+
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
170
|
|
171
|
-
|
172
|
-
* visit a page in your app with `?pp=flamegraph`
|
171
|
+
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
172
|
|
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.
|
173
|
+
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
174
|
|
178
175
|
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
176
|
Mini Profiler's methods that are responsible for generating the timings data out of the flamegraph.
|
@@ -350,19 +347,41 @@ Single page applications built using Ember, Angular or other frameworks need som
|
|
350
347
|
On route transition always call:
|
351
348
|
|
352
349
|
```
|
353
|
-
window.MiniProfiler
|
350
|
+
if (window.MiniProfiler !== undefined) {
|
351
|
+
window.MiniProfiler.pageTransition();
|
352
|
+
}
|
354
353
|
```
|
355
354
|
|
356
355
|
This method will remove profiling information that was related to previous page and clear aggregate statistics.
|
357
356
|
|
358
357
|
#### 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)):
|
358
|
+
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
359
|
|
361
360
|
```html
|
362
|
-
<script
|
363
|
-
|
364
|
-
|
365
|
-
|
361
|
+
<script type="text/javascript" id="mini-profiler"
|
362
|
+
src="/mini-profiler-resources/includes.js?v=12b4b45a3c42e6e15503d7a03810ff33"
|
363
|
+
data-css-url="/mini-profiler-resources/includes.css?v=12b4b45a3c42e6e15503d7a03810ff33"
|
364
|
+
data-version="12b4b45a3c42e6e15503d7a03810ff33"
|
365
|
+
data-path="/mini-profiler-resources/"
|
366
|
+
data-horizontal-position="left"
|
367
|
+
data-vertical-position="top"
|
368
|
+
data-ids=""
|
369
|
+
data-trivial="false"
|
370
|
+
data-children="false"
|
371
|
+
data-max-traces="20"
|
372
|
+
data-controls="false"
|
373
|
+
data-total-sql-count="false"
|
374
|
+
data-authorized="true"
|
375
|
+
data-toggle-shortcut="alt+p"
|
376
|
+
data-start-hidden="false"
|
377
|
+
data-collapse-results="true"
|
378
|
+
data-html-container="body"
|
379
|
+
data-hidden-custom-fields></script>
|
380
|
+
```
|
381
|
+
|
382
|
+
See an [example of how to do this in a React useEffect](https://gist.github.com/katelovescode/01cfc2b962c165193b160fd10af6c4d5).
|
383
|
+
|
384
|
+
_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
385
|
|
367
386
|
#### Using MiniProfiler's built in route for apps without HTML responses
|
368
387
|
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.
|
@@ -403,11 +422,12 @@ backtrace_threshold_ms|`0`|Minimum SQL query elapsed time before a backtrace is
|
|
403
422
|
flamegraph_sample_rate|`0.5`|How often to capture stack traces for flamegraphs in milliseconds.
|
404
423
|
flamegraph_mode|`:wall`|The [StackProf mode](https://github.com/tmm1/stackprof#all-options) to pass to `StackProf.run`.
|
405
424
|
base_url_path|`'/mini-profiler-resources/'`|Path for assets; added as a prefix when naming assets and sought when responding to requests.
|
425
|
+
cookie_path|`'/'`|Set-Cookie header path for profile cookie
|
406
426
|
collapse_results|`true`|If multiple timing results exist in a single page, collapse them till clicked.
|
407
427
|
max_traces_to_show|20|Maximum number of mini profiler timing blocks to show on one page
|
408
428
|
html_container|`body`|The HTML container (as a jQuery selector) to inject the mini_profiler UI into
|
409
429
|
show_total_sql_count|`false`|Displays the total number of SQL executions.
|
410
|
-
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.
|
430
|
+
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.
|
411
431
|
assets_url|`nil`|See the "Register MiniProfiler's assets in the Rails assets pipeline" section above.
|
412
432
|
snapshot_every_n_requests|`-1`|Determines how frequently snapshots are taken. See the "Snapshots Sampling" above for more details.
|
413
433
|
snapshots_limit|`1000`|Determines how many snapshots Mini Profiler is allowed to keep.
|
@@ -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 }
|
@@ -66,7 +67,7 @@ module Rack
|
|
66
67
|
|
67
68
|
attr_accessor :authorization_mode, :auto_inject, :backtrace_ignores,
|
68
69
|
:backtrace_includes, :backtrace_remove, :backtrace_threshold_ms,
|
69
|
-
:base_url_path, :disable_caching, :enabled,
|
70
|
+
:base_url_path, :cookie_path, :disable_caching, :enabled,
|
70
71
|
:flamegraph_sample_rate, :logger, :pre_authorize_cb, :skip_paths,
|
71
72
|
:skip_schema_queries, :storage, :storage_failure, :storage_instance,
|
72
73
|
:storage_options, :user_provider, :enable_advanced_debugging_tools,
|
@@ -773,7 +773,7 @@ This is the help menu of the <a href='#{Rack::MiniProfiler::SOURCE_CODE_URI}'>ra
|
|
773
773
|
end
|
774
774
|
|
775
775
|
# TODO : cache this snippet
|
776
|
-
script =
|
776
|
+
script = ::File.read(::File.expand_path('../html/profile_handler.js', ::File.dirname(__FILE__)))
|
777
777
|
# replace the variables
|
778
778
|
settings.each do |k, v|
|
779
779
|
regex = Regexp.new("\\{#{k.to_s}\\}")
|
@@ -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
|
@@ -25,7 +25,9 @@ module Rack
|
|
25
25
|
key = prefixed_id(id)
|
26
26
|
raw = redis.get key
|
27
27
|
begin
|
28
|
-
|
28
|
+
# rubocop:disable Security/MarshalLoad
|
29
|
+
Marshal.load(raw) if raw
|
30
|
+
# rubocop:enable Security/MarshalLoad
|
29
31
|
rescue
|
30
32
|
# bad format, junk old data
|
31
33
|
redis.del key
|
@@ -177,7 +179,9 @@ unviewed_ids: #{get_unviewed_ids(user)}
|
|
177
179
|
batch = redis.mapped_hmget(hash_key, *ids).to_a
|
178
180
|
batch.map! do |id, bytes|
|
179
181
|
begin
|
182
|
+
# rubocop:disable Security/MarshalLoad
|
180
183
|
Marshal.load(bytes)
|
184
|
+
# rubocop:enable Security/MarshalLoad
|
181
185
|
rescue
|
182
186
|
corrupt_snapshots << id
|
183
187
|
nil
|
@@ -189,9 +193,9 @@ unviewed_ids: #{get_unviewed_ids(user)}
|
|
189
193
|
iteration += 1
|
190
194
|
end
|
191
195
|
if corrupt_snapshots.size > 0
|
192
|
-
redis.pipelined do
|
193
|
-
|
194
|
-
|
196
|
+
redis.pipelined do |pipeline|
|
197
|
+
pipeline.zrem(zset_key, corrupt_snapshots)
|
198
|
+
pipeline.hdel(hash_key, corrupt_snapshots)
|
195
199
|
end
|
196
200
|
end
|
197
201
|
end
|
@@ -200,11 +204,13 @@ unviewed_ids: #{get_unviewed_ids(user)}
|
|
200
204
|
hash_key = snapshot_hash_key()
|
201
205
|
bytes = redis.hget(hash_key, id)
|
202
206
|
begin
|
207
|
+
# rubocop:disable Security/MarshalLoad
|
203
208
|
Marshal.load(bytes)
|
209
|
+
# rubocop:enable Security/MarshalLoad
|
204
210
|
rescue
|
205
|
-
redis.pipelined do
|
206
|
-
|
207
|
-
|
211
|
+
redis.pipelined do |pipeline|
|
212
|
+
pipeline.zrem(snapshot_zset_key(), id)
|
213
|
+
pipeline.hdel(hash_key, id)
|
208
214
|
end
|
209
215
|
nil
|
210
216
|
end
|
@@ -253,11 +259,11 @@ unviewed_ids: #{get_unviewed_ids(user)}
|
|
253
259
|
|
254
260
|
# only used in tests
|
255
261
|
def wipe_snapshots_data
|
256
|
-
redis.
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
262
|
+
redis.del(
|
263
|
+
snapshot_counter_key(),
|
264
|
+
snapshot_zset_key(),
|
265
|
+
snapshot_hash_key(),
|
266
|
+
)
|
261
267
|
end
|
262
268
|
end
|
263
269
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-mini-profiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-02-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|