ruby-changes:56868
From: Aaron <ko1@a...>
Date: Thu, 8 Aug 2019 02:36:44 +0900 (JST)
Subject: [ruby-changes:56868] Aaron Patterson: 70fd099220 (master): Add a way to print debug counters without exiting
https://git.ruby-lang.org/ruby.git/commit/?id=70fd099220 From 70fd099220446e39bb80eb0bb32870ce12134619 Mon Sep 17 00:00:00 2001 From: Aaron Patterson <tenderlove@r...> Date: Tue, 6 Aug 2019 12:23:30 -0700 Subject: Add a way to print debug counters without exiting I am trying to study debug counters inside a Rails application. Accessing debug counters by killing the process is hard because child processes don't get the same TRAP as the parent, and Rails seems to intercept calls to `exit`. Adding this method lets me print the debug counters when I want (at the end of requests for example) diff --git a/debug_counter.c b/debug_counter.c index f17fb1c..f17b3b4 100644 --- a/debug_counter.c +++ b/debug_counter.c @@ -44,6 +44,13 @@ rb_debug_counter_show_results(const char *msg) https://github.com/ruby/ruby/blob/trunk/debug_counter.c#L44 } VALUE +rb_debug_counter_show(void) +{ + rb_debug_counter_show_results("method call"); + return Qnil; +} + +VALUE rb_debug_counter_reset(void) { for (int i = 0; i < RB_DEBUG_COUNTER_MAX; i++) { diff --git a/debug_counter.h b/debug_counter.h index ef35c55..3fa6448 100644 --- a/debug_counter.h +++ b/debug_counter.h @@ -350,6 +350,7 @@ rb_debug_counter_add(enum rb_debug_counter_type type, int add, int cond) https://github.com/ruby/ruby/blob/trunk/debug_counter.h#L350 } VALUE rb_debug_counter_reset(void); +VALUE rb_debug_counter_show(void); #define RB_DEBUG_COUNTER_INC(type) rb_debug_counter_add(RB_DEBUG_COUNTER_##type, 1, 1) #define RB_DEBUG_COUNTER_INC_UNLESS(type, cond) (!rb_debug_counter_add(RB_DEBUG_COUNTER_##type, 1, !(cond))) diff --git a/vm.c b/vm.c index b4e2e3c..a0a04c6 100644 --- a/vm.c +++ b/vm.c @@ -2916,6 +2916,7 @@ Init_VM(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L2916 rb_define_singleton_method(rb_cRubyVM, "stat", vm_stat, -1); #if USE_DEBUG_COUNTER rb_define_singleton_method(rb_cRubyVM, "reset_debug_counters", rb_debug_counter_reset, 0); + rb_define_singleton_method(rb_cRubyVM, "show_debug_counters", rb_debug_counter_show, 0); #endif /* FrozenCore (hidden) */ -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/