Module: Allocations
- Defined in:
- lib/allocations/version.rb
Constant Summary collapse
- VERSION =
'1.0.1'
- MUTEX =
mutex
- 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
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'ext/liballocations/liballocations.c', line 172
VALUE allocations_enabled_p(VALUE self) {
VALUE enabled = Qfalse;
rb_mutex_lock(mutex);
if ( rb_ivar_get(self, id_enabled) == Qtrue ) {
enabled = Qtrue;
}
rb_mutex_unlock(mutex);
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 130 131 132 133 |
# File 'ext/liballocations/liballocations.c', line 114
VALUE allocations_start(VALUE self) {
rb_mutex_lock(mutex);
if ( rb_ivar_get(self, id_enabled) == Qtrue ) {
rb_mutex_unlock(mutex);
return Qnil;
}
object_counts = st_init_numtable();
rb_ivar_set(self, id_enabled, Qtrue);
rb_mutex_unlock(mutex);
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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'ext/liballocations/liballocations.c', line 141
VALUE allocations_stop(VALUE self) {
rb_mutex_lock(mutex);
if ( rb_ivar_get(self, id_enabled) != Qtrue ) {
rb_mutex_unlock(mutex);
return Qnil;
}
rb_tracepoint_disable(allocation_tracer);
rb_tracepoint_disable(free_tracer);
if ( object_counts ) {
st_free_table(object_counts);
}
object_counts = NULL;
rb_ivar_set(self, id_enabled, Qfalse);
rb_mutex_unlock(mutex);
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.
call-seq:
Allocations.to_hash -> Hash
83 84 85 86 87 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 83
VALUE allocations_to_hash(VALUE self) {
st_table *local_counts;
VALUE hash;
rb_mutex_lock(mutex);
if ( !object_counts ) {
rb_mutex_unlock(mutex);
return rb_hash_new();
}
local_counts = st_copy(object_counts);
rb_mutex_unlock(mutex);
hash = rb_hash_new();
st_foreach(local_counts, each_count, (st_data_t) hash);
st_free_table(local_counts);
return hash;
}
|