Class: ObjspaceHelpers
- Inherits:
-
Object
- Object
- ObjspaceHelpers
- Defined in:
- lib/objspace_helpers/helpers.rb,
lib/objspace_helpers/version.rb
Constant Summary collapse
- VERSION =
'0.0.2'
Class Method Summary collapse
- ._addresses_to_info(ary) ⇒ Object
- ._addresses_to_references(addresses) ⇒ Object
- ._dump_addresses ⇒ Object
- ._id2ref ⇒ Object
- .diff(&block) ⇒ Object
- .dump_all_addresses ⇒ Object
- .info_for_address(addresses) ⇒ Object
- .info_for_obj(obj) ⇒ Object
Class Method Details
._addresses_to_info(ary) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'ext/objspace_helpers/objspace_helpers.c', line 24 static VALUE oh_addresses_to_info(VALUE self, VALUE ary) { VALUE hash, obj_addr, info_hash; long i; hash = rb_hash_new(); for (i = 0; i < RARRAY_LEN(ary); i += 1) { obj_addr = rb_ary_entry(ary, i); info_hash = rb_hash_new(); objspace_info(oh_id2ref(self, obj_addr), info_hash); rb_hash_aset(hash, obj_addr, info_hash); } return hash; } |
._addresses_to_references(addresses) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'ext/objspace_helpers/objspace_helpers.c', line 47 static VALUE oh_addresses_to_references(VALUE self, VALUE addresses) { VALUE hash, obj_addr, references; long i; hash = rb_hash_new(); for (i = 0; i < RARRAY_LEN(addresses); i += 1) { obj_addr = rb_ary_entry(addresses, i); references = rb_ary_new(); rb_objspace_reachable_objects_from(oh_id2ref(self, obj_addr), reachable_object_i, (void*)references); rb_hash_aset(hash, obj_addr, references); } return hash; } |
._dump_addresses ⇒ Object
17 18 19 20 21 22 |
# File 'ext/objspace_helpers/objspace_helpers.c', line 17 static VALUE oh_dump_addresses(VALUE self) { VALUE ary = rb_ary_new(); rb_objspace_each_objects(collect_addresses, (void *)ary); return ary; } |
._id2ref ⇒ Object
.diff(&block) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/objspace_helpers/helpers.rb', line 14 def self.diff(&block) objs_before = dump_all_addresses block.call objs_after = dump_all_addresses objs_after - objs_before - [objs_after.object_id] end |
.dump_all_addresses ⇒ Object
2 3 4 |
# File 'lib/objspace_helpers/helpers.rb', line 2 def self.dump_all_addresses _dump_addresses end |
.info_for_address(addresses) ⇒ Object
6 7 8 |
# File 'lib/objspace_helpers/helpers.rb', line 6 def self.info_for_address(addresses) _addresses_to_info(addresses) end |
.info_for_obj(obj) ⇒ Object
10 11 12 |
# File 'lib/objspace_helpers/helpers.rb', line 10 def self.info_for_obj(obj) _addresses_to_info([obj.object_id]).values.first end |