rack-mini-profiler 0.9.2 → 0.9.3
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.
Potentially problematic release.
This version of rack-mini-profiler might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +17 -3
- data/lib/html/includes.css +15 -4
- data/lib/html/includes.js +93 -58
- data/lib/html/includes.less +21 -5
- data/lib/html/includes.tmpl +49 -49
- data/lib/html/list.tmpl +8 -8
- data/lib/mini_profiler/asset_version.rb +5 -0
- data/lib/mini_profiler/client_settings.rb +3 -3
- data/lib/mini_profiler/config.rb +11 -11
- data/lib/mini_profiler/gc_profiler.rb +10 -10
- data/lib/mini_profiler/profiler.rb +49 -71
- data/lib/mini_profiler/profiling_methods.rb +15 -17
- data/lib/mini_profiler/storage/file_store.rb +4 -4
- data/lib/mini_profiler/storage/memcache_store.rb +5 -7
- data/lib/mini_profiler/storage/memory_store.rb +56 -27
- data/lib/mini_profiler/storage/redis_store.rb +19 -11
- data/lib/mini_profiler/timer_struct/base.rb +33 -0
- data/lib/mini_profiler/timer_struct/client.rb +89 -0
- data/lib/mini_profiler/timer_struct/custom.rb +22 -0
- data/lib/mini_profiler/timer_struct/page.rb +62 -0
- data/lib/mini_profiler/timer_struct/request.rb +126 -0
- data/lib/mini_profiler/timer_struct/sql.rb +59 -0
- data/lib/mini_profiler/version.rb +2 -2
- data/lib/patches/db/activerecord.rb +42 -0
- data/lib/patches/db/moped.rb +12 -0
- data/lib/patches/db/mysql2.rb +30 -0
- data/lib/patches/db/pg.rb +104 -0
- data/lib/patches/db/plucky.rb +47 -0
- data/lib/patches/db/rsolr.rb +24 -0
- data/lib/patches/db/sequel.rb +10 -0
- data/lib/patches/sql_patches.rb +17 -255
- data/lib/rack-mini-profiler.rb +28 -0
- data/rack-mini-profiler.gemspec +6 -2
- metadata +16 -8
- data/lib/mini_profiler/client_timer_struct.rb +0 -78
- data/lib/mini_profiler/custom_timer_struct.rb +0 -22
- data/lib/mini_profiler/page_timer_struct.rb +0 -58
- data/lib/mini_profiler/request_timer_struct.rb +0 -115
- data/lib/mini_profiler/sql_timer_struct.rb +0 -58
- data/lib/mini_profiler/timer_struct.rb +0 -33
data/lib/html/list.tmpl
CHANGED
@@ -19,14 +19,14 @@
|
|
19
19
|
<script id="rowTemplate" type="text/x-jquery-tmpl">
|
20
20
|
<tr>
|
21
21
|
<td>
|
22
|
-
<a href="${MiniProfiler.path}results?id=${
|
23
|
-
<td class="date">${MiniProfiler.renderDate(
|
24
|
-
<td class="time">${
|
25
|
-
<td class="time">${
|
26
|
-
{{if
|
27
|
-
<td class="time">${MiniProfiler.getClientTimingByName(
|
28
|
-
<td class="time">${MiniProfiler.getClientTimingByName(
|
29
|
-
<td class="time">${MiniProfiler.getClientTimingByName(
|
22
|
+
<a href="${MiniProfiler.path}results?id=${id}">${name}</a></td>
|
23
|
+
<td class="date">${MiniProfiler.renderDate(started)}</td>
|
24
|
+
<td class="time">${duration_milliseconds_in_sql}</td>
|
25
|
+
<td class="time">${duration_milliseconds}</td>
|
26
|
+
{{if client_timings}}
|
27
|
+
<td class="time">${MiniProfiler.getClientTimingByName(client_timings,"Request").start}</td>
|
28
|
+
<td class="time">${MiniProfiler.getClientTimingByName(client_timings,"Response").start}</td>
|
29
|
+
<td class="time">${MiniProfiler.getClientTimingByName(client_timings,"Dom Complete").start}</td>
|
30
30
|
{{else}}
|
31
31
|
<td colspan="3"></td>
|
32
32
|
{{/if}}
|
@@ -5,8 +5,8 @@ module Rack
|
|
5
5
|
COOKIE_NAME = "__profilin"
|
6
6
|
|
7
7
|
BACKTRACE_DEFAULT = nil
|
8
|
-
BACKTRACE_FULL
|
9
|
-
BACKTRACE_NONE
|
8
|
+
BACKTRACE_FULL = 1
|
9
|
+
BACKTRACE_NONE = 2
|
10
10
|
|
11
11
|
attr_accessor :disable_profiling
|
12
12
|
attr_accessor :backtrace_level
|
@@ -30,7 +30,7 @@ module Rack
|
|
30
30
|
def write!(headers)
|
31
31
|
if @orig_disable_profiling != @disable_profiling || @orig_backtrace_level != @backtrace_level || @cookie.nil?
|
32
32
|
settings = {"p" => "t" }
|
33
|
-
settings["dp"] = "t"
|
33
|
+
settings["dp"] = "t" if @disable_profiling
|
34
34
|
settings["bt"] = @backtrace_level if @backtrace_level
|
35
35
|
settings_string = settings.map{|k,v| "#{k}=#{v}"}.join(",")
|
36
36
|
Rack::Utils.set_cookie_header!(headers, COOKIE_NAME, :value => settings_string, :path => '/')
|
data/lib/mini_profiler/config.rb
CHANGED
@@ -13,7 +13,7 @@ module Rack
|
|
13
13
|
end
|
14
14
|
|
15
15
|
attr_accessor :authorization_mode, :auto_inject, :backtrace_ignores, :backtrace_includes, :backtrace_remove,
|
16
|
-
:backtrace_threshold_ms, :base_url_path, :enabled, :flamegraph_sample_rate, :logger, :position,
|
16
|
+
:backtrace_threshold_ms, :base_url_path, :disable_caching, :enabled, :flamegraph_sample_rate, :logger, :position,
|
17
17
|
:pre_authorize_cb, :skip_paths, :skip_schema_queries, :start_hidden, :storage, :storage_failure,
|
18
18
|
:storage_instance, :storage_options, :toggle_shortcut, :user_provider
|
19
19
|
|
@@ -22,20 +22,20 @@ module Rack
|
|
22
22
|
|
23
23
|
def self.default
|
24
24
|
new.instance_eval {
|
25
|
-
@auto_inject
|
26
|
-
@base_url_path
|
27
|
-
|
25
|
+
@auto_inject = true # automatically inject on every html page
|
26
|
+
@base_url_path = "/mini-profiler-resources/"
|
27
|
+
@disable_caching = true
|
28
28
|
# called prior to rack chain, to ensure we are allowed to profile
|
29
29
|
@pre_authorize_cb = lambda {|env| true}
|
30
30
|
|
31
31
|
# called after rack chain, to ensure we are REALLY allowed to profile
|
32
|
-
@position
|
33
|
-
@skip_schema_queries
|
34
|
-
@storage
|
35
|
-
@user_provider
|
36
|
-
@authorization_mode
|
37
|
-
@toggle_shortcut
|
38
|
-
@start_hidden
|
32
|
+
@position = 'left' # Where it is displayed
|
33
|
+
@skip_schema_queries = false
|
34
|
+
@storage = MiniProfiler::MemoryStore
|
35
|
+
@user_provider = Proc.new{|env| Rack::Request.new(env).ip}
|
36
|
+
@authorization_mode = :allow_all
|
37
|
+
@toggle_shortcut = 'Alt+P'
|
38
|
+
@start_hidden = false
|
39
39
|
@backtrace_threshold_ms = 0
|
40
40
|
@flamegraph_sample_rate = 0.5
|
41
41
|
@storage_failure = Proc.new do |exception|
|
@@ -37,7 +37,7 @@ class Rack::MiniProfiler::GCProfiler
|
|
37
37
|
result
|
38
38
|
end
|
39
39
|
|
40
|
-
def diff_object_stats(before,after)
|
40
|
+
def diff_object_stats(before, after)
|
41
41
|
diff = {}
|
42
42
|
after.each do |k,v|
|
43
43
|
diff[k] = v - (before[k] || 0)
|
@@ -49,7 +49,7 @@ class Rack::MiniProfiler::GCProfiler
|
|
49
49
|
diff
|
50
50
|
end
|
51
51
|
|
52
|
-
def analyze_strings(ids_before,ids_after)
|
52
|
+
def analyze_strings(ids_before, ids_after)
|
53
53
|
result = {}
|
54
54
|
ids_after.each do |id,_|
|
55
55
|
obj = ObjectSpace._id2ref(id)
|
@@ -92,13 +92,13 @@ class Rack::MiniProfiler::GCProfiler
|
|
92
92
|
[objects,memory_allocated]
|
93
93
|
end
|
94
94
|
|
95
|
-
def profile_gc_time(app,env)
|
95
|
+
def profile_gc_time(app, env)
|
96
96
|
body = []
|
97
97
|
|
98
98
|
begin
|
99
99
|
GC::Profiler.clear
|
100
100
|
prev_profiler_state = GC::Profiler.enabled?
|
101
|
-
prev_gc_state
|
101
|
+
prev_gc_state = GC.enable
|
102
102
|
GC::Profiler.enable
|
103
103
|
b = app.call(env)[2]
|
104
104
|
b.close if b.respond_to? :close
|
@@ -112,7 +112,7 @@ class Rack::MiniProfiler::GCProfiler
|
|
112
112
|
return [200, {'Content-Type' => 'text/plain'}, body]
|
113
113
|
end
|
114
114
|
|
115
|
-
def profile_gc(app,env)
|
115
|
+
def profile_gc(app, env)
|
116
116
|
|
117
117
|
# for memsize_of
|
118
118
|
require 'objspace'
|
@@ -124,17 +124,17 @@ class Rack::MiniProfiler::GCProfiler
|
|
124
124
|
|
125
125
|
# clean up before
|
126
126
|
GC.start
|
127
|
-
stat
|
127
|
+
stat = GC.stat
|
128
128
|
prev_gc_state = GC.disable
|
129
|
-
stat_before
|
130
|
-
b
|
129
|
+
stat_before = object_space_stats
|
130
|
+
b = app.call(env)[2]
|
131
131
|
b.close if b.respond_to? :close
|
132
132
|
stat_after = object_space_stats
|
133
133
|
# so we don't blow out on memory
|
134
134
|
prev_gc_state ? GC.disable : GC.enable
|
135
135
|
|
136
|
-
diff
|
137
|
-
string_analysis
|
136
|
+
diff = diff_object_stats(stat_before[:stats],stat_after[:stats])
|
137
|
+
string_analysis = analyze_strings(stat_before[:ids], stat_after[:ids])
|
138
138
|
new_objects, memory_allocated = analyze_growth(stat_before[:ids], stat_after[:ids])
|
139
139
|
objects_before, memory_before = analyze_initial_state(stat_before[:ids])
|
140
140
|
|
@@ -1,30 +1,5 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'timeout'
|
3
|
-
require 'thread'
|
4
|
-
|
5
|
-
require 'mini_profiler/version'
|
6
|
-
require 'mini_profiler/page_timer_struct'
|
7
|
-
require 'mini_profiler/sql_timer_struct'
|
8
|
-
require 'mini_profiler/custom_timer_struct'
|
9
|
-
require 'mini_profiler/client_timer_struct'
|
10
|
-
require 'mini_profiler/request_timer_struct'
|
11
|
-
require 'mini_profiler/storage/abstract_store'
|
12
|
-
require 'mini_profiler/storage/memcache_store'
|
13
|
-
require 'mini_profiler/storage/memory_store'
|
14
|
-
require 'mini_profiler/storage/redis_store'
|
15
|
-
require 'mini_profiler/storage/file_store'
|
16
|
-
require 'mini_profiler/config'
|
17
|
-
require 'mini_profiler/profiling_methods'
|
18
|
-
require 'mini_profiler/context'
|
19
|
-
require 'mini_profiler/client_settings'
|
20
|
-
require 'mini_profiler/gc_profiler'
|
21
|
-
# TODO
|
22
|
-
# require 'mini_profiler/gc_profiler_ruby_head' if Gem::Version.new('2.1.0') <= Gem::Version.new(RUBY_VERSION)
|
23
|
-
|
24
1
|
module Rack
|
25
|
-
|
26
2
|
class MiniProfiler
|
27
|
-
|
28
3
|
class << self
|
29
4
|
|
30
5
|
include Rack::MiniProfiler::ProfilingMethods
|
@@ -43,8 +18,7 @@ module Rack
|
|
43
18
|
end
|
44
19
|
|
45
20
|
def share_template
|
46
|
-
|
47
|
-
@share_template = ::File.read(::File.expand_path("../html/share.html", ::File.dirname(__FILE__)))
|
21
|
+
@share_template ||= ::File.read(::File.expand_path("../html/share.html", ::File.dirname(__FILE__)))
|
48
22
|
end
|
49
23
|
|
50
24
|
def current
|
@@ -53,7 +27,7 @@ module Rack
|
|
53
27
|
|
54
28
|
def current=(c)
|
55
29
|
# we use TLS cause we need access to this from sql blocks and code blocks that have no access to env
|
56
|
-
Thread.current[:mini_profiler_private]= c
|
30
|
+
Thread.current[:mini_profiler_private] = c
|
57
31
|
end
|
58
32
|
|
59
33
|
# discard existing results, don't track this request
|
@@ -63,10 +37,10 @@ module Rack
|
|
63
37
|
|
64
38
|
def create_current(env={}, options={})
|
65
39
|
# profiling the request
|
66
|
-
self.current
|
67
|
-
self.current.inject_js
|
68
|
-
self.current.page_struct
|
69
|
-
self.current.current_timer = current.page_struct[
|
40
|
+
self.current = Context.new
|
41
|
+
self.current.inject_js = config.auto_inject && (!env['HTTP_X_REQUESTED_WITH'].eql? 'XMLHttpRequest')
|
42
|
+
self.current.page_struct = TimerStruct::Page.new(env)
|
43
|
+
self.current.current_timer = current.page_struct[:root]
|
70
44
|
end
|
71
45
|
|
72
46
|
def authorize_request
|
@@ -89,7 +63,7 @@ module Rack
|
|
89
63
|
def initialize(app, config = nil)
|
90
64
|
MiniProfiler.config.merge!(config)
|
91
65
|
@config = MiniProfiler.config
|
92
|
-
@app
|
66
|
+
@app = app
|
93
67
|
@config.base_url_path << "/" unless @config.base_url_path.end_with? "/"
|
94
68
|
unless @config.storage_instance
|
95
69
|
@config.storage_instance = @config.storage.new(@config.storage_options)
|
@@ -102,18 +76,18 @@ module Rack
|
|
102
76
|
end
|
103
77
|
|
104
78
|
def serve_results(env)
|
105
|
-
request
|
106
|
-
id
|
79
|
+
request = Rack::Request.new(env)
|
80
|
+
id = request[:id]
|
107
81
|
page_struct = @storage.load(id)
|
108
82
|
unless page_struct
|
109
83
|
@storage.set_viewed(user(env), id)
|
110
|
-
id
|
84
|
+
id = ERB::Util.html_escape(request['id'])
|
111
85
|
user_info = ERB::Util.html_escape(user(env))
|
112
86
|
return [404, {}, ["Request not found: #{id} - user #{user_info}"]]
|
113
87
|
end
|
114
|
-
unless page_struct[
|
115
|
-
page_struct[
|
116
|
-
page_struct[
|
88
|
+
unless page_struct[:has_user_viewed]
|
89
|
+
page_struct[:client_timings] = TimerStruct::Client.init_from_form_data(env, page_struct)
|
90
|
+
page_struct[:has_user_viewed] = true
|
117
91
|
@storage.save(page_struct)
|
118
92
|
@storage.set_viewed(user(env), id)
|
119
93
|
end
|
@@ -127,10 +101,10 @@ module Rack
|
|
127
101
|
# Otherwise give the HTML back
|
128
102
|
html = MiniProfiler.share_template.dup
|
129
103
|
html.gsub!(/\{path\}/, "#{env['SCRIPT_NAME']}#{@config.base_url_path}")
|
130
|
-
html.gsub!(/\{version\}/, MiniProfiler::
|
104
|
+
html.gsub!(/\{version\}/, MiniProfiler::ASSET_VERSION)
|
131
105
|
html.gsub!(/\{json\}/, result_json)
|
132
106
|
html.gsub!(/\{includes\}/, get_profile_script(env))
|
133
|
-
html.gsub!(/\{name\}/, page_struct[
|
107
|
+
html.gsub!(/\{name\}/, page_struct[:name])
|
134
108
|
html.gsub!(/\{duration\}/, "%.1f" % page_struct.duration_ms)
|
135
109
|
|
136
110
|
[200, {'Content-Type' => 'text/html'}, [html]]
|
@@ -145,7 +119,7 @@ module Rack
|
|
145
119
|
|
146
120
|
full_path = ::File.expand_path("../html/#{file_name}", ::File.dirname(__FILE__))
|
147
121
|
return [404, {}, ["Not found"]] unless ::File.exists? full_path
|
148
|
-
f
|
122
|
+
f = Rack::File.new nil
|
149
123
|
f.path = full_path
|
150
124
|
|
151
125
|
begin
|
@@ -166,7 +140,7 @@ module Rack
|
|
166
140
|
end
|
167
141
|
|
168
142
|
def current=(c)
|
169
|
-
MiniProfiler.current=c
|
143
|
+
MiniProfiler.current = c
|
170
144
|
end
|
171
145
|
|
172
146
|
|
@@ -181,7 +155,7 @@ module Rack
|
|
181
155
|
|
182
156
|
status = headers = body = nil
|
183
157
|
query_string = env['QUERY_STRING']
|
184
|
-
path
|
158
|
+
path = env['PATH_INFO']
|
185
159
|
|
186
160
|
skip_it = (@config.pre_authorize_cb && !@config.pre_authorize_cb.call(env)) ||
|
187
161
|
(@config.skip_paths && @config.skip_paths.any?{ |p| path[0,p.length] == p}) ||
|
@@ -262,7 +236,7 @@ module Rack
|
|
262
236
|
|
263
237
|
if trace_exceptions
|
264
238
|
exceptions = []
|
265
|
-
trace
|
239
|
+
trace = TracePoint.new(:raise) do |tp|
|
266
240
|
exceptions << tp.raised_exception
|
267
241
|
end
|
268
242
|
trace.enable
|
@@ -272,8 +246,10 @@ module Rack
|
|
272
246
|
|
273
247
|
# Strip all the caching headers so we don't get 304s back
|
274
248
|
# This solves a very annoying bug where rack mini profiler never shows up
|
275
|
-
|
276
|
-
|
249
|
+
if config.disable_caching
|
250
|
+
env['HTTP_IF_MODIFIED_SINCE'] = ''
|
251
|
+
env['HTTP_IF_NONE_MATCH'] = ''
|
252
|
+
end
|
277
253
|
|
278
254
|
if query_string =~ /pp=flamegraph/
|
279
255
|
unless defined?(Flamegraph) && Flamegraph.respond_to?(:generate)
|
@@ -283,7 +259,7 @@ module Rack
|
|
283
259
|
else
|
284
260
|
# do not sully our profile with mini profiler timings
|
285
261
|
current.measure = false
|
286
|
-
match_data
|
262
|
+
match_data = query_string.match(/flamegraph_sample_rate=([\d\.]+)/)
|
287
263
|
|
288
264
|
mode = query_string =~ /mode=c/ ? :c : :ruby
|
289
265
|
|
@@ -334,8 +310,8 @@ module Rack
|
|
334
310
|
end
|
335
311
|
|
336
312
|
page_struct = current.page_struct
|
337
|
-
page_struct[
|
338
|
-
page_struct[
|
313
|
+
page_struct[:user] = user(env)
|
314
|
+
page_struct[:root].record_time((Time.now - start) * 1000)
|
339
315
|
|
340
316
|
if flamegraph
|
341
317
|
body.close if body.respond_to? :close
|
@@ -345,7 +321,7 @@ module Rack
|
|
345
321
|
|
346
322
|
begin
|
347
323
|
# no matter what it is, it should be unviewed, otherwise we will miss POST
|
348
|
-
@storage.set_unviewed(page_struct[
|
324
|
+
@storage.set_unviewed(page_struct[:user], page_struct[:id])
|
349
325
|
@storage.save(page_struct)
|
350
326
|
|
351
327
|
# inject headers, script
|
@@ -373,9 +349,12 @@ module Rack
|
|
373
349
|
# Rack::ETag has already inserted some nonesense in the chain
|
374
350
|
content_type = headers['Content-Type']
|
375
351
|
|
376
|
-
|
377
|
-
|
378
|
-
|
352
|
+
if config.disable_caching
|
353
|
+
headers.delete('ETag')
|
354
|
+
headers.delete('Date')
|
355
|
+
end
|
356
|
+
|
357
|
+
headers['Cache-Control'] = "#{"no-store, " if config.disable_caching}must-revalidate, private, max-age=0"
|
379
358
|
|
380
359
|
# inject header
|
381
360
|
if headers.is_a? Hash
|
@@ -384,7 +363,7 @@ module Rack
|
|
384
363
|
|
385
364
|
if current.inject_js && content_type =~ /text\/html/
|
386
365
|
response = Rack::Response.new([], status, headers)
|
387
|
-
script
|
366
|
+
script = self.get_profile_script(env)
|
388
367
|
|
389
368
|
if String === body
|
390
369
|
response.write inject(body,script)
|
@@ -437,7 +416,7 @@ module Rack
|
|
437
416
|
|
438
417
|
def dump_exceptions(exceptions)
|
439
418
|
headers = {'Content-Type' => 'text/plain'}
|
440
|
-
body
|
419
|
+
body = "Exceptions (#{exceptions.length} raised during request)\n\n"
|
441
420
|
exceptions.each do |e|
|
442
421
|
body << "#{e.class} #{e.message}\n#{e.backtrace.join("\n")}\n\n\n\n"
|
443
422
|
end
|
@@ -504,7 +483,7 @@ module Rack
|
|
504
483
|
|
505
484
|
def ids(env)
|
506
485
|
# cap at 10 ids, otherwise there is a chance you can blow the header
|
507
|
-
([current.page_struct[
|
486
|
+
([current.page_struct[:id]] + (@storage.get_unviewed_ids(user(env)) || [])[0..8]).uniq
|
508
487
|
end
|
509
488
|
|
510
489
|
def ids_json(env)
|
@@ -522,25 +501,26 @@ module Rack
|
|
522
501
|
# * you have disabled auto append behaviour throught :auto_inject => false flag
|
523
502
|
# * you do not want script to be automatically appended for the current page. You can also call cancel_auto_inject
|
524
503
|
def get_profile_script(env)
|
504
|
+
path = "#{env['SCRIPT_NAME']}#{@config.base_url_path}"
|
525
505
|
|
526
506
|
settings = {
|
527
|
-
:path
|
528
|
-
:version
|
529
|
-
:position
|
530
|
-
:showTrivial
|
531
|
-
:showChildren
|
507
|
+
:path => path,
|
508
|
+
:version => MiniProfiler::ASSET_VERSION,
|
509
|
+
:position => @config.position,
|
510
|
+
:showTrivial => false,
|
511
|
+
:showChildren => false,
|
532
512
|
:maxTracesToShow => 10,
|
533
|
-
:showControls
|
534
|
-
:authorized
|
535
|
-
:toggleShortcut
|
536
|
-
:startHidden
|
513
|
+
:showControls => false,
|
514
|
+
:authorized => true,
|
515
|
+
:toggleShortcut => @config.toggle_shortcut,
|
516
|
+
:startHidden => @config.start_hidden
|
537
517
|
}
|
538
518
|
|
539
519
|
if current && current.page_struct
|
540
|
-
settings[:ids]
|
541
|
-
settings[:currentId] = current.page_struct[
|
520
|
+
settings[:ids] = ids_comma_separated(env)
|
521
|
+
settings[:currentId] = current.page_struct[:id]
|
542
522
|
else
|
543
|
-
settings[:ids]
|
523
|
+
settings[:ids] = []
|
544
524
|
settings[:currentId] = ""
|
545
525
|
end
|
546
526
|
|
@@ -562,6 +542,4 @@ module Rack
|
|
562
542
|
end
|
563
543
|
|
564
544
|
end
|
565
|
-
|
566
545
|
end
|
567
|
-
|
@@ -3,32 +3,30 @@ module Rack
|
|
3
3
|
module ProfilingMethods
|
4
4
|
|
5
5
|
def record_sql(query, elapsed_ms)
|
6
|
+
return unless current
|
6
7
|
c = current
|
7
|
-
return unless c
|
8
8
|
c.current_timer.add_sql(query, elapsed_ms, c.page_struct, c.skip_backtrace, c.full_backtrace) if (c && c.current_timer)
|
9
9
|
end
|
10
10
|
|
11
11
|
def start_step(name)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
12
|
+
return unless current
|
13
|
+
parent_timer = current.current_timer
|
14
|
+
current.current_timer = current_timer = current.current_timer.add_child(name)
|
15
|
+
[current_timer,parent_timer]
|
17
16
|
end
|
18
17
|
|
19
18
|
def finish_step(obj)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
19
|
+
return unless obj && current
|
20
|
+
current_timer, parent_timer = obj
|
21
|
+
current_timer.record_time
|
22
|
+
current.current_timer = parent_timer
|
25
23
|
end
|
26
24
|
|
27
25
|
# perform a profiling step on given block
|
28
26
|
def step(name, opts = nil)
|
29
27
|
if current
|
30
|
-
parent_timer
|
31
|
-
result
|
28
|
+
parent_timer = current.current_timer
|
29
|
+
result = nil
|
32
30
|
current.current_timer = current_timer = current.current_timer.add_child(name)
|
33
31
|
begin
|
34
32
|
result = yield if block_given?
|
@@ -65,9 +63,9 @@ module Rack
|
|
65
63
|
|
66
64
|
def profile_method(klass, method, type = :profile, &blk)
|
67
65
|
default_name = type==:counter ? method.to_s : klass.to_s + " " + method.to_s
|
68
|
-
clean
|
66
|
+
clean = clean_method_name(method)
|
69
67
|
|
70
|
-
with_profiling
|
68
|
+
with_profiling = ("#{clean}_with_mini_profiler").intern
|
71
69
|
without_profiling = ("#{clean}_without_mini_profiler").intern
|
72
70
|
|
73
71
|
if klass.send :method_defined?, with_profiling
|
@@ -131,8 +129,8 @@ module Rack
|
|
131
129
|
def counter(type, duration_ms=nil)
|
132
130
|
result = nil
|
133
131
|
if block_given?
|
134
|
-
start
|
135
|
-
result
|
132
|
+
start = Time.now
|
133
|
+
result = yield
|
136
134
|
duration_ms = (Time.now - start).to_f * 1000
|
137
135
|
end
|
138
136
|
return result if current.nil? || !request_authorized?
|