From 70fd099220446e39bb80eb0bb32870ce12134619 Mon Sep 17 00:00:00 2001 From: Aaron Patterson 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) --- debug_counter.c | 7 +++++++ debug_counter.h | 1 + vm.c | 1 + 3 files changed, 9 insertions(+) diff --git a/debug_counter.c b/debug_counter.c index f17fb1c488..f17b3b4d7c 100644 --- a/debug_counter.c +++ b/debug_counter.c @@ -43,6 +43,13 @@ rb_debug_counter_show_results(const char *msg) } } +VALUE +rb_debug_counter_show(void) +{ + rb_debug_counter_show_results("method call"); + return Qnil; +} + VALUE rb_debug_counter_reset(void) { diff --git a/debug_counter.h b/debug_counter.h index ef35c55e6e..3fa644828d 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) } 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 b4e2e3c5e6..a0a04c6337 100644 --- a/vm.c +++ b/vm.c @@ -2916,6 +2916,7 @@ Init_VM(void) 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 v1.2.3