Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug counters to RubyVM.stat #6086

Merged
merged 3 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions debug_counter.c
Expand Up @@ -16,7 +16,7 @@

#if USE_DEBUG_COUNTER

static const char *const debug_counter_names[] = {
const char *const rb_debug_counter_names[] = {
#define DEBUG_COUNTER_NAME_EMPTY "" /* Suppress -Wstring-concatenation */
DEBUG_COUNTER_NAME_EMPTY
#undef DEBUG_COUNTER_NAME_EMPTY
Expand All @@ -26,7 +26,7 @@ static const char *const debug_counter_names[] = {
};

MJIT_SYMBOL_EXPORT_BEGIN
size_t rb_debug_counter[numberof(debug_counter_names)];
size_t rb_debug_counter[numberof(rb_debug_counter_names)];
void rb_debug_counter_add_atomic(enum rb_debug_counter_type type, int add);
MJIT_SYMBOL_EXPORT_END

Expand Down Expand Up @@ -77,7 +77,7 @@ ruby_debug_counter_get(const char **names_ptr, size_t *counters_ptr)
int i;
if (names_ptr != NULL) {
for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
names_ptr[i] = debug_counter_names[i];
names_ptr[i] = rb_debug_counter_names[i];
}
}
if (counters_ptr != NULL) {
Expand Down Expand Up @@ -107,7 +107,7 @@ rb_debug_counter_show_results(const char *msg)
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%d %s\n", getpid(), msg);
for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%-30s\t%'14"PRIuSIZE"\n",
debug_counter_names[i],
rb_debug_counter_names[i],
rb_debug_counter[i]);
}
}
Expand Down
19 changes: 19 additions & 0 deletions vm.c
Expand Up @@ -65,6 +65,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)
Expand Down Expand Up @@ -518,6 +520,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.
*
Expand Down Expand Up @@ -562,6 +566,21 @@ vm_stat(int argc, VALUE *argv, VALUE self)
SET(global_cvar_state, ruby_vm_global_cvar_state);
#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));
}
Expand Down