summaryrefslogtreecommitdiff
path: root/debug_counter.h
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-21 08:18:15 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-21 08:18:15 +0000
commit76c4cca19c0c27b1c3ca6f597384707cccf3de06 (patch)
treebcb13fed3f68e50cbca8a4bd475157d9bfeb7dca /debug_counter.h
parent51de3aa2b27859305c74d5664724192602c4608f (diff)
downloadruby-76c4cca19c0c27b1c3ca6f597384707cccf3de06.tar.gz
add performance counting mechanism for MRI debug/tuning purpose.
* 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
Diffstat (limited to 'debug_counter.h')
-rw-r--r--debug_counter.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/debug_counter.h b/debug_counter.h
new file mode 100644
index 0000000000..e16d5fae4a
--- /dev/null
+++ b/debug_counter.h
@@ -0,0 +1,67 @@
+/**********************************************************************
+
+ debug_counter.h -
+
+ created at: Tue Feb 21 16:51:18 2017
+
+ Copyright (C) 2017 Koichi Sasada
+
+**********************************************************************/
+
+#ifndef RUBY_DEBUG_COUNTER_H
+#define RUBY_DEBUG_COUNTER_H 1
+
+#ifndef USE_DEBUG_COUNTER
+#define USE_DEBUG_COUNTER 0
+#endif
+
+#if !defined(__GNUC__) && USE_DEBUG_COUNTER
+#error "USE_DEBUG_COUNTER is not supported by other than __GNUC__"
+#endif
+
+enum rb_debug_counter_type {
+#define COUNTER(name) RB_DEBUG_COUNTER_##name
+ COUNTER(mc_inline_hit),
+ COUNTER(mc_inline_miss),
+ COUNTER(mc_global_hit),
+ COUNTER(mc_global_miss),
+ COUNTER(mc_global_state_miss),
+ COUNTER(mc_class_serial_miss),
+ COUNTER(mc_cme_complement),
+ COUNTER(mc_cme_complement_hit),
+ COUNTER(mc_search_super),
+ COUNTER(ivar_get_hit),
+ COUNTER(ivar_get_miss),
+ COUNTER(ivar_set_hit),
+ COUNTER(ivar_set_miss),
+ COUNTER(ivar_get),
+ COUNTER(ivar_set),
+ RB_DEBUG_COUNTER_MAX
+#undef COUNTER
+};
+
+#if USE_DEBUG_COUNTER
+#include "ruby/ruby.h"
+
+extern size_t rb_debug_counter[RB_DEBUG_COUNTER_MAX + 1];
+
+inline static int
+rb_debug_counter_add(enum rb_debug_counter_type type, int add, int cond)
+{
+ if (cond) {
+ rb_debug_counter[(int)type] += add;
+ }
+ return cond;
+}
+
+#define RB_DEBUG_COUNTER_INC(type) rb_debug_counter_add(RB_DEBUG_COUNTER_##type, 1, 1)
+#define RB_DEBUG_COUNTER_INC_UNLESS(type, cond) (!rb_debug_counter_add(RB_DEBUG_COUNTER_##type, 1, !(cond)))
+#define RB_DEBUG_COUNTER_INC_IF(type, cond) rb_debug_counter_add(RB_DEBUG_COUNTER_##type, 1, (cond))
+
+#else
+#define RB_DEBUG_COUNTER_INC(type) ((void)0)
+#define RB_DEBUG_COUNTER_INC_UNLESS(type, cond) (cond)
+#define RB_DEBUG_COUNTER_INC_IF(type, cond) (cond)
+#endif
+
+#endif /* RUBY_DEBUG_COUNTER_H */