miniprofiler 0.1.7.3 → 0.1.7.4
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.
- data/Gemfile.lock +1 -1
- data/README.md +3 -5
- data/Rakefile +1 -0
- data/UI/include.partial.html +60 -60
- data/lib/html/profile_handler.js +60 -60
- data/lib/html/share.html +11 -0
- data/lib/mini_profiler/profiler.rb +121 -121
- data/rack-mini-profiler.gemspec +1 -1
- metadata +12 -11
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# NOTE FOR THIS GEM FORK
|
2
2
|
|
3
|
-
This is a fork the Ruby folder of https://github.com/SamSaffron/MiniProfiler which includes some quick fixes to make the original rack-mini-profiler gem a little more usable. I will consolidate any useful changes here into pull requests for the original repo
|
3
|
+
This is a fork the Ruby folder of https://github.com/SamSaffron/MiniProfiler which includes some quick fixes to make the original rack-mini-profiler gem a little more usable. I will keep in in sync with Ruby related development from the original repo and consolidate any useful changes here into pull requests for the original repo
|
4
4
|
|
5
|
-
* Add `gem 'miniprofiler'` to your Gemfile (install of 'rack-mini-profiler')
|
5
|
+
* Add `gem 'miniprofiler', require: 'rack-mini-profiler'` to your Gemfile (install of `gem 'rack-mini-profiler'`)
|
6
6
|
* `miniprofiler`'s version uses `x.y.z.t` syntax in order to more easily sync with `rack-mini-profiler`'s `x.y.z` SemVer versioning. I will increase `t` whenever I make a patch
|
7
|
-
*
|
8
|
-
* Gem release date will be correct (as of now 'rack-mini-profiler' hardcodes the release date to be 04/02/2012, which is very confusing: https://rubygems.org/gems/rack-mini-profiler -- I will report to them)
|
9
|
-
* Allow turning off loading jquery if the app already uses jquery
|
7
|
+
* Note to use MiniProfiler outside development and production env in Rails, set `Rack::MiniProfiler.config.pre_authorize_cb = lambda {|env| true }` in an initializer file in Rails. I recommend wrapping all Rack::MiniProfiler calls under your env check. E.g. `if %w(development staging).include?(Rails.env)`
|
10
8
|
* More to come
|
11
9
|
|
12
10
|
# Original README below:
|
data/Rakefile
CHANGED
data/UI/include.partial.html
CHANGED
@@ -1,62 +1,62 @@
|
|
1
|
-
<script type="text/javascript">
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
<script type="text/javascript">
|
2
|
+
(function(){{
|
3
|
+
var init = function() {{
|
4
|
+
var load = function(s,f){{
|
5
|
+
var sc = document.createElement('script');
|
6
|
+
sc.async = 'async';
|
7
|
+
sc.type = 'text/javascript';
|
8
|
+
sc.src = s;
|
9
|
+
var l = false;
|
10
|
+
sc.onload = sc.onreadystatechange = function(_, abort) {{
|
11
|
+
if (!l && (!sc.readyState || /loaded|complete/.test(sc.readyState))) {{
|
12
|
+
if (!abort){{l=true; f();}}
|
13
|
+
}}
|
14
|
+
}};
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
var initMp = function(){{
|
20
|
-
load('{path}includes.js?v={version}',function(){{
|
21
|
-
MiniProfiler.init({{
|
22
|
-
ids: {ids},
|
23
|
-
path: '{path}',
|
24
|
-
version: '{version}',
|
25
|
-
renderPosition: '{position}',
|
26
|
-
showTrivial: {showTrivial},
|
27
|
-
showChildrenTime: {showChildren},
|
28
|
-
maxTracesToShow: {maxTracesToShow},
|
29
|
-
showControls: {showControls},
|
30
|
-
currentId: '{currentId}',
|
31
|
-
authorized: {authorized}
|
32
|
-
}});
|
33
|
-
}});
|
34
|
-
}};
|
35
|
-
if ({useExistingjQuery}) {{
|
36
|
-
jQueryMP = jQuery;
|
37
|
-
initMp();
|
38
|
-
}} else {{
|
39
|
-
load('{path}jquery.1.7.1.js?v={version}', initMp);
|
40
|
-
}}
|
41
|
-
|
42
|
-
}};
|
16
|
+
document.getElementsByTagName('head')[0].appendChild(sc);
|
17
|
+
}};
|
43
18
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
19
|
+
var initMp = function(){{
|
20
|
+
load('{path}includes.js?v={version}',function(){{
|
21
|
+
MiniProfiler.init({{
|
22
|
+
ids: {ids},
|
23
|
+
path: '{path}',
|
24
|
+
version: '{version}',
|
25
|
+
renderPosition: '{position}',
|
26
|
+
showTrivial: {showTrivial},
|
27
|
+
showChildrenTime: {showChildren},
|
28
|
+
maxTracesToShow: {maxTracesToShow},
|
29
|
+
showControls: {showControls},
|
30
|
+
currentId: '{currentId}',
|
31
|
+
authorized: {authorized}
|
32
|
+
}});
|
33
|
+
}});
|
34
|
+
}};
|
35
|
+
if ({useExistingjQuery} && typeof(jQuery) === "function") {{
|
36
|
+
jQueryMP = jQuery;
|
37
|
+
initMp();
|
38
|
+
}} else {{
|
39
|
+
load('{path}jquery.1.7.1.js?v={version}', initMp);
|
40
|
+
}}
|
41
|
+
|
42
|
+
}};
|
43
|
+
|
44
|
+
var w = 0;
|
45
|
+
var f = false;
|
46
|
+
var deferInit = function(){{
|
47
|
+
if (f) return;
|
48
|
+
if (window.performance && window.performance.timing && window.performance.timing.loadEventEnd == 0 && w < 10000){{
|
49
|
+
setTimeout(deferInit, 100);
|
50
|
+
w += 100;
|
51
|
+
}} else {{
|
52
|
+
f = true;
|
53
|
+
init();
|
54
|
+
}}
|
55
|
+
}};
|
56
|
+
if (document.addEventListener) {{
|
57
|
+
document.addEventListener('DOMContentLoaded',deferInit);
|
58
|
+
}}
|
59
|
+
var o = window.onload;
|
60
|
+
window.onload = function(){{if(o)o; deferInit()}};
|
61
|
+
}})();
|
62
|
+
</script>
|
data/lib/html/profile_handler.js
CHANGED
@@ -1,62 +1,62 @@
|
|
1
|
-
<script type="text/javascript">
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
<script type="text/javascript">
|
2
|
+
(function(){{
|
3
|
+
var init = function() {{
|
4
|
+
var load = function(s,f){{
|
5
|
+
var sc = document.createElement('script');
|
6
|
+
sc.async = 'async';
|
7
|
+
sc.type = 'text/javascript';
|
8
|
+
sc.src = s;
|
9
|
+
var l = false;
|
10
|
+
sc.onload = sc.onreadystatechange = function(_, abort) {{
|
11
|
+
if (!l && (!sc.readyState || /loaded|complete/.test(sc.readyState))) {{
|
12
|
+
if (!abort){{l=true; f();}}
|
13
|
+
}}
|
14
|
+
}};
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
var initMp = function(){{
|
20
|
-
load('{path}includes.js?v={version}',function(){{
|
21
|
-
MiniProfiler.init({{
|
22
|
-
ids: {ids},
|
23
|
-
path: '{path}',
|
24
|
-
version: '{version}',
|
25
|
-
renderPosition: '{position}',
|
26
|
-
showTrivial: {showTrivial},
|
27
|
-
showChildrenTime: {showChildren},
|
28
|
-
maxTracesToShow: {maxTracesToShow},
|
29
|
-
showControls: {showControls},
|
30
|
-
currentId: '{currentId}',
|
31
|
-
authorized: {authorized}
|
32
|
-
}});
|
33
|
-
}});
|
34
|
-
}};
|
35
|
-
if ({useExistingjQuery}) {{
|
36
|
-
jQueryMP = jQuery;
|
37
|
-
initMp();
|
38
|
-
}} else {{
|
39
|
-
load('{path}jquery.1.7.1.js?v={version}', initMp);
|
40
|
-
}}
|
41
|
-
|
42
|
-
}};
|
16
|
+
document.getElementsByTagName('head')[0].appendChild(sc);
|
17
|
+
}};
|
43
18
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
19
|
+
var initMp = function(){{
|
20
|
+
load('{path}includes.js?v={version}',function(){{
|
21
|
+
MiniProfiler.init({{
|
22
|
+
ids: {ids},
|
23
|
+
path: '{path}',
|
24
|
+
version: '{version}',
|
25
|
+
renderPosition: '{position}',
|
26
|
+
showTrivial: {showTrivial},
|
27
|
+
showChildrenTime: {showChildren},
|
28
|
+
maxTracesToShow: {maxTracesToShow},
|
29
|
+
showControls: {showControls},
|
30
|
+
currentId: '{currentId}',
|
31
|
+
authorized: {authorized}
|
32
|
+
}});
|
33
|
+
}});
|
34
|
+
}};
|
35
|
+
if ({useExistingjQuery} && typeof(jQuery) === "function") {{
|
36
|
+
jQueryMP = jQuery;
|
37
|
+
initMp();
|
38
|
+
}} else {{
|
39
|
+
load('{path}jquery.1.7.1.js?v={version}', initMp);
|
40
|
+
}}
|
41
|
+
|
42
|
+
}};
|
43
|
+
|
44
|
+
var w = 0;
|
45
|
+
var f = false;
|
46
|
+
var deferInit = function(){{
|
47
|
+
if (f) return;
|
48
|
+
if (window.performance && window.performance.timing && window.performance.timing.loadEventEnd == 0 && w < 10000){{
|
49
|
+
setTimeout(deferInit, 100);
|
50
|
+
w += 100;
|
51
|
+
}} else {{
|
52
|
+
f = true;
|
53
|
+
init();
|
54
|
+
}}
|
55
|
+
}};
|
56
|
+
if (document.addEventListener) {{
|
57
|
+
document.addEventListener('DOMContentLoaded',deferInit);
|
58
|
+
}}
|
59
|
+
var o = window.onload;
|
60
|
+
window.onload = function(){{if(o)o; deferInit()}};
|
61
|
+
}})();
|
62
|
+
</script>
|
data/lib/html/share.html
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>{name} ({duration} ms) - Profiling Results</title>
|
4
|
+
<script type='text/javascript' src='{path}jquery.1.7.1.js?v={version}'></script>
|
5
|
+
<script type='text/javascript'> var profiler = {json}; </script>
|
6
|
+
{includes}
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div class='profiler-result-full'></div>
|
10
|
+
</body>
|
11
|
+
</html>
|
@@ -17,12 +17,12 @@ require 'mini_profiler/context'
|
|
17
17
|
|
18
18
|
module Rack
|
19
19
|
|
20
|
-
|
20
|
+
class MiniProfiler
|
21
21
|
|
22
|
-
|
22
|
+
VERSION = '104'.freeze
|
23
|
+
|
24
|
+
class << self
|
23
25
|
|
24
|
-
class << self
|
25
|
-
|
26
26
|
include Rack::MiniProfiler::ProfilingMethods
|
27
27
|
|
28
28
|
def generate_id
|
@@ -42,7 +42,7 @@ module Rack
|
|
42
42
|
return @share_template unless @share_template.nil?
|
43
43
|
@share_template = ::File.read(::File.expand_path("../html/share.html", ::File.dirname(__FILE__)))
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def current
|
47
47
|
Thread.current[:mini_profiler_private]
|
48
48
|
end
|
@@ -92,70 +92,70 @@ module Rack
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
#
|
96
|
+
# options:
|
97
|
+
# :auto_inject - should script be automatically injected on every html page (not xhr)
|
98
|
+
def initialize(app, config = nil)
|
99
99
|
MiniProfiler.config.merge!(config)
|
100
|
-
@config = MiniProfiler.config
|
101
|
-
|
102
|
-
|
100
|
+
@config = MiniProfiler.config
|
101
|
+
@app = app
|
102
|
+
@config.base_url_path << "/" unless @config.base_url_path.end_with? "/"
|
103
103
|
unless @config.storage_instance
|
104
104
|
@storage = @config.storage_instance = @config.storage.new(@config.storage_options)
|
105
105
|
end
|
106
|
-
|
107
|
-
|
106
|
+
end
|
107
|
+
|
108
108
|
def user(env)
|
109
109
|
@config.user_provider.call(env)
|
110
110
|
end
|
111
111
|
|
112
|
-
|
113
|
-
|
112
|
+
def serve_results(env)
|
113
|
+
request = Rack::Request.new(env)
|
114
114
|
id = request['id']
|
115
|
-
|
115
|
+
page_struct = @storage.load(id)
|
116
116
|
unless page_struct
|
117
|
-
@storage.set_viewed(user(env), id)
|
118
|
-
return [404, {}, ["Request not found: #{request['id']} - user #{user(env)}"]]
|
117
|
+
@storage.set_viewed(user(env), id)
|
118
|
+
return [404, {}, ["Request not found: #{request['id']} - user #{user(env)}"]]
|
119
|
+
end
|
120
|
+
unless page_struct['HasUserViewed']
|
121
|
+
page_struct['ClientTimings'].init_from_form_data(env, page_struct)
|
122
|
+
page_struct['HasUserViewed'] = true
|
123
|
+
@storage.save(page_struct)
|
124
|
+
@storage.set_viewed(user(env), id)
|
119
125
|
end
|
120
|
-
unless page_struct['HasUserViewed']
|
121
|
-
page_struct['ClientTimings'].init_from_form_data(env, page_struct)
|
122
|
-
page_struct['HasUserViewed'] = true
|
123
|
-
@storage.save(page_struct)
|
124
|
-
@storage.set_viewed(user(env), id)
|
125
|
-
end
|
126
126
|
|
127
127
|
result_json = page_struct.to_json
|
128
128
|
# If we're an XMLHttpRequest, serve up the contents as JSON
|
129
129
|
if request.xhr?
|
130
|
-
|
130
|
+
[200, { 'Content-Type' => 'application/json'}, [result_json]]
|
131
131
|
else
|
132
132
|
|
133
133
|
# Otherwise give the HTML back
|
134
|
-
html = MiniProfiler.share_template.dup
|
135
|
-
html.gsub!(/\{path\}/, @config.base_url_path)
|
136
|
-
html.gsub!(/\{version\}/, MiniProfiler::VERSION)
|
134
|
+
html = MiniProfiler.share_template.dup
|
135
|
+
html.gsub!(/\{path\}/, @config.base_url_path)
|
136
|
+
html.gsub!(/\{version\}/, MiniProfiler::VERSION)
|
137
137
|
html.gsub!(/\{json\}/, result_json)
|
138
138
|
html.gsub!(/\{includes\}/, get_profile_script(env))
|
139
139
|
html.gsub!(/\{name\}/, page_struct['Name'])
|
140
140
|
html.gsub!(/\{duration\}/, page_struct.duration_ms.round(1).to_s)
|
141
|
-
|
141
|
+
|
142
142
|
[200, {'Content-Type' => 'text/html'}, [html]]
|
143
143
|
end
|
144
144
|
|
145
|
-
|
145
|
+
end
|
146
|
+
|
147
|
+
def serve_html(env)
|
148
|
+
file_name = env['PATH_INFO'][(@config.base_url_path.length)..1000]
|
149
|
+
return serve_results(env) if file_name.eql?('results')
|
150
|
+
full_path = ::File.expand_path("../html/#{file_name}", ::File.dirname(__FILE__))
|
151
|
+
return [404, {}, ["Not found"]] unless ::File.exists? full_path
|
152
|
+
f = Rack::File.new nil
|
153
|
+
f.path = full_path
|
154
|
+
f.cache_control = "max-age:86400"
|
155
|
+
f.serving env
|
156
|
+
end
|
146
157
|
|
147
|
-
def serve_html(env)
|
148
|
-
file_name = env['PATH_INFO'][(@config.base_url_path.length)..1000]
|
149
|
-
return serve_results(env) if file_name.eql?('results')
|
150
|
-
full_path = ::File.expand_path("../html/#{file_name}", ::File.dirname(__FILE__))
|
151
|
-
return [404, {}, ["Not found"]] unless ::File.exists? full_path
|
152
|
-
f = Rack::File.new nil
|
153
|
-
f.path = full_path
|
154
|
-
f.cache_control = "max-age:86400"
|
155
|
-
f.serving env
|
156
|
-
end
|
157
158
|
|
158
|
-
|
159
159
|
def current
|
160
160
|
MiniProfiler.current
|
161
161
|
end
|
@@ -170,26 +170,26 @@ module Rack
|
|
170
170
|
end
|
171
171
|
|
172
172
|
|
173
|
-
|
173
|
+
def call(env)
|
174
174
|
status = headers = body = nil
|
175
175
|
path = env['PATH_INFO']
|
176
176
|
|
177
177
|
skip_it = (@config.pre_authorize_cb && !@config.pre_authorize_cb.call(env)) ||
|
178
|
-
|
179
|
-
|
180
|
-
|
178
|
+
(@config.skip_paths && @config.skip_paths.any?{ |p| path[0,p.length] == p}) ||
|
179
|
+
env["QUERY_STRING"] =~ /pp=skip/
|
180
|
+
|
181
181
|
has_profiling_cookie = MiniProfiler.has_profiling_cookie?(env)
|
182
|
-
|
182
|
+
|
183
183
|
if skip_it || (@config.authorization_mode == :whitelist && !has_profiling_cookie)
|
184
184
|
status,headers,body = @app.call(env)
|
185
|
-
if !skip_it && @config.authorization_mode == :whitelist && !has_profiling_cookie && MiniProfiler.request_authorized?
|
186
|
-
MiniProfiler.set_profiling_cookie(headers)
|
185
|
+
if !skip_it && @config.authorization_mode == :whitelist && !has_profiling_cookie && MiniProfiler.request_authorized?
|
186
|
+
MiniProfiler.set_profiling_cookie(headers)
|
187
187
|
end
|
188
188
|
return [status,headers,body]
|
189
189
|
end
|
190
190
|
|
191
191
|
# handle all /mini-profiler requests here
|
192
|
-
|
192
|
+
return serve_html(env) if env['PATH_INFO'].start_with? @config.base_url_path
|
193
193
|
|
194
194
|
MiniProfiler.create_current(env, @config)
|
195
195
|
MiniProfiler.deauthorize_request if @config.authorization_mode == :whitelist
|
@@ -211,28 +211,28 @@ module Rack
|
|
211
211
|
require 'stacktrace' rescue nil
|
212
212
|
if !t.respond_to? :stacktrace
|
213
213
|
missing_stacktrace = true
|
214
|
-
quit_sampler = true
|
214
|
+
quit_sampler = true
|
215
215
|
return
|
216
216
|
end
|
217
|
-
i = 10000 # for sanity never grab more than 10k samples
|
217
|
+
i = 10000 # for sanity never grab more than 10k samples
|
218
218
|
while i > 0
|
219
219
|
break if done_sampling
|
220
220
|
i -= 1
|
221
221
|
backtraces << t.stacktrace
|
222
222
|
sleep 0.001
|
223
223
|
end
|
224
|
-
|
225
|
-
|
226
|
-
|
224
|
+
ensure
|
225
|
+
quit_sampler = true
|
226
|
+
end
|
227
227
|
}
|
228
228
|
end
|
229
229
|
|
230
|
-
|
231
|
-
start = Time.now
|
232
|
-
begin
|
230
|
+
status, headers, body = nil
|
231
|
+
start = Time.now
|
232
|
+
begin
|
233
233
|
status,headers,body = @app.call(env)
|
234
234
|
ensure
|
235
|
-
if backtraces
|
235
|
+
if backtraces
|
236
236
|
done_sampling = true
|
237
237
|
sleep 0.001 until quit_sampler
|
238
238
|
end
|
@@ -243,9 +243,9 @@ module Rack
|
|
243
243
|
MiniProfiler.remove_profiling_cookie(headers)
|
244
244
|
skip_it = true
|
245
245
|
end
|
246
|
-
|
246
|
+
|
247
247
|
return [status,headers,body] if skip_it
|
248
|
-
|
248
|
+
|
249
249
|
# we must do this here, otherwise current[:discard] is not being properly treated
|
250
250
|
if env["QUERY_STRING"] =~ /pp=env/
|
251
251
|
body.close if body.respond_to? :close
|
@@ -256,51 +256,51 @@ module Rack
|
|
256
256
|
body.close if body.respond_to? :close
|
257
257
|
return help
|
258
258
|
end
|
259
|
-
|
259
|
+
|
260
260
|
page_struct = current.page_struct
|
261
|
-
|
261
|
+
page_struct['Root'].record_time((Time.now - start) * 1000)
|
262
262
|
|
263
263
|
if backtraces
|
264
264
|
body.close if body.respond_to? :close
|
265
265
|
return help(:stacktrace) if missing_stacktrace
|
266
266
|
return analyze(backtraces, page_struct)
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
|
270
270
|
# no matter what it is, it should be unviewed, otherwise we will miss POST
|
271
|
-
@storage.set_unviewed(user(env), page_struct['Id'])
|
272
|
-
|
273
|
-
|
271
|
+
@storage.set_unviewed(user(env), page_struct['Id'])
|
272
|
+
@storage.save(page_struct)
|
273
|
+
|
274
274
|
# inject headers, script
|
275
|
-
|
276
|
-
|
277
|
-
|
275
|
+
if status == 200
|
276
|
+
|
277
|
+
# inject header
|
278
278
|
if headers.is_a? Hash
|
279
279
|
headers['X-MiniProfiler-Ids'] = ids_json(env)
|
280
280
|
end
|
281
281
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
282
|
+
# inject script
|
283
|
+
if current.inject_js \
|
284
|
+
&& headers.has_key?('Content-Type') \
|
285
|
+
&& !headers['Content-Type'].match(/text\/html/).nil? then
|
286
|
+
body = MiniProfiler::BodyAddProxy.new(body, self.get_profile_script(env))
|
287
|
+
end
|
288
|
+
end
|
289
289
|
|
290
290
|
# mini profiler is meddling with stuff, we can not cache cause we will get incorrect data
|
291
291
|
# Rack::ETag has already inserted some nonesense in the chain
|
292
292
|
headers.delete('ETag')
|
293
293
|
headers.delete('Date')
|
294
294
|
headers['Cache-Control'] = 'must-revalidate, private, max-age=0'
|
295
|
-
|
295
|
+
[status, headers, body]
|
296
296
|
ensure
|
297
297
|
# Make sure this always happens
|
298
298
|
current = nil
|
299
|
-
|
299
|
+
end
|
300
300
|
|
301
301
|
def dump_env(env)
|
302
302
|
headers = {'Content-Type' => 'text/plain'}
|
303
|
-
body = ""
|
303
|
+
body = ""
|
304
304
|
env.each do |k,v|
|
305
305
|
body << "#{k}: #{v}\n"
|
306
306
|
end
|
@@ -317,11 +317,11 @@ module Rack
|
|
317
317
|
pp=no-backtrace : don't collect stack traces from all the SQL executed
|
318
318
|
pp=full-backtrace : enable full backtrace for SQL executed
|
319
319
|
pp=sample : sample stack traces and return a report isolating heavy usage (requires the stacktrace gem)
|
320
|
-
"
|
320
|
+
"
|
321
321
|
if (category == :stacktrace)
|
322
322
|
body = "pp=stacktrace requires the stacktrace gem - add gem 'stacktrace' to your Gemfile"
|
323
323
|
end
|
324
|
-
|
324
|
+
|
325
325
|
[200, headers, [body]]
|
326
326
|
end
|
327
327
|
|
@@ -331,7 +331,7 @@ module Rack
|
|
331
331
|
|
332
332
|
seen = {}
|
333
333
|
fulldump = ""
|
334
|
-
traces.each do |trace|
|
334
|
+
traces.each do |trace|
|
335
335
|
fulldump << "\n\n"
|
336
336
|
distinct = {}
|
337
337
|
trace.each do |frame|
|
@@ -351,7 +351,7 @@ module Rack
|
|
351
351
|
body << "#{name} x #{count}\n"
|
352
352
|
end
|
353
353
|
end
|
354
|
-
|
354
|
+
|
355
355
|
body << "\n\n\nRaw traces \n"
|
356
356
|
body << fulldump
|
357
357
|
|
@@ -363,43 +363,43 @@ module Rack
|
|
363
363
|
::JSON.generate(ids.uniq)
|
364
364
|
end
|
365
365
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
366
|
+
# get_profile_script returns script to be injected inside current html page
|
367
|
+
# By default, profile_script is appended to the end of all html requests automatically.
|
368
|
+
# Calling get_profile_script cancels automatic append for the current page
|
369
|
+
# Use it when:
|
370
|
+
# * you have disabled auto append behaviour throught :auto_inject => false flag
|
371
|
+
# * you do not want script to be automatically appended for the current page. You can also call cancel_auto_inject
|
372
|
+
def get_profile_script(env)
|
373
|
+
ids = ids_json(env)
|
374
|
+
path = @config.base_url_path
|
375
|
+
version = MiniProfiler::VERSION
|
376
|
+
position = @config.position
|
377
|
+
showTrivial = false
|
378
|
+
showChildren = false
|
379
|
+
maxTracesToShow = 10
|
380
|
+
showControls = false
|
381
|
+
currentId = current.page_struct["Id"]
|
382
|
+
authorized = true
|
383
|
+
useExistingjQuery = @config.use_existing_jquery
|
384
|
+
# TODO : cache this snippet
|
385
|
+
script = IO.read(::File.expand_path('../html/profile_handler.js', ::File.dirname(__FILE__)))
|
386
|
+
# replace the variables
|
387
|
+
[:ids, :path, :version, :position, :showTrivial, :showChildren, :maxTracesToShow, :showControls, :currentId, :authorized, :useExistingjQuery].each do |v|
|
388
|
+
regex = Regexp.new("\\{#{v.to_s}\\}")
|
389
|
+
script.gsub!(regex, eval(v.to_s).to_s)
|
390
|
+
end
|
391
|
+
# replace the '{{' and '}}''
|
392
|
+
script.gsub!(/\{\{/, '{').gsub!(/\}\}/, '}')
|
393
|
+
current.inject_js = false
|
394
|
+
script
|
395
|
+
end
|
396
|
+
|
397
|
+
# cancels automatic injection of profile script for the current page
|
398
|
+
def cancel_auto_inject(env)
|
399
|
+
current.inject_js = false
|
400
|
+
end
|
401
|
+
|
402
|
+
end
|
403
403
|
|
404
404
|
end
|
405
405
|
|
data/rack-mini-profiler.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "miniprofiler"
|
3
|
-
s.version = "0.1.7.
|
3
|
+
s.version = "0.1.7.4"
|
4
4
|
s.summary = "Profiles loading speed for rack applications."
|
5
5
|
s.authors = ["Aleks Totic","Sam Saffron", "Robin Ward"]
|
6
6
|
s.description = "Page loading speed displayed on every page. Optimize while you develop, performance is a feature."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miniprofiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.7.
|
4
|
+
version: 0.1.7.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -15,7 +15,7 @@ date: 2012-07-20 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rack
|
18
|
-
requirement: &
|
18
|
+
requirement: &2157245440 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: 1.1.3
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *2157245440
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
|
-
requirement: &
|
29
|
+
requirement: &2157244860 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *2157244860
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rack-test
|
40
|
-
requirement: &
|
40
|
+
requirement: &2157212960 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *2157212960
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: activerecord
|
51
|
-
requirement: &
|
51
|
+
requirement: &2157212260 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
version: '3.0'
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *2157212260
|
60
60
|
description: Page loading speed displayed on every page. Optimize while you develop,
|
61
61
|
performance is a feature.
|
62
62
|
email: sam.saffron@gmail.com
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/html/list.js
|
96
96
|
- lib/html/list.tmpl
|
97
97
|
- lib/html/profile_handler.js
|
98
|
+
- lib/html/share.html
|
98
99
|
- lib/mini_profiler/body_add_proxy.rb
|
99
100
|
- lib/mini_profiler/client_timer_struct.rb
|
100
101
|
- lib/mini_profiler/config.rb
|
@@ -143,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
144
|
version: '0'
|
144
145
|
segments:
|
145
146
|
- 0
|
146
|
-
hash:
|
147
|
+
hash: 349144657699617797
|
147
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
149
|
none: false
|
149
150
|
requirements:
|
@@ -152,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
153
|
version: '0'
|
153
154
|
segments:
|
154
155
|
- 0
|
155
|
-
hash:
|
156
|
+
hash: 349144657699617797
|
156
157
|
requirements: []
|
157
158
|
rubyforge_project:
|
158
159
|
rubygems_version: 1.8.17
|