Module: Allocations
- Defined in:
- lib/allocations/version.rb
Defined Under Namespace
Classes: State
Constant Summary collapse
- VERSION =
'1.0.5'
- STATE =
rb_funcall(cState, rb_intern("new"), 0)
- ALLOCATION_TRACER =
allocation_tracer
- FREE_TRACER =
free_tracer
Class Method Summary collapse
-
.enabled? ⇒ Boolean
Returns true if tracking allocations has been enabled, false otherwise.
-
.start ⇒ Object
Starts the counting of object allocations.
-
.stop ⇒ Object
Stops the counting of object allocations and clears the current statistics.
-
.to_hash ⇒ Object
Returns a Hash containing the current allocation statistics.
Class Method Details
.enabled? ⇒ Boolean
Returns true if tracking allocations has been enabled, false otherwise.
call-seq:
Allocations.enabled? -> true/false
160 161 162 163 164 165 166 167 168 |
# File 'ext/liballocations/liballocations.c', line 160
VALUE allocations_enabled_p(VALUE self) {
VALUE enabled = Qfalse;
if ( rb_ivar_get(self, id_enabled) == Qtrue ) {
enabled = Qtrue;
}
return enabled;
}
|
.start ⇒ Object
Starts the counting of object allocations.
call-seq:
Allocations.start -> nil
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/liballocations/liballocations.c', line 114
VALUE allocations_start(VALUE self) {
AllocationState *state = allocation_state_get_struct(state_const);
if ( rb_ivar_get(self, id_enabled) == Qtrue ) {
return Qnil;
}
allocation_state_allocate_counts(state);
rb_ivar_set(self, id_enabled, Qtrue);
rb_tracepoint_enable(allocation_tracer);
rb_tracepoint_enable(free_tracer);
return Qnil;
}
|
.stop ⇒ Object
Stops the counting of object allocations and clears the current statistics.
call-seq:
Allocations.stop -> nil
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ext/liballocations/liballocations.c', line 137
VALUE allocations_stop(VALUE self) {
AllocationState *state = allocation_state_get_struct(state_const);
if ( rb_ivar_get(self, id_enabled) != Qtrue ) {
return Qnil;
}
rb_tracepoint_disable(allocation_tracer);
rb_tracepoint_disable(free_tracer);
allocation_state_reset_counts(state);
rb_ivar_set(self, id_enabled, Qfalse);
return Qnil;
}
|
.to_hash ⇒ Object
Returns a Hash containing the current allocation statistics.
The returned Hash contains its own copy of the statistics, any further object allocations/frees will not modify said Hash.
This method ignores singleton classes.
call-seq:
Allocations.to_hash -> Hash
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'ext/liballocations/liballocations.c', line 88
VALUE allocations_to_hash(VALUE self) {
AllocationState *state = allocation_state_get_struct(state_const);
st_table *local_counts;
VALUE hash;
if ( !state->object_counts ) {
return rb_hash_new();
}
local_counts = allocation_state_copy_table(state);
hash = rb_hash_new();
st_foreach(local_counts, each_count, (st_data_t) hash);
st_free_table(local_counts);
return hash;
}
|