rack-mini-profiler 1.0.1 → 1.1.6
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 +4 -4
- data/CHANGELOG.md +60 -20
- data/README.md +16 -8
- data/lib/html/dot.1.1.2.min.js +2 -0
- data/lib/html/includes.css +102 -34
- data/lib/html/includes.js +1295 -1011
- data/lib/html/includes.scss +515 -441
- data/lib/html/includes.tmpl +138 -148
- data/lib/html/pretty-print.js +810 -0
- data/lib/html/share.html +0 -1
- data/lib/html/vendor.js +840 -0
- data/lib/mini_profiler/asset_version.rb +3 -2
- data/lib/mini_profiler/client_settings.rb +10 -3
- data/lib/mini_profiler/config.rb +4 -4
- data/lib/mini_profiler/gc_profiler.rb +1 -1
- data/lib/mini_profiler/profiler.rb +41 -11
- data/lib/mini_profiler/profiling_methods.rb +2 -6
- data/lib/mini_profiler/storage/file_store.rb +3 -3
- data/lib/mini_profiler/storage/memcache_store.rb +2 -0
- data/lib/mini_profiler/storage/memory_store.rb +1 -1
- data/lib/mini_profiler/timer_struct/sql.rb +1 -1
- data/lib/mini_profiler/version.rb +1 -1
- data/lib/mini_profiler_rails/railtie.rb +2 -0
- data/lib/patches/db/mongo.rb +1 -1
- data/lib/patches/db/moped.rb +1 -1
- data/lib/patches/db/plucky.rb +4 -4
- data/lib/patches/sql_patches.rb +1 -1
- data/rack-mini-profiler.gemspec +5 -1
- metadata +35 -10
- 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
@@ -89,10 +89,17 @@ module Rack
|
|
89
89
|
def has_valid_cookie?
|
90
90
|
valid_cookie = !@cookie.nil?
|
91
91
|
|
92
|
-
if (MiniProfiler.config.authorization_mode == :whitelist)
|
93
|
-
|
92
|
+
if (MiniProfiler.config.authorization_mode == :whitelist) && valid_cookie
|
93
|
+
begin
|
94
|
+
@allowed_tokens ||= @store.allowed_tokens
|
95
|
+
rescue => e
|
96
|
+
if @config.storage_failure != nil
|
97
|
+
@config.storage_failure.call(e)
|
98
|
+
end
|
99
|
+
end
|
94
100
|
|
95
|
-
valid_cookie =
|
101
|
+
valid_cookie = @allowed_tokens &&
|
102
|
+
(Array === @orig_auth_tokens) &&
|
96
103
|
((@allowed_tokens & @orig_auth_tokens).length > 0)
|
97
104
|
end
|
98
105
|
|
data/lib/mini_profiler/config.rb
CHANGED
@@ -34,9 +34,9 @@ module Rack
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
@enabled = true
|
37
|
-
@disable_env_dump = false
|
38
37
|
@max_sql_param_length = 0 # disable sql parameter collection by default
|
39
38
|
@skip_sql_param_names = /password/ # skips parameters with the name password by default
|
39
|
+
@enable_advanced_debugging_tools = false
|
40
40
|
|
41
41
|
# ui parameters
|
42
42
|
@autorized = true
|
@@ -47,7 +47,7 @@ module Rack
|
|
47
47
|
@show_trivial = false
|
48
48
|
@show_total_sql_count = false
|
49
49
|
@start_hidden = false
|
50
|
-
@toggle_shortcut = '
|
50
|
+
@toggle_shortcut = 'alt+p'
|
51
51
|
@html_container = 'body'
|
52
52
|
@position = "top-left"
|
53
53
|
|
@@ -57,10 +57,10 @@ module Rack
|
|
57
57
|
|
58
58
|
attr_accessor :authorization_mode, :auto_inject, :backtrace_ignores,
|
59
59
|
:backtrace_includes, :backtrace_remove, :backtrace_threshold_ms,
|
60
|
-
:base_url_path, :disable_caching, :
|
60
|
+
:base_url_path, :disable_caching, :enabled,
|
61
61
|
:flamegraph_sample_rate, :logger, :pre_authorize_cb, :skip_paths,
|
62
62
|
:skip_schema_queries, :storage, :storage_failure, :storage_instance,
|
63
|
-
:storage_options, :user_provider
|
63
|
+
:storage_options, :user_provider, :enable_advanced_debugging_tools
|
64
64
|
attr_accessor :skip_sql_param_names, :suppress_encoding, :max_sql_param_length
|
65
65
|
|
66
66
|
# ui accessors
|
@@ -62,6 +62,11 @@ module Rack
|
|
62
62
|
Thread.current[:mp_authorized]
|
63
63
|
end
|
64
64
|
|
65
|
+
def advanced_tools_message
|
66
|
+
<<~TEXT
|
67
|
+
This feature is disabled by default, to enable set the enable_advanced_debugging_tools option to true in Mini Profiler config.
|
68
|
+
TEXT
|
69
|
+
end
|
65
70
|
end
|
66
71
|
|
67
72
|
#
|
@@ -71,7 +76,7 @@ module Rack
|
|
71
76
|
MiniProfiler.config.merge!(config)
|
72
77
|
@config = MiniProfiler.config
|
73
78
|
@app = app
|
74
|
-
@config.base_url_path
|
79
|
+
@config.base_url_path += "/" unless @config.base_url_path.end_with? "/"
|
75
80
|
unless @config.storage_instance
|
76
81
|
@config.storage_instance = @config.storage.new(@config.storage_options)
|
77
82
|
end
|
@@ -84,11 +89,11 @@ module Rack
|
|
84
89
|
|
85
90
|
def serve_results(env)
|
86
91
|
request = Rack::Request.new(env)
|
87
|
-
id = request[
|
92
|
+
id = request.params['id']
|
88
93
|
page_struct = @storage.load(id)
|
89
94
|
unless page_struct
|
90
95
|
@storage.set_viewed(user(env), id)
|
91
|
-
id = ERB::Util.html_escape(request['id'])
|
96
|
+
id = ERB::Util.html_escape(request.params['id'])
|
92
97
|
user_info = ERB::Util.html_escape(user(env))
|
93
98
|
return [404, {}, ["Request not found: #{id} - user #{user_info}"]]
|
94
99
|
end
|
@@ -147,6 +152,14 @@ module Rack
|
|
147
152
|
@config
|
148
153
|
end
|
149
154
|
|
155
|
+
def advanced_debugging_enabled?
|
156
|
+
config.enable_advanced_debugging_tools
|
157
|
+
end
|
158
|
+
|
159
|
+
def tool_disabled_message(client_settings)
|
160
|
+
client_settings.handle_cookie(text_result(Rack::MiniProfiler.advanced_tools_message))
|
161
|
+
end
|
162
|
+
|
150
163
|
def call(env)
|
151
164
|
|
152
165
|
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
@@ -195,12 +208,14 @@ module Rack
|
|
195
208
|
|
196
209
|
# profile gc
|
197
210
|
if query_string =~ /pp=profile-gc/
|
211
|
+
return tool_disabled_message(client_settings) if !advanced_debugging_enabled?
|
198
212
|
current.measure = false if current
|
199
213
|
return client_settings.handle_cookie(Rack::MiniProfiler::GCProfiler.new.profile_gc(@app, env))
|
200
214
|
end
|
201
215
|
|
202
216
|
# profile memory
|
203
217
|
if query_string =~ /pp=profile-memory/
|
218
|
+
return tool_disabled_message(client_settings) if !advanced_debugging_enabled?
|
204
219
|
query_params = Rack::Utils.parse_nested_query(query_string)
|
205
220
|
options = {
|
206
221
|
ignore_files: query_params['memory_profiler_ignore_files'],
|
@@ -307,12 +322,14 @@ module Rack
|
|
307
322
|
return client_settings.handle_cookie(dump_exceptions exceptions)
|
308
323
|
end
|
309
324
|
|
310
|
-
if query_string =~ /pp=env/
|
325
|
+
if query_string =~ /pp=env/
|
326
|
+
return tool_disabled_message(client_settings) if !advanced_debugging_enabled?
|
311
327
|
body.close if body.respond_to? :close
|
312
328
|
return client_settings.handle_cookie(dump_env env)
|
313
329
|
end
|
314
330
|
|
315
331
|
if query_string =~ /pp=analyze-memory/
|
332
|
+
return tool_disabled_message(client_settings) if !advanced_debugging_enabled?
|
316
333
|
body.close if body.respond_to? :close
|
317
334
|
return client_settings.handle_cookie(analyze_memory)
|
318
335
|
end
|
@@ -331,6 +348,17 @@ module Rack
|
|
331
348
|
return client_settings.handle_cookie(self.flamegraph(flamegraph))
|
332
349
|
end
|
333
350
|
|
351
|
+
if path == '/rack-mini-profiler/requests'
|
352
|
+
blank_page_html = <<~HTML
|
353
|
+
<html>
|
354
|
+
<head></head>
|
355
|
+
<body></body>
|
356
|
+
</html>
|
357
|
+
HTML
|
358
|
+
|
359
|
+
status, headers, body = [200, { 'Content-Type' => 'text/html' }, [blank_page_html.dup]]
|
360
|
+
end
|
361
|
+
|
334
362
|
begin
|
335
363
|
@storage.save(page_struct)
|
336
364
|
# no matter what it is, it should be unviewed, otherwise we will miss POST
|
@@ -369,7 +397,7 @@ module Rack
|
|
369
397
|
|
370
398
|
# inject header
|
371
399
|
if headers.is_a? Hash
|
372
|
-
headers['X-MiniProfiler-Ids'] =
|
400
|
+
headers['X-MiniProfiler-Ids'] = ids_comma_separated(env)
|
373
401
|
end
|
374
402
|
|
375
403
|
if current.inject_js && content_type =~ /text\/html/
|
@@ -397,7 +425,13 @@ module Rack
|
|
397
425
|
if script.respond_to?(:encoding) && script.respond_to?(:force_encoding)
|
398
426
|
script = script.force_encoding(fragment.encoding)
|
399
427
|
end
|
400
|
-
|
428
|
+
|
429
|
+
safe_script = script
|
430
|
+
if script.respond_to?(:html_safe)
|
431
|
+
safe_script = script.html_safe
|
432
|
+
end
|
433
|
+
|
434
|
+
fragment.insert(index, safe_script)
|
401
435
|
else
|
402
436
|
fragment
|
403
437
|
end
|
@@ -522,7 +556,7 @@ module Rack
|
|
522
556
|
|
523
557
|
def make_link(postfix, env)
|
524
558
|
link = env["PATH_INFO"] + "?" + env["QUERY_STRING"].sub("pp=help", "pp=#{postfix}")
|
525
|
-
"pp=<a href='#{link}'>#{postfix}</a>"
|
559
|
+
"pp=<a href='#{ERB::Util.html_escape(link)}'>#{postfix}</a>"
|
526
560
|
end
|
527
561
|
|
528
562
|
def help(client_settings, env)
|
@@ -568,10 +602,6 @@ Append the following to your query string:
|
|
568
602
|
all
|
569
603
|
end
|
570
604
|
|
571
|
-
def ids_json(env)
|
572
|
-
::JSON.generate(ids(env))
|
573
|
-
end
|
574
|
-
|
575
605
|
def ids_comma_separated(env)
|
576
606
|
ids(env).join(",")
|
577
607
|
end
|
@@ -112,11 +112,11 @@ module Rack
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def profile_singleton_method(klass, method, type = :profile, &blk)
|
115
|
-
profile_method(singleton_class
|
115
|
+
profile_method(klass.singleton_class, method, type, &blk)
|
116
116
|
end
|
117
117
|
|
118
118
|
def unprofile_singleton_method(klass, method)
|
119
|
-
unprofile_method(singleton_class
|
119
|
+
unprofile_method(klass.singleton_class, method)
|
120
120
|
end
|
121
121
|
|
122
122
|
# Add a custom timing. These are displayed similar to SQL/query time in
|
@@ -144,10 +144,6 @@ module Rack
|
|
144
144
|
|
145
145
|
private
|
146
146
|
|
147
|
-
def singleton_class(klass)
|
148
|
-
class << klass; self; end
|
149
|
-
end
|
150
|
-
|
151
147
|
def clean_method_name(method)
|
152
148
|
method.to_s.gsub(/[\?\!]/, "")
|
153
149
|
end
|
@@ -17,9 +17,9 @@ module Rack
|
|
17
17
|
def [](key)
|
18
18
|
begin
|
19
19
|
data = ::File.open(path(key), "rb") { |f| f.read }
|
20
|
-
|
20
|
+
Marshal.load data
|
21
21
|
rescue
|
22
|
-
|
22
|
+
nil
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -31,7 +31,7 @@ module Rack
|
|
31
31
|
end
|
32
32
|
|
33
33
|
private
|
34
|
-
if
|
34
|
+
if Gem.win_platform?
|
35
35
|
def path(key)
|
36
36
|
@path.dup << "/" << @prefix << "_" << key.gsub(/:/, '_')
|
37
37
|
end
|
@@ -10,8 +10,10 @@ module Rack
|
|
10
10
|
def initialize(args = nil)
|
11
11
|
require 'dalli' unless defined? Dalli
|
12
12
|
args ||= {}
|
13
|
+
|
13
14
|
@prefix = args[:prefix] || "MPMemcacheStore"
|
14
15
|
@prefix += "-#{Rack::MiniProfiler::VERSION}"
|
16
|
+
|
15
17
|
@client = args[:client] || Dalli::Client.new
|
16
18
|
@expires_in_seconds = args[:expires_in] || EXPIRES_IN_SECONDS
|
17
19
|
end
|
@@ -36,7 +36,7 @@ module Rack
|
|
36
36
|
start_millis = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i - page[:started]) - duration_ms
|
37
37
|
super(
|
38
38
|
execute_type: 3, # TODO
|
39
|
-
formatted_command_string: query,
|
39
|
+
formatted_command_string: ERB::Util.html_escape(query),
|
40
40
|
stack_trace_snippet: stack_trace,
|
41
41
|
start_milliseconds: start_millis,
|
42
42
|
duration_milliseconds: duration_ms,
|
@@ -64,6 +64,7 @@ module Rack::MiniProfilerRails
|
|
64
64
|
::Rack::MiniProfiler.profile_method(ActionView::Template, :render) { |x, y| "Rendering: #{@virtual_path}" }
|
65
65
|
end
|
66
66
|
|
67
|
+
c.enable_advanced_debugging_tools = Rails.env.development?
|
67
68
|
@already_initialized = true
|
68
69
|
end
|
69
70
|
|
@@ -95,6 +96,7 @@ module Rack::MiniProfilerRails
|
|
95
96
|
middlewares = app.middleware.middlewares
|
96
97
|
if Rack::MiniProfiler.config.suppress_encoding.nil? &&
|
97
98
|
middlewares.include?(Rack::Deflater) &&
|
99
|
+
middlewares.include?(Rack::MiniProfiler) &&
|
98
100
|
middlewares.index(Rack::Deflater) > middlewares.index(Rack::MiniProfiler)
|
99
101
|
Rack::MiniProfiler.config.suppress_encoding = true
|
100
102
|
end
|
data/lib/patches/db/mongo.rb
CHANGED
@@ -8,7 +8,7 @@ class Mongo::Server::Connection
|
|
8
8
|
result, _record = SqlPatches.record_sql(args[0][0].payload.inspect) do
|
9
9
|
dispatch_without_timing(*args, &blk)
|
10
10
|
end
|
11
|
-
|
11
|
+
result
|
12
12
|
end
|
13
13
|
|
14
14
|
# TODO: change to Module#prepend as soon as Ruby 1.9.3 support is dropped
|
data/lib/patches/db/moped.rb
CHANGED
data/lib/patches/db/plucky.rb
CHANGED
@@ -9,19 +9,19 @@ class Plucky::Query
|
|
9
9
|
alias_method :remove_without_profiling, :remove
|
10
10
|
|
11
11
|
def find_each(*args, &blk)
|
12
|
-
|
12
|
+
profile_database_operation(__callee__, filtered_inspect(), *args, &blk)
|
13
13
|
end
|
14
14
|
|
15
15
|
def find_one(*args, &blk)
|
16
|
-
|
16
|
+
profile_database_operation(__callee__, filtered_inspect(args[0]), *args, &blk)
|
17
17
|
end
|
18
18
|
|
19
19
|
def count(*args, &blk)
|
20
|
-
|
20
|
+
profile_database_operation(__callee__, filtered_inspect(), *args, &blk)
|
21
21
|
end
|
22
22
|
|
23
23
|
def remove(*args, &blk)
|
24
|
-
|
24
|
+
profile_database_operation(__callee__, filtered_inspect(), *args, &blk)
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
data/lib/patches/sql_patches.rb
CHANGED
@@ -11,7 +11,7 @@ class SqlPatches
|
|
11
11
|
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
12
12
|
result = yield
|
13
13
|
record = ::Rack::MiniProfiler.record_sql(statement, elapsed_time(start), parameters)
|
14
|
-
|
14
|
+
[result, record]
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.should_measure?
|
data/rack-mini-profiler.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('../lib', __FILE__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'mini_profiler/version'
|
@@ -32,9 +34,11 @@ Gem::Specification.new do |s|
|
|
32
34
|
s.add_development_dependency 'dalli'
|
33
35
|
s.add_development_dependency 'rspec', '~> 3.6.0'
|
34
36
|
s.add_development_dependency 'redis'
|
35
|
-
s.add_development_dependency '
|
37
|
+
s.add_development_dependency 'sassc'
|
36
38
|
s.add_development_dependency 'flamegraph'
|
37
39
|
s.add_development_dependency 'rubocop'
|
40
|
+
s.add_development_dependency 'mini_racer'
|
41
|
+
s.add_development_dependency 'nokogiri'
|
38
42
|
|
39
43
|
s.require_paths = ["lib"]
|
40
44
|
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: 1.
|
4
|
+
version: 1.1.6
|
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: 2020-01-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rack
|
@@ -111,7 +111,7 @@ dependencies:
|
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
|
-
name:
|
114
|
+
name: sassc
|
115
115
|
requirement: !ruby/object:Gem::Requirement
|
116
116
|
requirements:
|
117
117
|
- - ">="
|
@@ -152,6 +152,34 @@ dependencies:
|
|
152
152
|
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: '0'
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: mini_racer
|
157
|
+
requirement: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
type: :development
|
163
|
+
prerelease: false
|
164
|
+
version_requirements: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: nokogiri
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
type: :development
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
155
183
|
description: Profiling toolkit for Rack applications with Rails integration. Client
|
156
184
|
Side profiling, DB profiling and Server profiling.
|
157
185
|
email: sam.saffron@gmail.com
|
@@ -166,17 +194,15 @@ files:
|
|
166
194
|
- lib/generators/rack_profiler/USAGE
|
167
195
|
- lib/generators/rack_profiler/install_generator.rb
|
168
196
|
- lib/generators/rack_profiler/templates/rack_profiler.rb
|
197
|
+
- lib/html/dot.1.1.2.min.js
|
169
198
|
- lib/html/includes.css
|
170
199
|
- lib/html/includes.js
|
171
200
|
- lib/html/includes.scss
|
172
201
|
- lib/html/includes.tmpl
|
173
|
-
- lib/html/
|
174
|
-
- lib/html/jquery.tmpl.js
|
175
|
-
- lib/html/list.css
|
176
|
-
- lib/html/list.js
|
177
|
-
- lib/html/list.tmpl
|
202
|
+
- lib/html/pretty-print.js
|
178
203
|
- lib/html/profile_handler.js
|
179
204
|
- lib/html/share.html
|
205
|
+
- lib/html/vendor.js
|
180
206
|
- lib/mini_profiler/asset_version.rb
|
181
207
|
- lib/mini_profiler/client_settings.rb
|
182
208
|
- lib/mini_profiler/config.rb
|
@@ -234,8 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
260
|
- !ruby/object:Gem::Version
|
235
261
|
version: '0'
|
236
262
|
requirements: []
|
237
|
-
|
238
|
-
rubygems_version: 2.7.6
|
263
|
+
rubygems_version: 3.0.3
|
239
264
|
signing_key:
|
240
265
|
specification_version: 4
|
241
266
|
summary: Profiles loading speed for rack applications.
|