rack-mini-profiler 0.9.4 → 0.9.5
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/mini_profiler/profiler.rb +42 -8
- data/lib/mini_profiler/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9377633424424e89db32b3a32dac8e65a133558e
|
4
|
+
data.tar.gz: 4946cb1baa99559aee12e93ab62289d50efe9458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c25fe1d216a7f0ea2e641176557bc6e8ec3a33b3a244e8eab06f74e9d2b1a7092b511f09221fe0f2262e6cac3789d60c07a071d02abc7bf4639f439377e07c62
|
7
|
+
data.tar.gz: eec98bef439c1c455238a122eec88c8664fccfc4a6ef1be8574f973c0604f2fd95aa52eb1bc1c2aa9e1aa51b45b129a79482aedf4be8a3c73c35873d05352d85
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
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
|
-
|
498
|
+
string_counts = Hash.new(0)
|
499
|
+
sample_strings = []
|
477
500
|
|
478
|
-
|
479
|
-
|
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
|
-
|
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 <<
|
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
|