diff options
author | Chris Seaton <chris.seaton@shopify.com> | 2022-12-07 19:09:30 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-07 17:09:30 -0800 |
commit | 645cd94d9a2383f973ae2fd83fef7024ae59c679 (patch) | |
tree | 8228e9a5407f6ef19f7c652c489e550b0204eb89 /vm.c | |
parent | a2d3f5606a241999feda113f7331cf1a637bcaf0 (diff) |
Add debug counters to RubyVM.stat (#6086)
* Add debug counters to RubyVM.stat
* Use SIZET2NUM
Co-author: Nobuyoshi Nakada <nobu@ruby-lang.org>
* Prefix debug_counter_names
Notes
Notes:
Merged-By: k0kubun <takashikkbn@gmail.com>
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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 <tt>USE_DEBUG_COUNTER</tt> 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)); } |