11#include "debug_counter.h"
19const char *
const rb_debug_counter_names[] = {
20#define DEBUG_COUNTER_NAME_EMPTY ""
21 DEBUG_COUNTER_NAME_EMPTY
22#undef DEBUG_COUNTER_NAME_EMPTY
23#define RB_DEBUG_COUNTER(name) #name,
24#include "debug_counter.h"
25#undef RB_DEBUG_COUNTER
28size_t rb_debug_counter[numberof(rb_debug_counter_names)];
29void rb_debug_counter_add_atomic(
enum rb_debug_counter_type
type,
int add);
31static rb_nativethread_lock_t debug_counter_lock;
35debug_counter_setup(
void)
41rb_debug_counter_add_atomic(
enum rb_debug_counter_type
type,
int add)
45 rb_debug_counter[(int)
type] += add;
50static int debug_counter_disable_show_at_exit = 0;
54ruby_debug_counter_reset(
void)
56 for (
int i = 0; i < RB_DEBUG_COUNTER_MAX; i++) {
57 rb_debug_counter[i] = 0;
63ruby_debug_counter_get(
const char **names_ptr,
size_t *counters_ptr)
66 if (names_ptr != NULL) {
67 for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
68 names_ptr[i] = rb_debug_counter_names[i];
71 if (counters_ptr != NULL) {
72 for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
73 counters_ptr[i] = rb_debug_counter[i];
77 return RB_DEBUG_COUNTER_MAX;
81ruby_debug_counter_show_at_exit(
int enable)
83 debug_counter_disable_show_at_exit = !enable;
87rb_debug_counter_show_results(
const char *msg)
89 const char *env = getenv(
"RUBY_DEBUG_COUNTER_DISABLE");
91 setlocale(LC_NUMERIC,
"");
93 if (env == NULL || strcmp(
"1", env) != 0) {
95 fprintf(stderr,
"[RUBY_DEBUG_COUNTER]\t%d %s\n", getpid(), msg);
96 for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
97 fprintf(stderr,
"[RUBY_DEBUG_COUNTER]\t%-30s\t%'14"PRIuSIZE
"\n",
98 rb_debug_counter_names[i],
105rb_debug_counter_show(RB_UNUSED_VAR(
VALUE klass))
107 rb_debug_counter_show_results(
"show_debug_counters");
108 ruby_debug_counter_show_at_exit(FALSE);
113rb_debug_counter_reset(RB_UNUSED_VAR(
VALUE klass))
115 ruby_debug_counter_reset();
121debug_counter_show_results_at_exit(
void)
123 if (debug_counter_disable_show_at_exit == 0) {
124 rb_debug_counter_show_results(
"normal exit.");
131rb_debug_counter_show_results(
const char *msg)
136ruby_debug_counter_get(
const char **names_ptr,
size_t *counters_ptr)
141ruby_debug_counter_reset(
void)
146ruby_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.
uintptr_t VALUE
Type that represents a Ruby object.