summaryrefslogtreecommitdiff
path: root/vm_trace.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-13 09:01:21 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-13 09:01:21 (GMT)
commit4945572f3cc6dcd55ffac4876ae23f27e19120ad (patch)
tree2531fc0c5d73a0488401366e7668f45bbf11853b /vm_trace.c
parentddae6a05d7442f25ac04eb3338ffa8a8b4895d3f (diff)
* vm_trace.c: add new method TracePoint.stat to debug
TracePoint mechanism. Ruby users should not use this method. So I don't note this method in the NEWS file. * test/runner.rb: detect zombie active TracePoints with TracePoint.stat. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_trace.c')
-rw-r--r--vm_trace.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/vm_trace.c b/vm_trace.c
index fe10abf..8008401 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -1314,6 +1314,48 @@ tracepoint_inspect(VALUE self)
}
}
+static void
+tracepoint_stat_event_hooks(VALUE hash, VALUE key, rb_event_hook_t *hook)
+{
+ int active = 0, deleted = 0;
+
+ while (hook) {
+ if (hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) {
+ deleted++;
+ }
+ else {
+ active++;
+ }
+ hook = hook->next;
+ }
+
+ rb_hash_aset(hash, key, rb_ary_new3(2, INT2FIX(active), INT2FIX(deleted)));
+}
+
+/*
+ * call-seq:
+ * TracePoint.stat -> obj
+ *
+ * Returns internal information of TracePoint.
+ *
+ * The contents of the returned value are implementation specific.
+ * It may be changed in future.
+ *
+ * This method is only for debugging TracePoint itself.
+ */
+
+static VALUE
+tracepoint_stat_s(VALUE self)
+{
+ rb_vm_t *vm = GET_VM();
+ VALUE stat = rb_hash_new();
+
+ tracepoint_stat_event_hooks(stat, vm->self, vm->event_hooks.hooks);
+ /* TODO: thread local hooks */
+
+ return stat;
+}
+
static void Init_postponed_job(void);
/* This function is called from inits.c */
@@ -1407,6 +1449,8 @@ Init_vm_trace(void)
rb_define_method(rb_cTracePoint, "return_value", tracepoint_attr_return_value, 0);
rb_define_method(rb_cTracePoint, "raised_exception", tracepoint_attr_raised_exception, 0);
+ rb_define_singleton_method(rb_cTracePoint, "stat", tracepoint_stat_s, 0);
+
/* initialized for postponed job */
Init_postponed_job();