allocation_tracer 0.3.0 → 0.3.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 +4 -4
- data/README.md +4 -4
- data/ext/allocation_tracer/allocation_tracer.c +40 -31
- data/lib/allocation_tracer/version.rb +1 -1
- data/lib/allocation_tracer.rb +22 -1
- data/spec/allocation_tracer_spec.rb +30 -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: 5591d5370e3ce789b1f83038fb1a569d5d95df2f
|
4
|
+
data.tar.gz: 02e0ce857929fb00a7a05b2a4624a1ade3a9c634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea426ef389e777313fef152336f8c0fdee45710d192ec063ba9996edd2d3cff48a473593a19ee41b98312d70b78160a60edba741891f5ea1461ed9481ac03cd8
|
7
|
+
data.tar.gz: 8134ddefac4fb01ca99e0d7442cf1626e4e4a18802f80e5e1ed0f5d0abd3791976c72e88b32d5a52ea8fe411d44bbf4676b623966738f6d79d3c2f58a2897091
|
data/README.md
CHANGED
@@ -179,11 +179,11 @@ will show
|
|
179
179
|
|
180
180
|
This output means that the age of 3434 T_OBJECT objects are 0, 96563
|
181
181
|
objects are 1 and 2 objects are 7. Also the age of 3435 T_STRING
|
182
|
-
objects are 0, 96556 are 1 and so on.
|
182
|
+
objects are 0, 96556 objects are 1 and so on.
|
183
183
|
|
184
|
-
Note that these
|
185
|
-
dead
|
186
|
-
age.
|
184
|
+
Note that these numbers includes living objects and dead objects. For
|
185
|
+
dead objects, age means lifetime. For living objects, age means
|
186
|
+
current age.
|
187
187
|
|
188
188
|
## Contributing
|
189
189
|
|
@@ -176,6 +176,19 @@ free_key_values_i(st_data_t key, st_data_t value, void *data)
|
|
176
176
|
return ST_CONTINUE;
|
177
177
|
}
|
178
178
|
|
179
|
+
static void
|
180
|
+
delete_lifetime_table(struct traceobj_arg *arg)
|
181
|
+
{
|
182
|
+
int i;
|
183
|
+
if (arg->lifetime_table) {
|
184
|
+
for (i=0; i<T_MASK; i++) {
|
185
|
+
free(arg->lifetime_table[i]);
|
186
|
+
}
|
187
|
+
free(arg->lifetime_table);
|
188
|
+
arg->lifetime_table = NULL;
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
179
192
|
static void
|
180
193
|
clear_traceobj_arg(void)
|
181
194
|
{
|
@@ -187,17 +200,8 @@ clear_traceobj_arg(void)
|
|
187
200
|
st_clear(arg->object_table);
|
188
201
|
st_foreach(arg->str_table, free_keys_i, 0);
|
189
202
|
st_clear(arg->str_table);
|
190
|
-
|
191
|
-
|
192
|
-
int i;
|
193
|
-
|
194
|
-
for (i=0; i<T_MASK; i++) {
|
195
|
-
if (arg->lifetime_table[i] != NULL) {
|
196
|
-
free(arg->lifetime_table[i]);
|
197
|
-
arg->lifetime_table[i] = NULL;
|
198
|
-
}
|
199
|
-
}
|
200
|
-
}
|
203
|
+
arg->freed_allocation_info = 0;
|
204
|
+
delete_lifetime_table(arg);
|
201
205
|
}
|
202
206
|
|
203
207
|
static struct allocation_info *
|
@@ -316,11 +320,13 @@ aggregate_freed_info(void *data)
|
|
316
320
|
|
317
321
|
arg->freed_allocation_info = NULL;
|
318
322
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
323
|
+
if (arg->running) {
|
324
|
+
while (info) {
|
325
|
+
struct allocation_info *next_info = info->next;
|
326
|
+
aggregate_each_info(arg, info, gc_count);
|
327
|
+
free_allocation_info(arg, info);
|
328
|
+
info = next_info;
|
329
|
+
}
|
324
330
|
}
|
325
331
|
}
|
326
332
|
|
@@ -340,9 +346,9 @@ add_lifetime_table(size_t **lines, int type, struct allocation_info *info)
|
|
340
346
|
|
341
347
|
if (line == NULL) {
|
342
348
|
len = age + 1;
|
343
|
-
line = lines[type] =
|
349
|
+
line = lines[type] = calloc(1 + len, sizeof(size_t));
|
350
|
+
assert(line != NULL);
|
344
351
|
line[0] = len;
|
345
|
-
for (i=0; i<len; i++) line[i+1] = 0;
|
346
352
|
}
|
347
353
|
else {
|
348
354
|
len = line[0];
|
@@ -351,12 +357,18 @@ add_lifetime_table(size_t **lines, int type, struct allocation_info *info)
|
|
351
357
|
size_t old_len = len;
|
352
358
|
len = age + 1;
|
353
359
|
line = lines[type] = realloc(line, sizeof(size_t) * (1 + len));
|
354
|
-
|
360
|
+
|
361
|
+
assert(line != NULL);
|
362
|
+
|
363
|
+
for (i=old_len; i<len; i++) {
|
364
|
+
line[i+1] = 0;
|
365
|
+
}
|
366
|
+
|
355
367
|
line[0] = len;
|
356
368
|
}
|
357
369
|
}
|
358
370
|
|
359
|
-
line[
|
371
|
+
line[1 + age]++;
|
360
372
|
}
|
361
373
|
|
362
374
|
static void
|
@@ -467,7 +479,7 @@ stop_alloc_hooks(VALUE self)
|
|
467
479
|
static VALUE
|
468
480
|
type_sym(int type)
|
469
481
|
{
|
470
|
-
static VALUE syms[T_MASK];
|
482
|
+
static VALUE syms[T_MASK] = {0};
|
471
483
|
|
472
484
|
if (syms[0] == 0) {
|
473
485
|
int i;
|
@@ -501,6 +513,7 @@ type_sym(int type)
|
|
501
513
|
TYPE_NAME(T_DATA);
|
502
514
|
default:
|
503
515
|
syms[i] = ID2SYM(rb_intern("unknown"));
|
516
|
+
break;
|
504
517
|
#undef TYPE_NAME
|
505
518
|
}
|
506
519
|
}
|
@@ -546,7 +559,6 @@ aggregate_result_i(st_data_t key, st_data_t val, void *data)
|
|
546
559
|
}
|
547
560
|
if (arg->keys & KEY_TYPE) {
|
548
561
|
int sym_index = key_buff->data[i++];
|
549
|
-
assert(T_MASK > sym_index);
|
550
562
|
rb_ary_push(k, type_sym(sym_index));
|
551
563
|
}
|
552
564
|
if (arg->keys & KEY_CLASS) {
|
@@ -646,6 +658,8 @@ aggregate_result(struct traceobj_arg *arg)
|
|
646
658
|
VALUE h = rb_hash_new();
|
647
659
|
int i;
|
648
660
|
|
661
|
+
rb_ivar_set(rb_mAllocationTracer, rb_intern("lifetime_table"), h);
|
662
|
+
|
649
663
|
for (i=0; i<T_MASK; i++) {
|
650
664
|
size_t *line = arg->lifetime_table[i];
|
651
665
|
|
@@ -654,16 +668,15 @@ aggregate_result(struct traceobj_arg *arg)
|
|
654
668
|
VALUE ary = rb_ary_new();
|
655
669
|
VALUE sym = type_sym(i);
|
656
670
|
|
671
|
+
rb_hash_aset(h, sym, ary);
|
672
|
+
|
657
673
|
for (j=0; j<len; j++) {
|
658
674
|
rb_ary_push(ary, SIZET2NUM(line[j+1]));
|
659
675
|
}
|
660
|
-
|
661
|
-
rb_hash_aset(h, sym, ary);
|
662
676
|
}
|
663
677
|
}
|
664
678
|
|
665
679
|
st_foreach(arg->object_table, lifetime_table_for_live_objects_i, (st_data_t)h);
|
666
|
-
rb_ivar_set(rb_mAllocationTracer, rb_intern("lifetime_table"), h);
|
667
680
|
}
|
668
681
|
|
669
682
|
return aar.result;
|
@@ -805,15 +818,11 @@ allocation_tracer_lifetime_table_setup(VALUE self, VALUE set)
|
|
805
818
|
|
806
819
|
if (RTEST(set)) {
|
807
820
|
if (arg->lifetime_table == NULL) {
|
808
|
-
arg->lifetime_table = (size_t **)calloc(sizeof(size_t **)
|
809
|
-
|
821
|
+
arg->lifetime_table = (size_t **)calloc(T_MASK, sizeof(size_t **));
|
810
822
|
}
|
811
823
|
}
|
812
824
|
else {
|
813
|
-
|
814
|
-
free(arg->lifetime_table);
|
815
|
-
arg->lifetime_table = NULL;
|
816
|
-
}
|
825
|
+
delete_lifetime_table(arg);
|
817
826
|
}
|
818
827
|
|
819
828
|
return Qnil;
|
data/lib/allocation_tracer.rb
CHANGED
@@ -2,5 +2,26 @@ require "allocation_tracer/version"
|
|
2
2
|
require "allocation_tracer/allocation_tracer"
|
3
3
|
|
4
4
|
module ObjectSpace::AllocationTracer
|
5
|
-
|
5
|
+
def self.collect_lifetime_talbe
|
6
|
+
ObjectSpace::AllocationTracer.lifetime_table_setup true
|
7
|
+
|
8
|
+
if block_given?
|
9
|
+
begin
|
10
|
+
ObjectSpace::AllocationTracer.trace do
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
ObjectSpace::AllocationTracer.lifetime_table
|
14
|
+
ensure
|
15
|
+
ObjectSpace::AllocationTracer.lifetime_table_setup false
|
16
|
+
end
|
17
|
+
else
|
18
|
+
ObjectSpace::AllocationTracer.trace
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.collect_lifetime_talbe_stop
|
23
|
+
ObjectSpace::AllocationTracer.stop
|
24
|
+
result = ObjectSpace::AllocationTracer.lifetime_table
|
25
|
+
ObjectSpace::AllocationTracer.lifetime_table_setup false
|
26
|
+
end
|
6
27
|
end
|
@@ -188,7 +188,7 @@ describe ObjectSpace::AllocationTracer do
|
|
188
188
|
expect(table[:T_NONE]).to be nil
|
189
189
|
end
|
190
190
|
|
191
|
-
it 'should nil when ObjectSpace::AllocationTracer.lifetime_table_setup is
|
191
|
+
it 'should return nil when ObjectSpace::AllocationTracer.lifetime_table_setup is false' do
|
192
192
|
ObjectSpace::AllocationTracer.lifetime_table_setup false
|
193
193
|
|
194
194
|
ObjectSpace::AllocationTracer.trace do
|
@@ -202,5 +202,34 @@ describe ObjectSpace::AllocationTracer do
|
|
202
202
|
|
203
203
|
expect(table).to be nil
|
204
204
|
end
|
205
|
+
|
206
|
+
it 'should return nil getting it twice' do
|
207
|
+
ObjectSpace::AllocationTracer.trace do
|
208
|
+
100000.times{
|
209
|
+
Object.new
|
210
|
+
''
|
211
|
+
}
|
212
|
+
end
|
213
|
+
|
214
|
+
table = ObjectSpace::AllocationTracer.lifetime_table
|
215
|
+
table = ObjectSpace::AllocationTracer.lifetime_table
|
216
|
+
|
217
|
+
expect(table).to be nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe 'ObjectSpace::AllocationTracer.collect_lifetime_talbe' do
|
222
|
+
it 'should collect lifetime table' do
|
223
|
+
table = ObjectSpace::AllocationTracer.collect_lifetime_talbe do
|
224
|
+
100000.times{
|
225
|
+
Object.new
|
226
|
+
''
|
227
|
+
}
|
228
|
+
end
|
229
|
+
|
230
|
+
expect(table[:T_OBJECT].inject(&:+)).to be >= 10_000
|
231
|
+
expect(table[:T_STRING].inject(&:+)).to be >= 10_000
|
232
|
+
expect(table[:T_NONE]).to be nil
|
233
|
+
end
|
205
234
|
end
|
206
235
|
end
|