rack-mini-profiler 0.1.28 → 0.1.29

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd8393bb0afbc59162f9ece7f63b47218f742127
4
- data.tar.gz: 4f29c3a0407eb08c0b5146eea018919dc6620db8
3
+ metadata.gz: ca3a413c784a90f894e6ae5b6025f9203d161d1f
4
+ data.tar.gz: 570faec20b83dc6069a7b91fb065835668093ad9
5
5
  SHA512:
6
- metadata.gz: 0276de7ece6f3f8a70a4ce085ddb36a209385b1e3892c147057d6629922b4ea90e33177fc1093c72c08bf2de156585cff6b95576733c1cc906cf7cd4cd16000f
7
- data.tar.gz: f9accaad19036dde64fdacb1c86ddd15892d97e778ce079bd579bdbe78df508b41716fecc17e0b3176887002caef63f6cc9f37c6384f12ecc233bb170a384863
6
+ metadata.gz: c2c03d9750cfa1411b78993f16303bdb836a81b741cfea22cccc6209df9c506b6cf020cd0c3409fe77c869009fded27316683ded937b02759b990dbc5dde4a27
7
+ data.tar.gz: ba89510aba2923e06632876f740242325e26ebecd48d231b4fcef03cfe1a1417878eba48c63c0ca7d1e040ba029ff2493afdc0e1ff764be6d91fbb1c2c2abf20
@@ -143,5 +143,10 @@
143
143
  ?pp=env and others
144
144
  * SOLR xml unescaped by mistake
145
145
 
146
+ 20-August-2013
147
+ * 1.29
148
+ * Bugfix: SOLR patching had an incorrect monkey patch
149
+ * Implemented exception tracing using TracePoint see pp=trace-exceptions
150
+
146
151
 
147
152
 
@@ -267,8 +267,19 @@ module Rack
267
267
  }
268
268
  end
269
269
 
270
- status, headers, body = nil
270
+ trace_exceptions = query_string =~ /pp=trace-exceptions/ && defined? TracePoint
271
+ status, headers, body, exceptions,trace = nil
272
+
271
273
  start = Time.now
274
+
275
+ if trace_exceptions
276
+ exceptions = []
277
+ trace = TracePoint.new(:raise) do |tp|
278
+ exceptions << tp.raised_exception
279
+ end
280
+ trace.enable
281
+ end
282
+
272
283
  begin
273
284
 
274
285
  # Strip all the caching headers so we don't get 304s back
@@ -279,6 +290,8 @@ module Rack
279
290
  status,headers,body = @app.call(env)
280
291
  client_settings.write!(headers)
281
292
  ensure
293
+ trace.disable if trace
294
+
282
295
  if backtraces
283
296
  done_sampling = true
284
297
  sleep 0.001 until quit_sampler
@@ -299,6 +312,11 @@ module Rack
299
312
  return [status,headers,body] if skip_it
300
313
 
301
314
  # we must do this here, otherwise current[:discard] is not being properly treated
315
+ if trace_exceptions
316
+ body.close if body.respond_to? :close
317
+ return dump_exceptions exceptions
318
+ end
319
+
302
320
  if query_string =~ /pp=env/
303
321
  body.close if body.respond_to? :close
304
322
  return dump_env env
@@ -327,44 +345,52 @@ module Rack
327
345
  @storage.set_unviewed(page_struct['User'], page_struct['Id'])
328
346
  @storage.save(page_struct)
329
347
 
330
- content_type = headers['Content-Type']
331
348
  # inject headers, script
332
- if content_type && status == 200
333
-
349
+ if headers['Content-Type'] && status == 200
334
350
  client_settings.write!(headers)
335
351
 
336
- # mini profiler is meddling with stuff, we can not cache cause we will get incorrect data
337
- # Rack::ETag has already inserted some nonesense in the chain
338
- headers.delete('ETag')
339
- headers.delete('Date')
340
- headers['Cache-Control'] = 'must-revalidate, private, max-age=0'
341
-
342
- # inject header
343
- if headers.is_a? Hash
344
- headers['X-MiniProfiler-Ids'] = ids_json(env)
345
- end
346
-
347
- if current.inject_js && content_type =~ /text\/html/
348
- response = Rack::Response.new([], status, headers)
349
- script = self.get_profile_script(env)
350
-
351
- if String === body
352
- response.write inject(body,script)
353
- else
354
- body.each { |fragment| response.write inject(fragment, script) }
355
- end
356
- body.close if body.respond_to? :close
357
- return response.finish
358
- end
352
+ result = inject_profiler(env,status,headers,body)
353
+ return result if result
359
354
  end
360
355
 
361
356
  client_settings.write!(headers)
362
357
  [status, headers, body]
358
+
363
359
  ensure
364
360
  # Make sure this always happens
365
361
  current = nil
366
362
  end
367
363
 
364
+ def inject_profiler(env,status,headers,body)
365
+ # mini profiler is meddling with stuff, we can not cache cause we will get incorrect data
366
+ # Rack::ETag has already inserted some nonesense in the chain
367
+ content_type = headers['Content-Type']
368
+
369
+ headers.delete('ETag')
370
+ headers.delete('Date')
371
+ headers['Cache-Control'] = 'must-revalidate, private, max-age=0'
372
+
373
+ # inject header
374
+ if headers.is_a? Hash
375
+ headers['X-MiniProfiler-Ids'] = ids_json(env)
376
+ end
377
+
378
+ if current.inject_js && content_type =~ /text\/html/
379
+ response = Rack::Response.new([], status, headers)
380
+ script = self.get_profile_script(env)
381
+
382
+ if String === body
383
+ response.write inject(body,script)
384
+ else
385
+ body.each { |fragment| response.write inject(fragment, script) }
386
+ end
387
+ body.close if body.respond_to? :close
388
+ response.finish
389
+ else
390
+ nil
391
+ end
392
+ end
393
+
368
394
  def inject(fragment, script)
369
395
  if fragment.match(/<\/body>/i)
370
396
  # explicit </body>
@@ -402,6 +428,16 @@ module Rack
402
428
  end
403
429
  end
404
430
 
431
+ def dump_exceptions(exceptions)
432
+ headers = {'Content-Type' => 'text/plain'}
433
+ body = "Exceptions (#{exceptions.length} raised during request)\n\n"
434
+ exceptions.each do |e|
435
+ body << "#{e.class} #{e.message}\n#{e.backtrace.join("\n")}\n\n\n\n"
436
+ end
437
+
438
+ [200, headers, [body]]
439
+ end
440
+
405
441
  def dump_env(env)
406
442
  headers = {'Content-Type' => 'text/plain'}
407
443
  body = "Rack Environment\n---------------\n"
@@ -438,6 +474,7 @@ module Rack
438
474
  pp=profile-gc: perform gc profiling on this request, analyzes ObjectSpace generated by request (ruby 1.9.3 only)
439
475
  pp=profile-gc-time: perform built-in gc profiling on this request (ruby 1.9.3 only)
440
476
  pp=flamegraph: works best on Ruby 2.0, a graph representing sampled activity.
477
+ pp=trace-exceptions: requires Ruby 2.0, will return all the spots where your application raises execptions
441
478
  "
442
479
 
443
480
  client_settings.write!(headers)
@@ -200,7 +200,7 @@ if SqlPatches.class_exists?("RSolr::Connection") && RSolr::VERSION[0] != "0" #
200
200
 
201
201
  data = "#{request_context[:method].upcase} #{request_context[:uri]}"
202
202
  if request_context[:method] == :post and request_context[:data]
203
- if request_context[:headers].include("Content-Type") and request_context[:headers]["Content-Type"] == "text/xml"
203
+ if request_context[:headers].include?("Content-Type") and request_context[:headers]["Content-Type"] == "text/xml"
204
204
  # it's xml, unescaping isn't needed
205
205
  data << "\n#{request_context[:data]}"
206
206
  else
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rack-mini-profiler"
3
- s.version = "0.1.28"
3
+ s.version = "0.1.29"
4
4
  s.summary = "Profiles loading speed for rack applications."
5
5
  s.authors = ["Sam Saffron", "Robin Ward","Aleks Totic"]
6
6
  s.description = "Profiling toolkit for Rack applications with Rails integration. Client Side profiling, DB profiling and Server profiling."
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: 0.1.28
4
+ version: 0.1.29
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: 2013-07-30 00:00:00.000000000 Z
13
+ date: 2013-08-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack