rack-mini-profiler 0.1.14.pre → 0.1.19

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.

data/CHANGELOG CHANGED
@@ -63,3 +63,21 @@
63
63
  * made pp=full-backtrace "sticky"
64
64
  * added pp=normal-backtrace to clear the "sticky" state
65
65
  * change "pp=sample" to work with "caller" no need for stack trace gem
66
+
67
+ 4-September-2012 - Sam
68
+
69
+ * 1.15.pre
70
+ * fixed annoying bug where client settings were not sticking
71
+ * fixed long standing issue with Rack::ConditionalGet stopping MiniProfiler from working properly
72
+
73
+ 5-September-2012 - Sam
74
+
75
+ * 1.16
76
+ * fixed long standing problem specs (issue with memory store)
77
+ * fixed issue where profiler would be dumped when you got a 404 in production (and any time rails is bypassed)
78
+ * implemented stacktrace properly
79
+
80
+ 9-September-2012 - Sam
81
+
82
+ * 1.17
83
+ * pp=sample was bust unless stacktrace was installed
@@ -138,7 +138,7 @@
138
138
  </td>
139
139
 
140
140
  {{if HasSqlTimings}}
141
- <td class="profiler-duration {{if HasDuplicateSqlTimings}}profiler-warning{{/if}}" title="{{if HasDuplicateSqlTimings}}duplicate queries detected - {{/if}}${ExecutedReaders} reader, ${ExecutedScalars} scalar, ${ExecutedNonQueries} non-query statements executed">
141
+ <td class="profiler-duration {{if HasDuplicateSqlTimings}}profiler-warning{{/if}}" title="{{if HasDuplicateSqlTimings}}duplicate queries detected - {{/if}}{{if ExecutedReaders > 0 || ExecutedScalars > 0 || ExecutedNonQueries > 0}}${ExecutedReaders} reader, ${ExecutedScalars} scalar, ${ExecutedNonQueries} non-query statements executed{{/if}}">
142
142
  <a class="profiler-queries-show">
143
143
  {{if HasDuplicateSqlTimings}}<span class="profiler-nuclear">!</span>{{/if}}
144
144
  ${SqlTimings.length} <span class="profiler-unit">sql</span>
@@ -33,12 +33,12 @@ module Rack
33
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
- Rack::Utils.set_cookie_header!(headers, COOKIE_NAME, :value => settings_string)
36
+ Rack::Utils.set_cookie_header!(headers, COOKIE_NAME, :value => settings_string, :path => '/')
37
37
  end
38
38
  end
39
39
 
40
40
  def discard_cookie!(headers)
41
- Rack::Utils.delete_cookie_header!(headers, COOKIE_NAME)
41
+ Rack::Utils.delete_cookie_header!(headers, COOKIE_NAME, :path => '/')
42
42
  end
43
43
 
44
44
  def has_cookie?
@@ -19,7 +19,7 @@ module Rack
19
19
 
20
20
  class MiniProfiler
21
21
 
22
- VERSION = '106'.freeze
22
+ VERSION = '107'.freeze
23
23
 
24
24
  class << self
25
25
 
@@ -225,17 +225,30 @@ module Rack
225
225
  done_sampling = false
226
226
  quit_sampler = false
227
227
  backtraces = nil
228
- missing_stacktrace = false
228
+ stacktrace_installed = true
229
229
  if query_string =~ /pp=sample/
230
+ skip_frames = 0
230
231
  backtraces = []
231
232
  t = Thread.current
233
+
234
+ begin
235
+ require 'stacktrace'
236
+ skip_frames = stacktrace.length
237
+ rescue LoadError
238
+ stacktrace_installed = false
239
+ end
240
+
232
241
  Thread.new {
233
242
  begin
234
243
  i = 10000 # for sanity never grab more than 10k samples
235
244
  while i > 0
236
245
  break if done_sampling
237
246
  i -= 1
238
- backtraces << t.backtrace
247
+ if stacktrace_installed
248
+ backtraces << t.stacktrace(0,-(1+skip_frames), StackFrame::Flags::METHOD | StackFrame::Flags::KLASS)
249
+ else
250
+ backtraces << t.backtrace
251
+ end
239
252
  sleep 0.001
240
253
  end
241
254
  ensure
@@ -247,6 +260,12 @@ module Rack
247
260
  status, headers, body = nil
248
261
  start = Time.now
249
262
  begin
263
+
264
+ # Strip all the caching headers so we don't get 304s back
265
+ # This solves a very annoying bug where rack mini profiler never shows up
266
+ env['HTTP_IF_MODIFIED_SINCE'] = nil
267
+ env['HTTP_IF_NONE_MATCH'] = nil
268
+
250
269
  status,headers,body = @app.call(env)
251
270
  client_settings.write!(headers)
252
271
  ensure
@@ -258,10 +277,14 @@ module Rack
258
277
 
259
278
  skip_it = current.discard
260
279
  if (config.authorization_mode == :whitelist && !MiniProfiler.request_authorized?)
261
- client_settings.discard_cookie!(headers)
280
+ # this is non-obvious, don't kill the profiling cookie on errors or short requests
281
+ # this ensures that stuff that never reaches the rails stack does not kill profiling
282
+ if status == 200 && ((Time.now - start) > 0.1)
283
+ client_settings.discard_cookie!(headers)
284
+ end
262
285
  skip_it = true
263
286
  end
264
-
287
+
265
288
  return [status,headers,body] if skip_it
266
289
 
267
290
  # we must do this here, otherwise current[:discard] is not being properly treated
@@ -272,7 +295,7 @@ module Rack
272
295
 
273
296
  if query_string =~ /pp=help/
274
297
  body.close if body.respond_to? :close
275
- return help(nil, client_settings)
298
+ return help(client_settings)
276
299
  end
277
300
 
278
301
  page_struct = current.page_struct
@@ -280,7 +303,6 @@ module Rack
280
303
 
281
304
  if backtraces
282
305
  body.close if body.respond_to? :close
283
- return help(:stacktrace, client_settings) if missing_stacktrace
284
306
  return analyze(backtraces, page_struct)
285
307
  end
286
308
 
@@ -350,7 +372,7 @@ module Rack
350
372
  [200, headers, [body]]
351
373
  end
352
374
 
353
- def help(category = nil, client_settings)
375
+ def help(client_settings)
354
376
  headers = {'Content-Type' => 'text/plain'}
355
377
  body = "Append the following to your query string:
356
378
 
@@ -360,13 +382,10 @@ module Rack
360
382
  pp=no-backtrace #{"(*) " if client_settings.backtrace_none?}: don't collect stack traces from all the SQL executed (sticky, use pp=normal-backtrace to enable)
361
383
  pp=normal-backtrace #{"(*) " if client_settings.backtrace_default?}: collect stack traces from all the SQL executed and filter normally
362
384
  pp=full-backtrace #{"(*) " if client_settings.backtrace_full?}: enable full backtraces for SQL executed (use pp=normal-backtrace to disable)
363
- pp=sample : sample stack traces and return a report isolating heavy usage (experimental)
385
+ pp=sample : sample stack traces and return a report isolating heavy usage (experimental works best with the stacktrace gem)
364
386
  pp=disable : disable profiling for this session
365
387
  pp=enable : enable profiling for this session (if previously disabled)
366
388
  "
367
- if (category == :stacktrace)
368
- body = "pp=stacktrace requires the stacktrace gem - add gem 'stacktrace' to your Gemfile"
369
- end
370
389
 
371
390
  client_settings.write!(headers)
372
391
  [200, headers, [body]]
@@ -382,6 +401,7 @@ module Rack
382
401
  fulldump << "\n\n"
383
402
  distinct = {}
384
403
  trace.each do |frame|
404
+ frame = "#{frame.klass}::#{frame.method}" unless String === frame
385
405
  unless distinct[frame]
386
406
  distinct[frame] = true
387
407
  seen[frame] ||= 0
@@ -8,6 +8,22 @@ module Rack
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
+ def start_step(name)
12
+ if current
13
+ parent_timer = current.current_timer
14
+ current.current_timer = current_timer = current.current_timer.add_child(name)
15
+ [current_timer,parent_timer]
16
+ end
17
+ end
18
+
19
+ def finish_step(obj)
20
+ if obj && current
21
+ current_timer, parent_timer = obj
22
+ current_timer.record_time
23
+ current.current_timer = parent_timer
24
+ end
25
+ end
26
+
11
27
  # perform a profiling step on given block
12
28
  def step(name, opts = nil)
13
29
  if current
@@ -26,8 +42,11 @@ module Rack
26
42
  end
27
43
 
28
44
  def unprofile_method(klass, method)
29
- with_profiling = (method.to_s + "_with_mini_profiler").intern
30
- without_profiling = (method.to_s + "_without_mini_profiler").intern
45
+
46
+ clean = clean_method_name(method)
47
+
48
+ with_profiling = ("#{clean}_with_mini_profiler").intern
49
+ without_profiling = ("#{clean}_without_mini_profiler").intern
31
50
 
32
51
  if klass.send :method_defined?, with_profiling
33
52
  klass.send :alias_method, method, without_profiling
@@ -38,8 +57,10 @@ module Rack
38
57
 
39
58
  def profile_method(klass, method, &blk)
40
59
  default_name = klass.to_s + " " + method.to_s
41
- with_profiling = (method.to_s + "_with_mini_profiler").intern
42
- without_profiling = (method.to_s + "_without_mini_profiler").intern
60
+ clean = clean_method_name(method)
61
+
62
+ with_profiling = ("#{clean}_with_mini_profiler").intern
63
+ without_profiling = ("#{clean}_without_mini_profiler").intern
43
64
 
44
65
  if klass.send :method_defined?, with_profiling
45
66
  return # dont double profile
@@ -67,6 +88,13 @@ module Rack
67
88
  end
68
89
  klass.send :alias_method, method, with_profiling
69
90
  end
91
+
92
+ private
93
+
94
+ def clean_method_name(method)
95
+ method.to_s.gsub(/[\?\!]/, "")
96
+ end
97
+
70
98
  end
71
99
  end
72
100
  end
@@ -55,7 +55,7 @@ module Rack
55
55
  def cleanup_cache
56
56
  expire_older_than = ((Time.now.to_f - MiniProfiler::MemoryStore::EXPIRE_TIMER_CACHE) * 1000).to_i
57
57
  @timer_struct_lock.synchronize {
58
- @timer_struct_cache.delete_if { |k, v| v['Root']['StartMilliseconds'] < expire_older_than }
58
+ @timer_struct_cache.delete_if { |k, v| v['Started'] < expire_older_than }
59
59
  }
60
60
  end
61
61
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rack-mini-profiler"
3
- s.version = "0.1.14.pre"
3
+ s.version = "0.1.19"
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,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mini-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14.pre
5
- prerelease: 7
4
+ version: 0.1.19
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Aleks Totic
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-09-03 00:00:00.000000000 Z
14
+ date: 2012-09-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rack
@@ -131,13 +131,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: -291023635
134
+ hash: -352003811
135
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  none: false
137
137
  requirements:
138
- - - ! '>'
138
+ - - ! '>='
139
139
  - !ruby/object:Gem::Version
140
- version: 1.3.1
140
+ version: '0'
141
+ segments:
142
+ - 0
143
+ hash: -352003811
141
144
  requirements: []
142
145
  rubyforge_project:
143
146
  rubygems_version: 1.8.24