From e7b0a01002323d9ed8eed9abca2a4979ebe9ae32 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Fri, 9 Feb 2024 14:12:24 -0800 Subject: YJIT: Add top ISEQ call counts to --yjit-stats (#9906) --- yjit.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'yjit.c') diff --git a/yjit.c b/yjit.c index cf6d81092f..4e9fed35ae 100644 --- a/yjit.c +++ b/yjit.c @@ -895,6 +895,30 @@ rb_yjit_dump_iseq_loc(const rb_iseq_t *iseq, uint32_t insn_idx) fprintf(stderr, "%s %.*s:%u\n", __func__, (int)len, ptr, rb_iseq_line_no(iseq, insn_idx)); } +// Get the number of digits required to print an integer +static int +num_digits(int integer) +{ + int num = 1; + while (integer /= 10) { + num++; + } + return num; +} + +// Allocate a C string that formats an ISEQ label like iseq_inspect() +char * +rb_yjit_iseq_inspect(const rb_iseq_t *iseq) +{ + const char *label = RSTRING_PTR(iseq->body->location.label); + const char *path = RSTRING_PTR(rb_iseq_path(iseq)); + int lineno = iseq->body->location.code_location.beg_pos.lineno; + + char *buf = ZALLOC_N(char, strlen(label) + strlen(path) + num_digits(lineno) + 3); + sprintf(buf, "%s@%s:%d", label, path, lineno); + return buf; +} + // The FL_TEST() macro VALUE rb_FL_TEST(VALUE obj, VALUE flags) -- cgit v1.2.3