class_stat 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/class_stat/class_stat.c +97 -86
- data/ext/class_stat/extconf.rb +1 -1
- data/lib/class_stat/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: 1f795b0aefd1a72e5316344aa64b238f6e5ebb4a
|
4
|
+
data.tar.gz: 0ece78825bdaef2d74d7e535d6103aec2e3217db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9bc8e2229f3a66a52b10c98f610c37763cb87ebebe6e69702df6862f0d90cf0cc874b6309fcc79f41150c0047a30020f42c0017bd5eebf7e1806f1b3c06a262
|
7
|
+
data.tar.gz: b056358effdc2e29b55304a9bc667e94d3803a47c94407ca03cd0bd30e5079e4f0f876b352775136406920a0333adfe398d3de719b504af3a06da6e471feeef6
|
data/ext/class_stat/class_stat.c
CHANGED
@@ -1,86 +1,97 @@
|
|
1
|
-
|
2
|
-
#include <ruby/ruby.h>
|
3
|
-
|
4
|
-
void rb_objspace_each_objects(
|
5
|
-
int (*callback)(void *start, void *end, size_t stride, void *data),
|
6
|
-
void *data);
|
7
|
-
|
8
|
-
struct class_stat_struct {
|
9
|
-
VALUE klass_iclassnum; /* { klass => iclassnum } */
|
10
|
-
VALUE klass_msize; /* { klass => method_count_size } */
|
11
|
-
};
|
12
|
-
|
13
|
-
#define RICLASS_IS_ORIGIN FL_USER5
|
14
|
-
|
15
|
-
static void
|
16
|
-
countup(VALUE h, VALUE k, int n)
|
17
|
-
{
|
18
|
-
VALUE cn = INT2FIX(0);
|
19
|
-
|
20
|
-
if (!RBASIC_CLASS(k)) {
|
21
|
-
k = rb_sprintf("#<hidden_class:%p>", (void *)k);
|
22
|
-
}
|
23
|
-
|
24
|
-
cn = rb_hash_lookup2(h, k, cn);
|
25
|
-
cn = INT2FIX(FIX2INT(cn) + n);
|
26
|
-
rb_hash_aset(h, k, cn);
|
27
|
-
}
|
28
|
-
|
29
|
-
static int
|
30
|
-
msize(VALUE klass)
|
31
|
-
{
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
case
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
1
|
+
|
2
|
+
#include <ruby/ruby.h>
|
3
|
+
|
4
|
+
void rb_objspace_each_objects(
|
5
|
+
int (*callback)(void *start, void *end, size_t stride, void *data),
|
6
|
+
void *data);
|
7
|
+
|
8
|
+
struct class_stat_struct {
|
9
|
+
VALUE klass_iclassnum; /* { klass => iclassnum } */
|
10
|
+
VALUE klass_msize; /* { klass => method_count_size } */
|
11
|
+
};
|
12
|
+
|
13
|
+
#define RICLASS_IS_ORIGIN FL_USER5
|
14
|
+
|
15
|
+
static void
|
16
|
+
countup(VALUE h, VALUE k, int n)
|
17
|
+
{
|
18
|
+
VALUE cn = INT2FIX(0);
|
19
|
+
|
20
|
+
if (!RBASIC_CLASS(k)) {
|
21
|
+
k = rb_sprintf("#<hidden_class:%p>", (void *)k);
|
22
|
+
}
|
23
|
+
|
24
|
+
cn = rb_hash_lookup2(h, k, cn);
|
25
|
+
cn = INT2FIX(FIX2INT(cn) + n);
|
26
|
+
rb_hash_aset(h, k, cn);
|
27
|
+
}
|
28
|
+
|
29
|
+
static int
|
30
|
+
msize(VALUE klass)
|
31
|
+
{
|
32
|
+
#if RUBY_API_VERSION_MAJOR == 2 && (RUBY_API_VERSION_MINOR == 2 || RUBY_API_VERSION_MINOR == 1)
|
33
|
+
struct method_table_wrapper {
|
34
|
+
st_table *tbl;
|
35
|
+
size_t serial;
|
36
|
+
};
|
37
|
+
#define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper)
|
38
|
+
#define RCLASS_M_TBL(c) (RCLASS_M_TBL_WRAPPER(c) ? RCLASS_M_TBL_WRAPPER(c)->tbl : 0)
|
39
|
+
#else
|
40
|
+
#define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
|
41
|
+
#endif
|
42
|
+
|
43
|
+
if (RCLASS_M_TBL(klass)) {
|
44
|
+
return RCLASS_M_TBL(klass)->num_entries;
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
return 0;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
static int
|
52
|
+
stat_i(void *vstart, void *vend, size_t stride, void *data)
|
53
|
+
{
|
54
|
+
struct class_stat_struct *d = (struct class_stat_struct *)data;
|
55
|
+
VALUE v = (VALUE)vstart;
|
56
|
+
|
57
|
+
for (;v != (VALUE)vend; v += stride) {
|
58
|
+
if (RBASIC(v)->flags) {
|
59
|
+
switch (BUILTIN_TYPE(v)) {
|
60
|
+
case T_ICLASS: {
|
61
|
+
VALUE klass = RBASIC_CLASS(v);
|
62
|
+
if (FL_TEST(v, RICLASS_IS_ORIGIN)) {
|
63
|
+
countup(d->klass_msize, klass, msize(klass));
|
64
|
+
}
|
65
|
+
else {
|
66
|
+
countup(d->klass_iclassnum, klass, 1);
|
67
|
+
}
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
case T_CLASS:
|
71
|
+
case T_MODULE:
|
72
|
+
countup(d->klass_msize, v, msize(v));
|
73
|
+
break;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
return 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE
|
81
|
+
class_stat(VALUE self)
|
82
|
+
{
|
83
|
+
struct class_stat_struct data;
|
84
|
+
data.klass_iclassnum = rb_hash_new();
|
85
|
+
data.klass_msize =rb_hash_new();
|
86
|
+
|
87
|
+
rb_objspace_each_objects(stat_i, &data);
|
88
|
+
|
89
|
+
return rb_ary_new_from_args(2, data.klass_iclassnum, data.klass_msize);
|
90
|
+
}
|
91
|
+
|
92
|
+
void
|
93
|
+
Init_class_stat(void)
|
94
|
+
{
|
95
|
+
VALUE mod = rb_define_module("ClassStat");
|
96
|
+
rb_define_singleton_method(mod, "stat", class_stat, 0);
|
97
|
+
}
|
data/ext/class_stat/extconf.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'mkmf'
|
2
|
-
create_makefile('class_stat')
|
2
|
+
create_makefile('class_stat/class_stat')
|
data/lib/class_stat/version.rb
CHANGED