allocation_tracer 0.5.0 → 0.5.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00e9bb56504e9d79f1182f199aa74bcae77f8452
4
- data.tar.gz: 1847dac5c208e05f9e9bc05669d3371082fb0997
3
+ metadata.gz: 0490edb35cef102a8ae71d1bb580a4706e4fe54c
4
+ data.tar.gz: 757f80cbd164caccf83294f36bea9e6ad7f84d3f
5
5
  SHA512:
6
- metadata.gz: fe772a13c725eb2aa94e50dbafbca0a9a1a05113f69b951150437ad6dd4d38237ccd5eaaef3ce36241ca823a3527b77b4628feaa2d30d62da8cbdae63dfe62bd
7
- data.tar.gz: 307ba703a9026f632601defaf9da8cd220f9334b1f5286622f64457496ee9696f723a5021dc7db472dac2f84fd17d8268321d8571516b230b23ce82b648c61e2
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,3 +1,3 @@
1
1
  module ObjectSpace::AllocationTracer
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -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
- table = result.map{|(file, line, klass), (count, oldcount, total_age, min_age, max_age, memsize)|
21
- ["#{Rack::Utils.escape_html(file)}:#{'%04d' % line}",
22
- klass ? klass.name : '<internal>',
23
- count, oldcount, total_age / Float(count), min_age, max_age, memsize]
24
- }.sort_by{|vs|
25
- ary = @sort_order.map{|i| Numeric === vs[i] ? -vs[i] : vs[i]}
26
- }
27
-
28
- headers = %w(path class count old_count average_age max_age min_age memsize).map.with_index{|e, i|
29
- "<th><a href='./?s=#{i}'>#{e}</a></th>"
30
- }.join("\n")
31
- header = "<tr>#{headers}</tr>"
32
- body = table.map{|cols|
33
- "<tr>" + cols.map{|c| "<td>#{c}</td>"}.join("\n") + "</tr>"
34
- }.join("\n")
35
- "<table>#{header}#{body}</table>"
36
- end
37
-
38
- def count_table_page count_table
39
- text = count_table.map{|k, v| "%-10s\t%8d" % [k, v]}.join("\n")
40
- "<pre>#{text}</pre>"
41
- end
42
-
43
- def allocated_count_table_page
44
- count_table_page ObjectSpace::AllocationTracer.allocated_count_table
45
- end
46
-
47
- def freed_count_table_page
48
- count_table_page ObjectSpace::AllocationTracer.freed_count_table
49
- end
50
-
51
- def call env
52
- if /\A\/allocation_tracer\// =~ env["PATH_INFO"]
53
- result = ObjectSpace::AllocationTracer.result
54
- ObjectSpace::AllocationTracer.pause
55
-
56
- p env["PATH_INFO"]
57
- case env["PATH_INFO"]
58
- when /lifetime_table/
59
- raise "Unsupported: lifetime_table"
60
- when /allocated_count_table/
61
- text = allocated_count_table_page
62
- when /freed_count_table/
63
- text = freed_count_table_page
64
- else
65
- text = allocation_trace_page result
66
- end
67
-
68
- if /\As=(\d+)/ =~ env["QUERY_STRING"]
69
- top = $1.to_i
70
- @sort_order.unshift top if @sort_order.delete top
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allocation_tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Sasada