summaryrefslogtreecommitdiff
path: root/vm_exec.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2019-12-28 00:44:09 -0800
committerGitHub <noreply@github.com>2019-12-28 00:44:09 -0800
commita994b0aee73a78de1137f195fb252b3660199f0b (patch)
treed62127e73cc8224cf5a1a262065df72850890bb4 /vm_exec.c
parentbf04fe086bca47184c6ab13603e064b3c0e88d8e (diff)
Add VM insns counter like debug_counter (#2789)
Notes
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
Diffstat (limited to 'vm_exec.c')
-rw-r--r--vm_exec.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/vm_exec.c b/vm_exec.c
index 0adaa7b721..2c7e22228a 100644
--- a/vm_exec.c
+++ b/vm_exec.c
@@ -15,6 +15,36 @@
static void vm_analysis_insn(int insn);
#endif
+#if USE_INSNS_COUNTER
+static size_t rb_insns_counter[VM_INSTRUCTION_SIZE];
+
+static void
+vm_insns_counter_count_insn(int insn)
+{
+ rb_insns_counter[insn]++;
+}
+
+__attribute__((destructor))
+static void
+vm_insns_counter_show_results_at_exit(void)
+{
+ int insn_end = (ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS)
+ ? VM_INSTRUCTION_SIZE : VM_INSTRUCTION_SIZE / 2;
+
+ size_t total = 0;
+ for (int insn = 0; insn < insn_end; insn++)
+ total += rb_insns_counter[insn];
+
+ for (int insn = 0; insn < insn_end; insn++) {
+ fprintf(stderr, "[RUBY_INSNS_COUNTER]\t%-32s%'12"PRIuSIZE" (%4.1f%%)\n",
+ insn_name(insn), rb_insns_counter[insn],
+ 100.0 * rb_insns_counter[insn] / total);
+ }
+}
+#else
+static void vm_insns_counter_count_insn(int insn) {}
+#endif
+
#if VMDEBUG > 0
#define DECL_SC_REG(type, r, reg) register type reg_##r