ruby-changes:59457
From: Koichi <ko1@a...>
Date: Wed, 25 Dec 2019 01:36:11 +0900 (JST)
Subject: [ruby-changes:59457] 5220145ea2 (master): add debug_counter access functions.
https://git.ruby-lang.org/ruby.git/commit/?id=5220145ea2 From 5220145ea289d9eb955b373f31773fab2d4f0271 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Wed, 25 Dec 2019 01:32:37 +0900 Subject: add debug_counter access functions. These functions are enabled only on USE_DEBUG_COUNTER=1. diff --git a/debug_counter.c b/debug_counter.c index 1e395f3..11ec57a 100644 --- a/debug_counter.c +++ b/debug_counter.c @@ -8,8 +8,8 @@ https://github.com/ruby/ruby/blob/trunk/debug_counter.c#L8 **********************************************************************/ -#include "debug_counter.h" #include "internal.h" +#include "debug_counter.h" #include <stdio.h> #include <locale.h> @@ -25,6 +25,52 @@ MJIT_SYMBOL_EXPORT_BEGIN https://github.com/ruby/ruby/blob/trunk/debug_counter.c#L25 size_t rb_debug_counter[numberof(debug_counter_names)]; MJIT_SYMBOL_EXPORT_END +int debug_counter_disable_show_at_exit = 0; + +// note that this operation is not atomic. +void +ruby_debug_counter_reset(void) +{ + for (int i = 0; i < RB_DEBUG_COUNTER_MAX; i++) { + switch (i) { + case RB_DEBUG_COUNTER_mjit_length_unit_queue: + case RB_DEBUG_COUNTER_mjit_length_active_units: + case RB_DEBUG_COUNTER_mjit_length_compact_units: + case RB_DEBUG_COUNTER_mjit_length_stale_units: + // These counters may be decreased and should not be reset. + break; + default: + rb_debug_counter[i] = 0; + break; + } + } +} + +// note that this operation is not atomic. +size_t +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]; + } + } + if (counters_ptr != NULL) { + for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) { + counters_ptr[i] = rb_debug_counter[i]; + } + } + + return RB_DEBUG_COUNTER_MAX; +} + +void +ruby_debug_counter_show_at_exit(int enable) +{ + debug_counter_disable_show_at_exit = !enable; +} + void rb_debug_counter_show_results(const char *msg) { @@ -53,19 +99,7 @@ rb_debug_counter_show(RB_UNUSED_VAR(VALUE klass)) https://github.com/ruby/ruby/blob/trunk/debug_counter.c#L99 VALUE rb_debug_counter_reset(RB_UNUSED_VAR(VALUE klass)) { - for (int i = 0; i < RB_DEBUG_COUNTER_MAX; i++) { - switch (i) { - case RB_DEBUG_COUNTER_mjit_length_unit_queue: - case RB_DEBUG_COUNTER_mjit_length_active_units: - case RB_DEBUG_COUNTER_mjit_length_compact_units: - case RB_DEBUG_COUNTER_mjit_length_stale_units: - // These counters may be decreased and should not be reset. - break; - default: - rb_debug_counter[i] = 0; - break; - } - } + ruby_debug_counter_reset(); return Qnil; } @@ -73,11 +107,29 @@ __attribute__((destructor)) https://github.com/ruby/ruby/blob/trunk/debug_counter.c#L107 static void debug_counter_show_results_at_exit(void) { - rb_debug_counter_show_results("normal exit."); + if (debug_counter_disable_show_at_exit == 0) { + rb_debug_counter_show_results("normal exit."); + } } #else void rb_debug_counter_show_results(const char *msg) { } + +size_t +ruby_debug_counter_get(const char **names_ptr, size_t *counters_ptr) +{ + return 0; +} +void +ruby_debug_counter_reset(void) +{ +} + +void +ruby_debug_counter_show_at_exit(int enable) +{ +} + #endif /* USE_DEBUG_COUNTER */ diff --git a/debug_counter.h b/debug_counter.h index b9515f4..066533d 100644 --- a/debug_counter.h +++ b/debug_counter.h @@ -353,8 +353,6 @@ enum rb_debug_counter_type { https://github.com/ruby/ruby/blob/trunk/debug_counter.h#L353 }; #if USE_DEBUG_COUNTER -#include "ruby/ruby.h" - extern size_t rb_debug_counter[]; inline static int @@ -381,4 +379,12 @@ VALUE rb_debug_counter_show(VALUE klass); https://github.com/ruby/ruby/blob/trunk/debug_counter.h#L379 void rb_debug_counter_show_results(const char *msg); +RUBY_SYMBOL_EXPORT_BEGIN + +size_t ruby_debug_counter_get(const char **names_ptr, size_t *counters_ptr); +void ruby_debug_counter_reset(void); +void ruby_debug_counter_show_at_exit(int enable); + +RUBY_SYMBOL_EXPORT_END + #endif /* RUBY_DEBUG_COUNTER_H */ -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/