mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
76c4cca19c
* How to enable this feature? * define USE_DEBUG_COUNTER as 1. * you can disable to output the result with RUBY_DEBUG_COUNTER_DISABLE environment variable even if USE_DEBUG_COUNTER == 1. * How to add new counter? * add COUNTER(<name>) line on debug_counter.h. * include "debug_counter.h" * insert RB_DEBUG_COUNTER_INC(<name>) line on your favorite place. * counter output example: [RUBY_DEBUG_COUNTER] mc_inline_hit 999 [RUBY_DEBUG_COUNTER] mc_inline_miss 3 [RUBY_DEBUG_COUNTER] mc_global_hit 23 [RUBY_DEBUG_COUNTER] mc_global_miss 273 [RUBY_DEBUG_COUNTER] mc_global_state_miss 3 [RUBY_DEBUG_COUNTER] mc_class_serial_miss 0 [RUBY_DEBUG_COUNTER] mc_cme_complement 0 [RUBY_DEBUG_COUNTER] mc_cme_complement_hit 0 [RUBY_DEBUG_COUNTER] mc_search_super 1384 [RUBY_DEBUG_COUNTER] ivar_get_hit 0 [RUBY_DEBUG_COUNTER] ivar_get_miss 0 [RUBY_DEBUG_COUNTER] ivar_set_hit 0 [RUBY_DEBUG_COUNTER] ivar_set_miss 0 [RUBY_DEBUG_COUNTER] ivar_get 431 [RUBY_DEBUG_COUNTER] ivar_set 465 * mc_... is related to method caching. * ivar_... is related to instance variable accesses. * compare with dtrace/system tap features, there are completely no performacne penalties when it is disabled. * This feature is supported only on __GNUC__ compilers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
39 lines
906 B
C
39 lines
906 B
C
/**********************************************************************
|
|
|
|
debug_counter.c -
|
|
|
|
created at: Tue Feb 21 16:51:18 2017
|
|
|
|
Copyright (C) 2017 Koichi Sasada
|
|
|
|
**********************************************************************/
|
|
|
|
#include "debug_counter.h"
|
|
#include <stdio.h>
|
|
|
|
#if USE_DEBUG_COUNTER
|
|
|
|
/* do not modify manually. use a script above */
|
|
const char * const debug_counter_names[] = {
|
|
#include "debug_counter_names.inc"
|
|
""
|
|
};
|
|
|
|
size_t rb_debug_counter[RB_DEBUG_COUNTER_MAX + 1];
|
|
|
|
__attribute__((destructor))
|
|
static void
|
|
rb_debug_counter_show_results(void)
|
|
{
|
|
const char *env = getenv("RUBY_DEBUG_COUNTER_DISABLE");
|
|
if (env == NULL || strcmp("1", env) != 0) {
|
|
int i;
|
|
for (i=0; i<RB_DEBUG_COUNTER_MAX; i++) {
|
|
fprintf(stderr, "[RUBY_DEBUG_COUNTER]\t%s\t%"PRIuSIZE"\n",
|
|
debug_counter_names[i],
|
|
rb_debug_counter[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif /* USE_DEBUG_COUNTER */
|