Module: GC::Profiler
- Defined in:
- gc.c
Class Method Summary collapse
-
.GC::Profiler.clear ⇒ nil
Clears the GC profiler data.
-
.GC::Profiler.disable(->nil) ⇒ Object
Stops the GC profiler.
-
.GC::Profiler.enable(->nil) ⇒ Object
Starts the GC profiler.
-
.GC::Profiler.enabled?(->true) ⇒ Boolean
The current status of GC profile mode.
-
.GC::Profiler.raw_data(->[Hash, ...]) ⇒ Object
Returns an Array of individual raw profile data Hashes ordered from earliest to latest by
:GC_INVOKE_TIME
. -
.report ⇒ Object
Writes the GC::Profiler.result to
$stdout
or the given IO object. -
.GC::Profiler.result ⇒ String
Returns a profile data report such as:.
-
.GC::Profiler.total_time(->float) ⇒ Object
The total time used for garbage collection in seconds.
Class Method Details
.GC::Profiler.clear ⇒ nil
Clears the GC profiler data.
6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 |
# File 'gc.c', line 6931
static VALUE
gc_profile_clear(void)
{
rb_objspace_t *objspace = &rb_objspace;
if (GC_PROFILE_RECORD_DEFAULT_SIZE * 2 < objspace->profile.size) {
objspace->profile.size = GC_PROFILE_RECORD_DEFAULT_SIZE * 2;
objspace->profile.records = realloc(objspace->profile.records, sizeof(gc_profile_record) * objspace->profile.size);
if (!objspace->profile.records) {
rb_memerror();
}
}
MEMZERO(objspace->profile.records, gc_profile_record, objspace->profile.size);
objspace->profile.next_index = 0;
objspace->profile.current_record = 0;
return Qnil;
}
|
.GC::Profiler.disable(->nil) ⇒ Object
Stops the GC profiler.
7283 7284 7285 7286 7287 7288 7289 7290 7291 |
# File 'gc.c', line 7283
static VALUE
gc_profile_disable(void)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->profile.run = FALSE;
objspace->profile.current_record = 0;
return Qnil;
}
|
.GC::Profiler.enable(->nil) ⇒ Object
Starts the GC profiler.
7266 7267 7268 7269 7270 7271 7272 7273 |
# File 'gc.c', line 7266
static VALUE
gc_profile_enable(void)
{
rb_objspace_t *objspace = &rb_objspace;
objspace->profile.run = TRUE;
objspace->profile.current_record = 0;
return Qnil;
}
|
.GC::Profiler.enabled?(->true) ⇒ Boolean
The current status of GC profile mode.
7251 7252 7253 7254 7255 7256 |
# File 'gc.c', line 7251
static VALUE
gc_profile_enable_get(VALUE self)
{
rb_objspace_t *objspace = &rb_objspace;
return objspace->profile.run ? Qtrue : Qfalse;
}
|
.GC::Profiler.raw_data(->[Hash, ...]) ⇒ Object
Returns an Array of individual raw profile data Hashes ordered from earliest to latest by :GC_INVOKE_TIME
.
For example:
[
:GC_TIME=>1.3000000000000858e-05,
:GC_INVOKE_TIME=>0.010634999999999999,
:HEAP_USE_SIZE=>289640,
:HEAP_TOTAL_SIZE=>588960,
:HEAP_TOTAL_OBJECTS=>14724,
:GC_IS_MARKED=>false
,
# ...
]
The keys mean:
:GC_TIME
-
Time elapsed in seconds for this GC run
:GC_INVOKE_TIME
-
Time elapsed in seconds from startup to when the GC was invoked
:HEAP_USE_SIZE
-
Total bytes of heap used
:HEAP_TOTAL_SIZE
-
Total size of heap in bytes
:HEAP_TOTAL_OBJECTS
-
Total number of objects
:GC_IS_MARKED
-
Returns
true
if the GC is in mark phaseIf ruby was built with
GC_PROFILE_MORE_DETAIL
, you will also have access to the following hash keys::GC_MARK_TIME
:GC_SWEEP_TIME
:ALLOCATE_INCREASE
:ALLOCATE_LIMIT
:HEAP_USE_PAGES
:HEAP_LIVE_OBJECTS
:HEAP_FREE_OBJECTS
:HAVE_FINALIZE
6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 |
# File 'gc.c', line 6998
static VALUE
gc_profile_record_get(void)
{
VALUE prof;
VALUE gc_profile = rb_ary_new();
size_t i;
rb_objspace_t *objspace = (&rb_objspace);
if (!objspace->profile.run) {
return Qnil;
}
for (i =0; i < objspace->profile.next_index; i++) {
gc_profile_record *record = &objspace->profile.records[i];
prof = rb_hash_new();
rb_hash_aset(prof, ID2SYM(rb_intern("GC_FLAGS")), gc_info_decode(record->flags, rb_hash_new()));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_TIME")), DBL2NUM(record->gc_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_INVOKE_TIME")), DBL2NUM(record->gc_invoke_time));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_SIZE")), SIZET2NUM(record->heap_use_size));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_SIZE")), SIZET2NUM(record->heap_total_size));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_TOTAL_OBJECTS")), SIZET2NUM(record->heap_total_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_IS_MARKED")), Qtrue);
#if GC_PROFILE_MORE_DETAIL
rb_hash_aset(prof, ID2SYM(rb_intern("GC_MARK_TIME")), DBL2NUM(record->gc_mark_time));
rb_hash_aset(prof, ID2SYM(rb_intern("GC_SWEEP_TIME")), DBL2NUM(record->gc_sweep_time));
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_INCREASE")), SIZET2NUM(record->allocate_increase));
rb_hash_aset(prof, ID2SYM(rb_intern("ALLOCATE_LIMIT")), SIZET2NUM(record->allocate_limit));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_USE_PAGES")), SIZET2NUM(record->heap_use_pages));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_LIVE_OBJECTS")), SIZET2NUM(record->heap_live_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("HEAP_FREE_OBJECTS")), SIZET2NUM(record->heap_free_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("REMOVING_OBJECTS")), SIZET2NUM(record->removing_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("EMPTY_OBJECTS")), SIZET2NUM(record->empty_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("HAVE_FINALIZE")), (record->flags & GPR_FLAG_HAVE_FINALIZE) ? Qtrue : Qfalse);
#endif
#if RGENGC_PROFILE > 0
rb_hash_aset(prof, ID2SYM(rb_intern("OLD_OBJECTS")), SIZET2NUM(record->old_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBED_NORMAL_OBJECTS")), SIZET2NUM(record->remembered_normal_objects));
rb_hash_aset(prof, ID2SYM(rb_intern("REMEMBED_SHADY_OBJECTS")), SIZET2NUM(record->remembered_shady_objects));
#endif
rb_ary_push(gc_profile, prof);
}
return gc_profile;
}
|
.GC::Profiler.report ⇒ Object .GC::Profiler.report(io) ⇒ Object
Writes the GC::Profiler.result to $stdout
or the given IO object.
7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 |
# File 'gc.c', line 7204
static VALUE
gc_profile_report(int argc, VALUE *argv, VALUE self)
{
VALUE out;
if (argc == 0) {
out = rb_stdout;
}
else {
rb_scan_args(argc, argv, "01", &out);
}
gc_profile_dump_on(out, rb_io_write);
return Qnil;
}
|
.GC::Profiler.result ⇒ String
Returns a profile data report such as:
GC 1 invokes.
Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC time(ms)
1 0.012 159240 212940 10647 0.00000000000001530000
7187 7188 7189 7190 7191 7192 7193 |
# File 'gc.c', line 7187
static VALUE
gc_profile_result(void)
{
VALUE str = rb_str_buf_new(0);
gc_profile_dump_on(str, rb_str_buf_append);
return str;
}
|
.GC::Profiler.total_time(->float) ⇒ Object
The total time used for garbage collection in seconds
7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 |
# File 'gc.c', line 7227
static VALUE
gc_profile_total_time(VALUE self)
{
double time = 0;
rb_objspace_t *objspace = &rb_objspace;
if (objspace->profile.run && objspace->profile.next_index > 0) {
size_t i;
size_t count = objspace->profile.next_index;
for (i = 0; i < count; i++) {
time += objspace->profile.records[i].gc_time;
}
}
return DBL2NUM(time);
}
|