11#include "debug_counter.h"
19static const char *
const debug_counter_names[] = {
21#define RB_DEBUG_COUNTER(name) #name,
22#include "debug_counter.h"
23#undef RB_DEBUG_COUNTER
26MJIT_SYMBOL_EXPORT_BEGIN
27size_t rb_debug_counter[numberof(debug_counter_names)];
28void rb_debug_counter_add_atomic(
enum rb_debug_counter_type
type,
int add);
33__attribute__((constructor))
35debug_counter_setup(
void)
41rb_debug_counter_add_atomic(
enum rb_debug_counter_type
type,
int add)
45 rb_debug_counter[(int)
type] += add;
50int debug_counter_disable_show_at_exit = 0;
54ruby_debug_counter_reset(
void)
56 for (
int i = 0; i < RB_DEBUG_COUNTER_MAX; i++) {
58 case RB_DEBUG_COUNTER_mjit_length_unit_queue:
59 case RB_DEBUG_COUNTER_mjit_length_active_units:
60 case RB_DEBUG_COUNTER_mjit_length_compact_units:
61 case RB_DEBUG_COUNTER_mjit_length_stale_units:
65 rb_debug_counter[i] = 0;
73ruby_debug_counter_get(
const char **names_ptr,
size_t *counters_ptr)
76 if (names_ptr != NULL) {
77 for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
78 names_ptr[i] = debug_counter_names[i];
81 if (counters_ptr != NULL) {
82 for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
83 counters_ptr[i] = rb_debug_counter[i];
87 return RB_DEBUG_COUNTER_MAX;
91ruby_debug_counter_show_at_exit(
int enable)
93 debug_counter_disable_show_at_exit = !enable;
97rb_debug_counter_show_results(
const char *msg)
99 const char *env = getenv(
"RUBY_DEBUG_COUNTER_DISABLE");
101 setlocale(LC_NUMERIC,
"");
103 if (env == NULL || strcmp(
"1", env) != 0) {
105 fprintf(stderr,
"[RUBY_DEBUG_COUNTER]\t%d %s\n", getpid(), msg);
106 for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
107 fprintf(stderr,
"[RUBY_DEBUG_COUNTER]\t%-30s\t%'14"PRIuSIZE
"\n",
108 debug_counter_names[i],
109 rb_debug_counter[i]);
115rb_debug_counter_show(RB_UNUSED_VAR(VALUE klass))
117 rb_debug_counter_show_results(
"show_debug_counters");
118 ruby_debug_counter_show_at_exit(FALSE);
123rb_debug_counter_reset(RB_UNUSED_VAR(VALUE klass))
125 ruby_debug_counter_reset();
129__attribute__((destructor))
131debug_counter_show_results_at_exit(
void)
133 if (debug_counter_disable_show_at_exit == 0) {
134 rb_debug_counter_show_results(
"normal exit.");
141rb_debug_counter_show_results(
const char *msg)
146ruby_debug_counter_get(
const char **names_ptr,
size_t *counters_ptr)
151ruby_debug_counter_reset(
void)
156ruby_debug_counter_show_at_exit(
int enable)
#define Qnil
Old name of RUBY_Qnil.
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock)
Blocks until the current thread obtains a lock.
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
Releases a lock.
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock)
Fills the passed lock with an initial value.