2017-02-21 03:18:15 -05:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
debug_counter.c -
|
|
|
|
|
|
|
|
created at: Tue Feb 21 16:51:18 2017
|
|
|
|
|
|
|
|
Copyright (C) 2017 Koichi Sasada
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#include "debug_counter.h"
|
2019-12-11 14:31:38 -05:00
|
|
|
#include "internal.h"
|
2018-09-25 14:13:29 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <locale.h>
|
2017-02-21 03:18:15 -05:00
|
|
|
|
2019-08-07 10:22:06 -04:00
|
|
|
#if USE_DEBUG_COUNTER
|
2017-03-10 02:18:03 -05:00
|
|
|
static const char *const debug_counter_names[] = {
|
2017-02-21 03:18:15 -05:00
|
|
|
""
|
2017-03-10 02:18:03 -05:00
|
|
|
#define RB_DEBUG_COUNTER(name) #name,
|
|
|
|
#include "debug_counter.h"
|
|
|
|
#undef RB_DEBUG_COUNTER
|
2017-02-21 03:18:15 -05:00
|
|
|
};
|
|
|
|
|
2019-03-29 09:54:29 -04:00
|
|
|
MJIT_SYMBOL_EXPORT_BEGIN
|
2017-03-10 02:18:03 -05:00
|
|
|
size_t rb_debug_counter[numberof(debug_counter_names)];
|
2019-03-29 09:54:29 -04:00
|
|
|
MJIT_SYMBOL_EXPORT_END
|
2017-02-21 03:18:15 -05:00
|
|
|
|
2018-09-25 14:13:29 -04:00
|
|
|
void
|
|
|
|
rb_debug_counter_show_results(const char *msg)
|
2017-02-21 03:18:15 -05:00
|
|
|
{
|
|
|
|
const char *env = getenv("RUBY_DEBUG_COUNTER_DISABLE");
|
2018-09-25 14:13:29 -04:00
|
|
|
|
|
|
|
setlocale(LC_NUMERIC, "");
|
|
|
|
|
2017-02-21 03:18:15 -05:00
|
|
|
if (env == NULL || strcmp("1", env) != 0) {
|
|
|
|
int i;
|
2018-09-25 14:13:29 -04:00
|
|
|
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%d %s\n", getpid(), msg);
|
2017-02-21 03:18:15 -05:00
|
|
|
for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
|
2018-09-27 21:10:43 -04:00
|
|
|
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%-30s\t%'14"PRIuSIZE"\n",
|
2017-02-21 03:18:15 -05:00
|
|
|
debug_counter_names[i],
|
|
|
|
rb_debug_counter[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 15:23:30 -04:00
|
|
|
VALUE
|
Fix rb_define_singleton_method warning
for debug counters
```
../include/ruby/intern.h:1175:137: warning: passing argument 3 of 'rb_define_singleton_method0' from incompatible pointer type [-Wincompatible-pointer-types]
#define rb_define_singleton_method(klass, mid, func, arity) rb_define_singleton_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity));
^
../vm.c:2958:5: note: in expansion of macro 'rb_define_singleton_method'
rb_define_singleton_method(rb_cRubyVM, "show_debug_counters", rb_debug_counter_show, 0);
^~~~~~~~~~~~~~~~~~~~~~~~~~
../include/ruby/intern.h:1139:99: note: expected 'VALUE (*)(VALUE) {aka long unsigned int (*)(long unsigned int)}' but argument is of type 'VALUE (*)(void) {aka long unsigned int (*)(void)}'
__attribute__((__unused__,__weakref__("rb_define_singleton_method"),__nonnull__(2,3)))static void rb_define_singleton_method0 (VALUE,const char*,VALUE(*)(VALUE),int);
```
2019-09-20 04:44:16 -04:00
|
|
|
rb_debug_counter_show(RB_UNUSED_VAR(VALUE klass))
|
2019-08-06 15:23:30 -04:00
|
|
|
{
|
|
|
|
rb_debug_counter_show_results("method call");
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2019-04-14 02:57:21 -04:00
|
|
|
VALUE
|
Fix rb_define_singleton_method warning
for debug counters
```
../include/ruby/intern.h:1175:137: warning: passing argument 3 of 'rb_define_singleton_method0' from incompatible pointer type [-Wincompatible-pointer-types]
#define rb_define_singleton_method(klass, mid, func, arity) rb_define_singleton_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity));
^
../vm.c:2958:5: note: in expansion of macro 'rb_define_singleton_method'
rb_define_singleton_method(rb_cRubyVM, "show_debug_counters", rb_debug_counter_show, 0);
^~~~~~~~~~~~~~~~~~~~~~~~~~
../include/ruby/intern.h:1139:99: note: expected 'VALUE (*)(VALUE) {aka long unsigned int (*)(long unsigned int)}' but argument is of type 'VALUE (*)(void) {aka long unsigned int (*)(void)}'
__attribute__((__unused__,__weakref__("rb_define_singleton_method"),__nonnull__(2,3)))static void rb_define_singleton_method0 (VALUE,const char*,VALUE(*)(VALUE),int);
```
2019-09-20 04:44:16 -04:00
|
|
|
rb_debug_counter_reset(RB_UNUSED_VAR(VALUE klass))
|
2019-04-14 02:57:21 -04:00
|
|
|
{
|
|
|
|
for (int i = 0; i < RB_DEBUG_COUNTER_MAX; i++) {
|
2019-04-14 03:10:34 -04:00
|
|
|
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:
|
2019-04-14 03:12:44 -04:00
|
|
|
case RB_DEBUG_COUNTER_mjit_length_stale_units:
|
2019-04-14 03:10:34 -04:00
|
|
|
// These counters may be decreased and should not be reset.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb_debug_counter[i] = 0;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-14 02:57:21 -04:00
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2018-09-25 14:13:29 -04: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 03:18:15 -05:00
|
|
|
#endif /* USE_DEBUG_COUNTER */
|