From 645cd94d9a2383f973ae2fd83fef7024ae59c679 Mon Sep 17 00:00:00 2001 From: Chris Seaton Date: Wed, 7 Dec 2022 19:09:30 -0600 Subject: Add debug counters to RubyVM.stat (#6086) * Add debug counters to RubyVM.stat * Use SIZET2NUM Co-author: Nobuyoshi Nakada * Prefix debug_counter_names --- vm.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 3181f97123..d62b2f0d48 100644 --- a/vm.c +++ b/vm.c @@ -66,6 +66,8 @@ MJIT_FUNC_EXPORTED #endif VALUE vm_exec(rb_execution_context_t *, bool); +extern const char *const rb_debug_counter_names[]; + PUREFUNC(static inline const VALUE *VM_EP_LEP(const VALUE *)); static inline const VALUE * VM_EP_LEP(const VALUE *ep) @@ -578,6 +580,8 @@ rb_dtrace_setup(rb_execution_context_t *ec, VALUE klass, ID id, * :global_cvar_state=>27 * } * + * If USE_DEBUG_COUNTER is enabled, debug counters will be included. + * * The contents of the hash are implementation specific and may be changed in * the future. * @@ -622,6 +626,21 @@ vm_stat(int argc, VALUE *argv, VALUE self) SET(next_shape_id, (rb_serial_t)GET_VM()->next_shape_id); #undef SET +#if USE_DEBUG_COUNTER + ruby_debug_counter_show_at_exit(FALSE); + for (size_t i = 0; i < RB_DEBUG_COUNTER_MAX; i++) { + const VALUE name = rb_sym_intern_ascii_cstr(rb_debug_counter_names[i]); + const VALUE boxed_value = SIZET2NUM(rb_debug_counter[i]); + + if (key == name) { + return boxed_value; + } + else if (hash != Qnil) { + rb_hash_aset(hash, name, boxed_value); + } + } +#endif + if (!NIL_P(key)) { /* matched key should return above */ rb_raise(rb_eArgError, "unknown key: %"PRIsVALUE, rb_sym2str(key)); } -- cgit v1.2.3