summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorwanabe <wanabe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-04 04:51:43 +0000
committerwanabe <wanabe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-04 04:51:43 +0000
commit4d8d6d9d6319be436cdc0fb1da81502d9b0c3abd (patch)
tree0d6b238814fac991e29c2961cea9f0a2f3bc28db /gc.c
parente09838c691805ae2bf6b46fa66abaa626f70e9d3 (diff)
* gc.c (gc_profile_total_time): add GC::Profiler.total_time.
* NEWS: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/gc.c b/gc.c
index fb2994066a..768337d84f 100644
--- a/gc.c
+++ b/gc.c
@@ -3129,6 +3129,28 @@ gc_profile_report(int argc, VALUE *argv, VALUE self)
}
/*
+ * call-seq:
+ * GC::Profiler.total_time -> float
+ *
+ * return total time that GC used. (msec)
+ */
+
+static VALUE
+gc_profile_total_time(VALUE self)
+{
+ double time = 0;
+ rb_objspace_t *objspace = &rb_objspace;
+ size_t i;
+
+ if (objspace->profile.run && objspace->profile.count) {
+ for (i = 0; i < objspace->profile.count; i++) {
+ time += objspace->profile.record[i].gc_time;
+ }
+ }
+ return DBL2NUM(time);
+}
+
+/*
* The <code>GC</code> module provides an interface to Ruby's mark and
* sweep garbage collection mechanism. Some of the underlying methods
* are also available via the <code>ObjectSpace</code> module.
@@ -3156,6 +3178,7 @@ Init_GC(void)
rb_define_singleton_method(rb_mProfiler, "clear", gc_profile_clear, 0);
rb_define_singleton_method(rb_mProfiler, "result", gc_profile_result, 0);
rb_define_singleton_method(rb_mProfiler, "report", gc_profile_report, -1);
+ rb_define_singleton_method(rb_mProfiler, "total_time", gc_profile_total_time, 0);
rb_mObSpace = rb_define_module("ObjectSpace");
rb_define_module_function(rb_mObSpace, "each_object", os_each_obj, -1);