From 601d2ea243faa80b97fd8f9c0bf22e346eb9cf4d Mon Sep 17 00:00:00 2001 From: ko1 Date: Sun, 27 Apr 2008 06:28:08 +0000 Subject: * gc.c (gc_count): add a GC.count method. This method returns a GC invoking count. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- gc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'gc.c') diff --git a/gc.c b/gc.c index e58269def..b94e7c625 100644 --- a/gc.c +++ b/gc.c @@ -173,6 +173,7 @@ typedef struct rb_objspace { int overflow; } markstack; struct gc_list *global_list; + unsigned int count; } rb_objspace_t; #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE @@ -1673,6 +1674,7 @@ garbage_collect(rb_objspace_t *objspace) return Qtrue; } during_gc++; + objspace->count++; SET_STACK_END; @@ -2351,6 +2353,22 @@ count_objects(int argc, VALUE *argv, VALUE os) return hash; } +/* + * call-seq: + * GC.count -> Integer + * + * Counts objects for each type. + * + * It returns a number of GC invoke counts. + * + */ + +static VALUE +gc_count(VALUE self) +{ + return UINT2NUM((&rb_objspace)->count); +} + /* * The GC module provides an interface to Ruby's mark and * sweep garbage collection mechanism. Some of the underlying methods @@ -2368,6 +2386,7 @@ Init_GC(void) rb_define_singleton_method(rb_mGC, "disable", rb_gc_disable, 0); rb_define_singleton_method(rb_mGC, "stress", gc_stress_get, 0); rb_define_singleton_method(rb_mGC, "stress=", gc_stress_set, 1); + rb_define_singleton_method(rb_mGC, "count", gc_count, 0); rb_define_method(rb_mGC, "garbage_collect", rb_gc_start, 0); rb_mObSpace = rb_define_module("ObjectSpace"); -- cgit