rack-mini-profiler 0.9.4 → 0.9.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f6c4ad1e41a0b8cf00506f6c3d732a0a8ea2dc1
4
- data.tar.gz: 0a4e5b357dd0473b157ba8728c069cd165fbb99f
3
+ metadata.gz: 9377633424424e89db32b3a32dac8e65a133558e
4
+ data.tar.gz: 4946cb1baa99559aee12e93ab62289d50efe9458
5
5
  SHA512:
6
- metadata.gz: 91b62e7d1beec331e6d104bbf3efe4b2e267c1d93e83166d3289d15798e3a777f847e8f7a0d49f138098e3fea075dcc771b13691534087c6911cf08072e157ee
7
- data.tar.gz: 81115816fa927e35361804b8e8ef79148d39283cbf7b7609020dd993b811e7af4972f38b5c00d75a04f01eb3a3c1e33a2e0a3e5fbe74370efccd25694f069257
6
+ metadata.gz: c25fe1d216a7f0ea2e641176557bc6e8ec3a33b3a244e8eab06f74e9d2b1a7092b511f09221fe0f2262e6cac3789d60c07a071d02abc7bf4639f439377e07c62
7
+ data.tar.gz: eec98bef439c1c455238a122eec88c8664fccfc4a6ef1be8574f973c0604f2fd95aa52eb1bc1c2aa9e1aa51b45b129a79482aedf4be8a3c73c35873d05352d85
@@ -1,4 +1,9 @@
1
1
  # CHANGELOG
2
+
3
+ ## 0.9.5 - 2014-07-08 (Sam Saffron)
4
+
5
+ - [FEATURE] improve pp=analyze-memory
6
+
2
7
  ## 0.9.4 - 2014-07-08 (Sam Saffron)
3
8
  - [UX] added a link to "more" actions in profiler
4
9
  - [FEATURE] pp=help now displays links
@@ -463,23 +463,50 @@ module Rack
463
463
  def analyze_memory
464
464
  require 'objspace'
465
465
 
466
+ utf8 = "utf-8"
467
+
468
+ GC.start
469
+
470
+ trunc = lambda do |str|
471
+ str.length > 200 ? str : str[0..200]
472
+
473
+ if str.encoding != Encoding::UTF_8
474
+ str = str.dup
475
+ str.force_encoding(utf8)
476
+
477
+ unless str.valid_encoding?
478
+ # work around bust string with a double conversion
479
+ str.encode!("utf-16","utf-8",:invalid => :replace)
480
+ str.encode!("utf-8","utf-16")
481
+ end
482
+ end
483
+
484
+ str
485
+ end
486
+
466
487
  body = "ObjectSpace stats:\n\n"
467
488
 
468
- body << ObjectSpace.count_objects
489
+ counts = ObjectSpace.count_objects
490
+ total_strings = counts[:T_STRING]
491
+
492
+ body << counts
469
493
  .sort{|a,b| b[1] <=> a[1]}
470
494
  .map{|k,v| "#{k}: #{v}"}
471
495
  .join("\n")
472
496
 
473
- body << "\n\n\n1000 Largest strings:\n\n"
474
-
475
497
  strings = []
476
- max_size = 1000
498
+ string_counts = Hash.new(0)
499
+ sample_strings = []
477
500
 
478
- GC.start
479
- GC.start
501
+ max_size = 1000
502
+ sample_every = total_strings / max_size
480
503
 
504
+ i = 0
481
505
  ObjectSpace.each_object(String) do |str|
482
- strings << [str[0..200], str.length]
506
+ i += 1
507
+ string_counts[str] += 1
508
+ strings << [trunc.call(str), str.length]
509
+ sample_strings << [trunc.call(str), str.length] if i % sample_every == 0
483
510
  if strings.length > max_size * 2
484
511
  trim_strings(strings, max_size)
485
512
  end
@@ -487,7 +514,14 @@ module Rack
487
514
 
488
515
  trim_strings(strings, max_size)
489
516
 
490
- body << strings.map{|s,len| "#{s}\n(#{len})\n\n"}.join("\n")
517
+ body << "\n\n\n1000 Largest strings:\n\n"
518
+ body << strings.map{|s,len| "#{s}\n(len: #{len})\n\n"}.join("\n")
519
+
520
+ body << "\n\n\n1000 Sample strings:\n\n"
521
+ body << sample_strings.map{|s,len| "#{s}\n(len: #{len})\n\n"}.join("\n")
522
+
523
+ body << "\n\n\n1000 Most common strings:\n\n"
524
+ body << string_counts.sort{|a,b| b[1] <=> a[1]}[0..max_size].map{|s,len| "#{trunc.call(s)}\n(x #{len})\n\n"}.join("\n")
491
525
 
492
526
  text_result(body)
493
527
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class MiniProfiler
3
- VERSION = '0.9.4'
3
+ VERSION = '0.9.5'
4
4
  end
5
5
  end
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.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron