summaryrefslogtreecommitdiff
path: root/yjit.c
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2024-02-09 14:12:24 -0800
committerGitHub <[email protected]>2024-02-09 22:12:24 +0000
commite7b0a01002323d9ed8eed9abca2a4979ebe9ae32 (patch)
tree2e66274fb4d260e38a368717a92d283e9d4ee7c4 /yjit.c
parentf7467e70e1803a230f9a0bf013c8134c1dde2c94 (diff)
YJIT: Add top ISEQ call counts to --yjit-stats (#9906)
Diffstat (limited to 'yjit.c')
-rw-r--r--yjit.c24
1 files changed, 24 insertions, 0 deletions
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)