2017-02-21 11:18:15 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
debug_counter.c -
|
|
|
|
|
|
|
|
created at: Tue Feb 21 16:51:18 2017
|
|
|
|
|
|
|
|
Copyright (C) 2017 Koichi Sasada
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#include "debug_counter.h"
|
|
|
|
#if USE_DEBUG_COUNTER
|
2018-09-25 21:13:29 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <locale.h>
|
2017-03-10 10:18:03 +03:00
|
|
|
#include "internal.h"
|
2017-02-21 11:18:15 +03:00
|
|
|
|
2017-03-10 10:18:03 +03:00
|
|
|
static const char *const debug_counter_names[] = {
|
2017-02-21 11:18:15 +03:00
|
|
|
""
|
2017-03-10 10:18:03 +03:00
|
|
|
#define RB_DEBUG_COUNTER(name) #name,
|
|
|
|
#include "debug_counter.h"
|
|
|
|
#undef RB_DEBUG_COUNTER
|
2017-02-21 11:18:15 +03:00
|
|
|
};
|
|
|
|
|
2017-03-10 10:18:03 +03:00
|
|
|
size_t rb_debug_counter[numberof(debug_counter_names)];
|
2017-02-21 11:18:15 +03:00
|
|
|
|
2018-09-25 21:13:29 +03:00
|
|
|
void
|
|
|
|
rb_debug_counter_show_results(const char *msg)
|
2017-02-21 11:18:15 +03:00
|
|
|
{
|
|
|
|
const char *env = getenv("RUBY_DEBUG_COUNTER_DISABLE");
|
2018-09-25 21:13:29 +03:00
|
|
|
|
|
|
|
setlocale(LC_NUMERIC, "");
|
|
|
|
|
2017-02-21 11:18:15 +03:00
|
|
|
if (env == NULL || strcmp("1", env) != 0) {
|
|
|
|
int i;
|
2018-09-25 21:13:29 +03:00
|
|
|
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%d %s\n", getpid(), msg);
|
2017-02-21 11:18:15 +03:00
|
|
|
for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
|
2018-09-28 04:10:43 +03:00
|
|
|
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%-30s\t%'14"PRIuSIZE"\n",
|
2017-02-21 11:18:15 +03:00
|
|
|
debug_counter_names[i],
|
|
|
|
rb_debug_counter[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 21:13:29 +03:00
|
|
|
__attribute__((destructor))
|
|
|
|
static void
|
|
|
|
debug_counter_show_results_at_exit(void)
|
|
|
|
{
|
|
|
|
rb_debug_counter_show_results("normal exit.");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
rb_debug_counter_show_results(const char *msg)
|
|
|
|
{
|
|
|
|
}
|
2017-02-21 11:18:15 +03:00
|
|
|
#endif /* USE_DEBUG_COUNTER */
|