rack-mini-profiler 0.1.15.pre → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack-mini-profiler might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -69,3 +69,10 @@
69
69
  * 1.15.pre
70
70
  * fixed annoying bug where client settings were not sticking
71
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
@@ -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>
@@ -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
 
@@ -167,6 +167,7 @@ module Rack
167
167
 
168
168
 
169
169
  def call(env)
170
+
170
171
  client_settings = ClientSettings.new(env)
171
172
 
172
173
  status = headers = body = nil
@@ -224,17 +225,30 @@ module Rack
224
225
  done_sampling = false
225
226
  quit_sampler = false
226
227
  backtraces = nil
227
- missing_stacktrace = false
228
+ stacktrace_installed = true
228
229
  if query_string =~ /pp=sample/
230
+ skip_frames = 0
229
231
  backtraces = []
230
232
  t = Thread.current
233
+
234
+ begin
235
+ require 'stacktrace'
236
+ skip_frames = stacktrace.length
237
+ rescue
238
+ stacktrace_installed = false
239
+ end
240
+
231
241
  Thread.new {
232
242
  begin
233
243
  i = 10000 # for sanity never grab more than 10k samples
234
244
  while i > 0
235
245
  break if done_sampling
236
246
  i -= 1
237
- 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
238
252
  sleep 0.001
239
253
  end
240
254
  ensure
@@ -263,10 +277,14 @@ module Rack
263
277
 
264
278
  skip_it = current.discard
265
279
  if (config.authorization_mode == :whitelist && !MiniProfiler.request_authorized?)
266
- 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
267
285
  skip_it = true
268
286
  end
269
-
287
+
270
288
  return [status,headers,body] if skip_it
271
289
 
272
290
  # we must do this here, otherwise current[:discard] is not being properly treated
@@ -285,7 +303,6 @@ module Rack
285
303
 
286
304
  if backtraces
287
305
  body.close if body.respond_to? :close
288
- return help(:stacktrace, client_settings) if missing_stacktrace
289
306
  return analyze(backtraces, page_struct)
290
307
  end
291
308
 
@@ -365,7 +382,7 @@ module Rack
365
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)
366
383
  pp=normal-backtrace #{"(*) " if client_settings.backtrace_default?}: collect stack traces from all the SQL executed and filter normally
367
384
  pp=full-backtrace #{"(*) " if client_settings.backtrace_full?}: enable full backtraces for SQL executed (use pp=normal-backtrace to disable)
368
- 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)
369
386
  pp=disable : disable profiling for this session
370
387
  pp=enable : enable profiling for this session (if previously disabled)
371
388
  "
@@ -387,6 +404,7 @@ module Rack
387
404
  fulldump << "\n\n"
388
405
  distinct = {}
389
406
  trace.each do |frame|
407
+ frame = "#{frame.klass}::#{frame.method}" unless String === frame
390
408
  unless distinct[frame]
391
409
  distinct[frame] = true
392
410
  seen[frame] ||= 0
@@ -26,8 +26,11 @@ module Rack
26
26
  end
27
27
 
28
28
  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
29
+
30
+ clean = clean_method_name(method)
31
+
32
+ with_profiling = ("#{clean}_with_mini_profiler").intern
33
+ without_profiling = ("#{clean}_without_mini_profiler").intern
31
34
 
32
35
  if klass.send :method_defined?, with_profiling
33
36
  klass.send :alias_method, method, without_profiling
@@ -38,8 +41,10 @@ module Rack
38
41
 
39
42
  def profile_method(klass, method, &blk)
40
43
  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
44
+ clean = clean_method_name(method)
45
+
46
+ with_profiling = ("#{clean}_with_mini_profiler").intern
47
+ without_profiling = ("#{clean}_without_mini_profiler").intern
43
48
 
44
49
  if klass.send :method_defined?, with_profiling
45
50
  return # dont double profile
@@ -67,6 +72,13 @@ module Rack
67
72
  end
68
73
  klass.send :alias_method, method, with_profiling
69
74
  end
75
+
76
+ private
77
+
78
+ def clean_method_name(method)
79
+ method.to_s.gsub(/[\?\!]/, "")
80
+ end
81
+
70
82
  end
71
83
  end
72
84
  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.15.pre"
3
+ s.version = "0.1.16"
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.15.pre
5
- prerelease: 7
4
+ version: 0.1.16
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-04 00:00:00.000000000 Z
14
+ date: 2012-09-05 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: 439688077
134
+ hash: 1044164429
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: 1044164429
141
144
  requirements: []
142
145
  rubyforge_project:
143
146
  rubygems_version: 1.8.24