From 48736599ace66fe6bd205e3df2979563f04e0a30 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Tue, 16 Feb 2021 11:15:29 -0500 Subject: [PATCH] Fix compiled iseq count stat --- ujit_core.c | 5 ++++- ujit_iface.c | 7 ++++--- ujit_iface.h | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ujit_core.c b/ujit_core.c index 603d7a34e2..ef76637d54 100644 --- a/ujit_core.c +++ b/ujit_core.c @@ -164,13 +164,16 @@ add_block_version(blockid_t blockid, block_t* block) const rb_iseq_t *iseq = block->blockid.iseq; struct rb_iseq_constant_body *body = iseq->body; - // Ensure ujit_blocks is initialized + // Ensure ujit_blocks is initialized for this iseq if (rb_darray_size(body->ujit_blocks) == 0) { // Initialize ujit_blocks to be as wide as body->iseq_encoded // TODO: add resize API for dary while ((unsigned)rb_darray_size(body->ujit_blocks) < body->iseq_size) { (void)rb_darray_append(&body->ujit_blocks, NULL); } + + // First block compiled for this iseq + rb_compiled_iseq_count++; } block_t *first_version = get_first_version(iseq, blockid.idx); diff --git a/ujit_iface.c b/ujit_iface.c index e25d515d17..2a6f4fea90 100644 --- a/ujit_iface.c +++ b/ujit_iface.c @@ -29,10 +29,12 @@ bool rb_ujit_enabled; static int64_t vm_insns_count = 0; int64_t rb_ujit_exec_insns_count = 0; static int64_t exit_op_count[VM_INSTRUCTION_SIZE] = { 0 }; -static int64_t compiled_iseq_count = 0; +int64_t rb_compiled_iseq_count = 0; +// Machine code blocks (executable memory) extern codeblock_t *cb; extern codeblock_t *ocb; + // Hash table of encoded instructions extern st_table *rb_encoded_insn_data; @@ -312,7 +314,6 @@ rb_ujit_compile_iseq(const rb_iseq_t *iseq) int first_opcode = opcode_at_pc(iseq, &encoded[0]); map_addr2insn(code_ptr, first_opcode); encoded[0] = (VALUE)code_ptr; - compiled_iseq_count++; } RB_VM_LOCK_LEAVE(); @@ -540,7 +541,7 @@ print_ujit_stats(void) double total_insns_count = vm_insns_count + rb_ujit_exec_insns_count; double ratio = rb_ujit_exec_insns_count / total_insns_count; - fprintf(stderr, "compiled_iseq_count: %10" PRId64 "\n", compiled_iseq_count); + fprintf(stderr, "compiled_iseq_count: %10" PRId64 "\n", rb_compiled_iseq_count); fprintf(stderr, "main_block_code_size: %6.1f MiB\n", ((double)cb->write_pos) / 1048576.0); fprintf(stderr, "side_block_code_size: %6.1f MiB\n", ((double)ocb->write_pos) / 1048576.0); fprintf(stderr, "vm_insns_count: %10" PRId64 "\n", vm_insns_count); diff --git a/ujit_iface.h b/ujit_iface.h index bab86ec7e7..620dc57dd1 100644 --- a/ujit_iface.h +++ b/ujit_iface.h @@ -22,6 +22,7 @@ struct rb_callcache; RUBY_EXTERN struct rb_ujit_options rb_ujit_opts; RUBY_EXTERN int64_t rb_ujit_exec_insns_count; +RUBY_EXTERN int64_t rb_compiled_iseq_count; void cb_write_pre_call_bytes(codeblock_t* cb); void cb_write_post_call_bytes(codeblock_t* cb);