[前][次][番号順一覧][スレッド一覧]

ruby-changes:34339

From: ko1 <ko1@a...>
Date: Fri, 13 Jun 2014 18:01:31 +0900 (JST)
Subject: [ruby-changes:34339] ko1:r46420 (trunk): * vm_trace.c: add new method TracePoint.stat to debug

ko1	2014-06-13 18:01:21 +0900 (Fri, 13 Jun 2014)

  New Revision: 46420

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46420

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/test/runner.rb
    trunk/vm_trace.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46419)
+++ ChangeLog	(revision 46420)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jun 13 17:58:58 2014  Koichi Sasada  <ko1@a...>
+
+	* 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.
+
 Fri Jun 13 17:46:31 2014  Koichi Sasada  <ko1@a...>
 
 	* vm_trace.c: clear and restore recursive checking thread local data
Index: vm_trace.c
===================================================================
--- vm_trace.c	(revision 46419)
+++ vm_trace.c	(revision 46420)
@@ -1314,6 +1314,48 @@ tracepoint_inspect(VALUE self) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1314
     }
 }
 
+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) https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1449
     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();
Index: test/runner.rb
===================================================================
--- test/runner.rb	(revision 46419)
+++ test/runner.rb	(revision 46420)
@@ -22,6 +22,12 @@ module Test::Unit https://github.com/ruby/ruby/blob/trunk/test/runner.rb#L22
     def after_teardown
       super
       assert_empty(Process.waitall)
+
+      # detect zombie traces.
+      TracePoint.stat.each{|key, (activated, deleted)|
+        assert_equal(0, activated, 'The number of active trace events should be zero.')
+        # puts "TracePoint - deleted: #{deleted}" if deleted > 0
+      }
     end
   end
   class TestCase

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]