allocation_tracer 0.4.3 → 0.5.0
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 +4 -4
- data/.travis.yml +1 -1
- data/README.md +24 -0
- data/ext/allocation_tracer/allocation_tracer.c +6 -3
- data/lib/allocation_tracer/version.rb +1 -1
- data/lib/rack/allocation_tracer.rb +92 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00e9bb56504e9d79f1182f199aa74bcae77f8452
|
4
|
+
data.tar.gz: 1847dac5c208e05f9e9bc05669d3371082fb0997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe772a13c725eb2aa94e50dbafbca0a9a1a05113f69b951150437ad6dd4d38237ccd5eaaef3ce36241ca823a3527b77b4628feaa2d30d62da8cbdae63dfe62bd
|
7
|
+
data.tar.gz: 307ba703a9026f632601defaf9da8cd220f9334b1f5286622f64457496ee9696f723a5021dc7db472dac2f84fd17d8268321d8571516b230b23ce82b648c61e2
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -213,6 +213,30 @@ Note that these numbers includes living objects and dead objects. For
|
|
213
213
|
dead objects, age means lifetime. For living objects, age means
|
214
214
|
current age.
|
215
215
|
|
216
|
+
## Rack middleware
|
217
|
+
|
218
|
+
You can use
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
require 'rack'
|
222
|
+
require 'sinatra'
|
223
|
+
require 'rack/allocation_tracer'
|
224
|
+
|
225
|
+
use Rack::AllocationTracerMiddleware
|
226
|
+
|
227
|
+
get '/' do
|
228
|
+
'foo'
|
229
|
+
end
|
230
|
+
```
|
231
|
+
|
232
|
+
When you access to `http://host/allocation_tracer/` then you can see table of allocation tracer.
|
233
|
+
|
234
|
+
You can access the following pages.
|
235
|
+
|
236
|
+
* http://host/allocation_tracer/
|
237
|
+
* http://host/allocation_tracer/allocated_count_table
|
238
|
+
* http://host/allocation_tracer/freed_count_table_page
|
239
|
+
|
216
240
|
## Contributing
|
217
241
|
|
218
242
|
1. Fork it ( http://github.com/ko1/allocation_tracer/fork )
|
@@ -102,9 +102,10 @@ delete_unique_str(st_table *tbl, const char *str)
|
|
102
102
|
if (str) {
|
103
103
|
st_data_t n;
|
104
104
|
|
105
|
-
st_lookup(tbl, (st_data_t)str, &n);
|
105
|
+
if (st_lookup(tbl, (st_data_t)str, &n) == 0) rb_bug("delete_unique_str: unreachable");
|
106
|
+
|
106
107
|
if (n == 1) {
|
107
|
-
st_delete(tbl, (st_data_t *)&str,
|
108
|
+
st_delete(tbl, (st_data_t *)&str, NULL);
|
108
109
|
ruby_xfree((char *)str);
|
109
110
|
}
|
110
111
|
else {
|
@@ -522,6 +523,9 @@ type_sym(int type)
|
|
522
523
|
TYPE_NAME(T_SYMBOL);
|
523
524
|
TYPE_NAME(T_FIXNUM);
|
524
525
|
TYPE_NAME(T_UNDEF);
|
526
|
+
#ifdef T_IMEMO /* introduced from Rub 2.3 */
|
527
|
+
TYPE_NAME(T_IMEMO);
|
528
|
+
#endif
|
525
529
|
TYPE_NAME(T_NODE);
|
526
530
|
TYPE_NAME(T_ICLASS);
|
527
531
|
TYPE_NAME(T_ZOMBIE);
|
@@ -559,7 +563,6 @@ aggregate_result_i(st_data_t key, st_data_t val, void *data)
|
|
559
563
|
const char *path = (const char *)key_buff->data[i++];
|
560
564
|
if (path) {
|
561
565
|
rb_ary_push(k, rb_str_new2(path));
|
562
|
-
delete_unique_str(arg->str_table, path);
|
563
566
|
}
|
564
567
|
else {
|
565
568
|
rb_ary_push(k, Qnil);
|
@@ -0,0 +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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: allocation_tracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi Sasada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/allocation_tracer.rb
|
87
87
|
- lib/allocation_tracer/trace.rb
|
88
88
|
- lib/allocation_tracer/version.rb
|
89
|
+
- lib/rack/allocation_tracer.rb
|
89
90
|
- spec/allocation_tracer_spec.rb
|
90
91
|
- spec/spec_helper.rb
|
91
92
|
homepage: https://github.com/ko1/allocation_tracer
|