allocation_tracer 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/allocation_tracer/version.rb +1 -1
- data/lib/rack/allocation_tracer.rb +92 -92
- 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: 0490edb35cef102a8ae71d1bb580a4706e4fe54c
|
4
|
+
data.tar.gz: 757f80cbd164caccf83294f36bea9e6ad7f84d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3949336005c81e65fb067cc938276cc21d4fcc87c291b25a4d2afd2527e522e45879d390fb74dc00905514994a3031874edc2eaee761de1cf127dbe3d2807192
|
7
|
+
data.tar.gz: 7d89c07e3f732139d86610a28ab51dc42f4ef51478f20af324edfa012a90abdae94bc1527325f9ab164795fc61225a63ea0a648b746750e4e7f93d5a093a3999
|
data/README.md
CHANGED
@@ -215,7 +215,7 @@ current age.
|
|
215
215
|
|
216
216
|
## Rack middleware
|
217
217
|
|
218
|
-
You can use
|
218
|
+
You can use AllocationTracer via rack middleware.
|
219
219
|
|
220
220
|
```ruby
|
221
221
|
require 'rack'
|
@@ -229,7 +229,7 @@ get '/' do
|
|
229
229
|
end
|
230
230
|
```
|
231
231
|
|
232
|
-
When you access to `http://host/allocation_tracer/` then you can see table of allocation tracer.
|
232
|
+
When you access to `http://host/allocation_tracer/` then you can see a table of allocation tracer.
|
233
233
|
|
234
234
|
You can access the following pages.
|
235
235
|
|
@@ -1,92 +1,92 @@
|
|
1
|
-
#
|
2
|
-
# Rack middleware
|
3
|
-
#
|
4
|
-
|
5
|
-
require 'allocation_tracer'
|
6
|
-
|
7
|
-
module Rack
|
8
|
-
module AllocationTracerMiddleware
|
9
|
-
def self.new *args
|
10
|
-
TotalTracer.new *args
|
11
|
-
end
|
12
|
-
|
13
|
-
class Tracer
|
14
|
-
def initialize app
|
15
|
-
@app = app
|
16
|
-
@sort_order = (0..7).to_a
|
17
|
-
end
|
18
|
-
|
19
|
-
def allocation_trace_page result
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
"<
|
41
|
-
end
|
42
|
-
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
begin
|
74
|
-
[200, {"Content-Type" => "text/html"}, [text]]
|
75
|
-
ensure
|
76
|
-
ObjectSpace::AllocationTracer.resume
|
77
|
-
end
|
78
|
-
else
|
79
|
-
@app.call env
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class TotalTracer < Tracer
|
85
|
-
def initialize *args
|
86
|
-
super
|
87
|
-
ObjectSpace::AllocationTracer.setup %i(path line class)
|
88
|
-
ObjectSpace::AllocationTracer.start
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
1
|
+
#
|
2
|
+
# Rack middleware
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'allocation_tracer'
|
6
|
+
|
7
|
+
module Rack
|
8
|
+
module AllocationTracerMiddleware
|
9
|
+
def self.new *args
|
10
|
+
TotalTracer.new *args
|
11
|
+
end
|
12
|
+
|
13
|
+
class Tracer
|
14
|
+
def initialize app
|
15
|
+
@app = app
|
16
|
+
@sort_order = (0..7).to_a
|
17
|
+
end
|
18
|
+
|
19
|
+
def allocation_trace_page result, env
|
20
|
+
if /\As=(\d+)/ =~ env["QUERY_STRING"]
|
21
|
+
top = $1.to_i
|
22
|
+
@sort_order.unshift top if @sort_order.delete top
|
23
|
+
end
|
24
|
+
|
25
|
+
table = result.map{|(file, line, klass), (count, oldcount, total_age, min_age, max_age, memsize)|
|
26
|
+
["#{Rack::Utils.escape_html(file)}:#{'%04d' % line}",
|
27
|
+
klass ? klass.name : '<internal>',
|
28
|
+
count, oldcount, total_age / Float(count), min_age, max_age, memsize]
|
29
|
+
}.sort_by{|vs|
|
30
|
+
ary = @sort_order.map{|i| Numeric === vs[i] ? -vs[i] : vs[i]}
|
31
|
+
}
|
32
|
+
|
33
|
+
headers = %w(path class count old_count average_age max_age min_age memsize).map.with_index{|e, i|
|
34
|
+
"<th><a href='./?s=#{i}'>#{e}</a></th>"
|
35
|
+
}.join("\n")
|
36
|
+
header = "<tr>#{headers}</tr>"
|
37
|
+
body = table.map{|cols|
|
38
|
+
"<tr>" + cols.map{|c| "<td>#{c}</td>"}.join("\n") + "</tr>"
|
39
|
+
}.join("\n")
|
40
|
+
"<table>#{header}#{body}</table>"
|
41
|
+
end
|
42
|
+
|
43
|
+
def count_table_page count_table
|
44
|
+
text = count_table.map{|k, v| "%-10s\t%8d" % [k, v]}.join("\n")
|
45
|
+
"<pre>#{text}</pre>"
|
46
|
+
end
|
47
|
+
|
48
|
+
def allocated_count_table_page
|
49
|
+
count_table_page ObjectSpace::AllocationTracer.allocated_count_table
|
50
|
+
end
|
51
|
+
|
52
|
+
def freed_count_table_page
|
53
|
+
count_table_page ObjectSpace::AllocationTracer.freed_count_table
|
54
|
+
end
|
55
|
+
|
56
|
+
def call env
|
57
|
+
if /\A\/allocation_tracer\// =~ env["PATH_INFO"]
|
58
|
+
result = ObjectSpace::AllocationTracer.result
|
59
|
+
ObjectSpace::AllocationTracer.pause
|
60
|
+
|
61
|
+
p env["PATH_INFO"]
|
62
|
+
case env["PATH_INFO"]
|
63
|
+
when /lifetime_table/
|
64
|
+
raise "Unsupported: lifetime_table"
|
65
|
+
when /allocated_count_table/
|
66
|
+
text = allocated_count_table_page
|
67
|
+
when /freed_count_table/
|
68
|
+
text = freed_count_table_page
|
69
|
+
else
|
70
|
+
text = allocation_trace_page result, env
|
71
|
+
end
|
72
|
+
|
73
|
+
begin
|
74
|
+
[200, {"Content-Type" => "text/html"}, [text]]
|
75
|
+
ensure
|
76
|
+
ObjectSpace::AllocationTracer.resume
|
77
|
+
end
|
78
|
+
else
|
79
|
+
@app.call env
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class TotalTracer < Tracer
|
85
|
+
def initialize *args
|
86
|
+
super
|
87
|
+
ObjectSpace::AllocationTracer.setup %i(path line class)
|
88
|
+
ObjectSpace::AllocationTracer.start
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|