From 3de80833a23b6aa07f698bf20fffbba25d6fe79d Mon Sep 17 00:00:00 2001 From: ko1 Date: Sun, 27 Apr 2008 06:28:08 +0000 Subject: [PATCH] * gc.c (gc_count): add a GC.count method. This method returns a GC invoking count. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ doc/NEWS | 3 ++- gc.c | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9a0b1a3ea0..5fc6355b40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Apr 27 15:23:40 2008 Koichi Sasada + + * gc.c (gc_count): add a GC.count method. This method returns + a GC invoking count. + Sun Apr 27 12:20:33 2008 Nobuyoshi Nakada * vm_core.h (rb_vm_t), gc.c (rb_objspace, rb_newobj), vm.c diff --git a/doc/NEWS b/doc/NEWS index d2a5a23210..551f2c19fb 100644 --- a/doc/NEWS +++ b/doc/NEWS @@ -195,7 +195,8 @@ Compatible o Process.exec * Misc. new methods o public_send - o GC.stress, GC.stress= + o GC.stress, GC.stress=, GC.count + o ObjectSpace.count_objects o Method#hash, Proc#hash o __method__ and __callee__ o Symbol#to_proc diff --git a/gc.c b/gc.c index e58269deff..b94e7c6257 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");