ruby-changes:60402
From: Takashi <ko1@a...>
Date: Sun, 15 Mar 2020 12:43:51 +0900 (JST)
Subject: [ruby-changes:60402] cecebf55c4 (master): Use a human-readable funcname with --jit-debug
https://git.ruby-lang.org/ruby.git/commit/?id=cecebf55c4 From cecebf55c476ae936f3e880477dfb62149143c46 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Sat, 14 Mar 2020 20:38:48 -0700 Subject: Use a human-readable funcname with --jit-debug for perf output like: Samples: 100K of event 'cycles:ppp', Event count (approx.): 1007750000 Children Self Command Shared Object Symbol + 81.58% 1.47% ruby ruby [.] rb_vm_exec + 81.06% 7.61% ruby ruby [.] vm_exec_core + 80.16% 0.00% ruby ruby [.] vm_sendish (inlined) + 75.03% 0.00% ruby ruby [.] mjit_exec (inlined) + 74.37% 0.00% ruby ruby [.] mjit_exec (inlined) + 73.42% 0.22% ruby _ruby_mjit_p11277u42.so [.] _mjit42_rack_method_override_rb_call + 73.25% 0.10% ruby _ruby_mjit_p11277u41.so [.] _mjit41_sinatra_show_exceptions_rb_call + 73.19% 0.22% ruby _ruby_mjit_p11277u44.so [.] _mjit44_rack_head_rb_call + 73.03% 0.15% ruby _ruby_mjit_p11277u45.so [.] _mjit45_sinatra_base_rb_call + 72.87% 0.26% ruby _ruby_mjit_p11277u49.so [.] _mjit49_rack_logger_rb_call + 70.56% 0.11% ruby _ruby_mjit_p11277u40.so [.] _mjit40_sinatra_base_rb_call + 68.70% 0.11% ruby _ruby_mjit_p11277u39.so [.] _mjit39_sinatra_base_rb_call + 68.39% 0.29% ruby _ruby_mjit_p11277u56.so [.] _mjit56_rack_protection_frame_options_rb_call + 67.89% 0.18% ruby _ruby_mjit_p11277u37.so [.] _mjit37_sinatra_base_rb_block_in_call + 67.04% 0.16% ruby _ruby_mjit_p11277u34.so [.] _mjit34_sinatra_base_rb_synchronize diff --git a/mjit_worker.c b/mjit_worker.c index e735045..9df7bc6 100644 --- a/mjit_worker.c +++ b/mjit_worker.c @@ -92,6 +92,7 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L92 #include "ruby_assert.h" #include "ruby/debug.h" #include "ruby/thread.h" +#include "ruby/version.h" #ifdef _WIN32 #include <winsock2.h> @@ -688,6 +689,40 @@ remove_so_file(const char *so_file, struct rb_mjit_unit *unit) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L689 #endif } +// Print _mjitX, but make a human-readable funcname when --jit-debug is used +static void +sprint_funcname(char *funcname, const struct rb_mjit_unit *unit) +{ + const rb_iseq_t *iseq = unit->iseq; + if (iseq == NULL || (!mjit_opts.debug && !mjit_opts.debug_flags)) { + sprintf(funcname, "_mjit%d", unit->id); + return; + } + + // Generate a short path + const char *path = RSTRING_PTR(rb_iseq_path(iseq)); + const char *lib = "/lib/"; + const char *version = "/" STRINGIZE(RUBY_API_VERSION_MAJOR) "." STRINGIZE(RUBY_API_VERSION_MINOR) "." STRINGIZE(RUBY_API_VERSION_TEENY) "/"; + while (strstr(path, lib)) // skip "/lib/" + path = strstr(path, lib) + strlen(lib); + while (strstr(path, version)) // skip "/x.y.z/" + path = strstr(path, version) + strlen(version); + + // Annotate all-normalized method names + const char *method = RSTRING_PTR(iseq->body->location.label); + if (!strcmp(method, "[]")) method = "AREF"; + if (!strcmp(method, "[]=")) method = "ASET"; + + // Print and normalize + sprintf(funcname, "_mjit%d_%s_%s", unit->id, path, method); + for (size_t i = 0; i < strlen(funcname); i++) { + char c = funcname[i]; + if (!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_')) { + funcname[i] = '_'; + } + } +} + #define append_str2(p, str, len) ((char *)memcpy((p), str, (len))+(len)) #define append_str(p, str) append_str2(p, str, sizeof(str)-1) #define append_lit(p, str) append_str2(p, str, rb_strlen_lit(str)) @@ -912,8 +947,8 @@ compact_all_jit_code(void) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L947 CRITICAL_SECTION_START(3, "in compact_all_jit_code to read list"); list_for_each(&active_units.head, cur, unode) { void *func; - char funcname[35]; // TODO: reconsider `35` - sprintf(funcname, "_mjit%d", cur->id); + char funcname[MAXPATHLEN]; + sprint_funcname(funcname, unit); if ((func = dlsym(handle, funcname)) == NULL) { mjit_warning("skipping to reload '%s' from '%s': %s", funcname, so_file, dlerror()); @@ -1001,7 +1036,7 @@ compile_prelude(FILE *f) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1036 static mjit_func_t convert_unit_to_func(struct rb_mjit_unit *unit) { - char c_file_buff[MAXPATHLEN], *c_file = c_file_buff, *so_file, funcname[35]; // TODO: reconsider `35` + char c_file_buff[MAXPATHLEN], *c_file = c_file_buff, *so_file, funcname[MAXPATHLEN]; int fd; FILE *f; void *func; @@ -1036,7 +1071,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1071 memcpy(so_file, c_file, c_file_len - sizeof(c_ext)); memcpy(&so_file[c_file_len - sizeof(c_ext)], so_ext, sizeof(so_ext)); - sprintf(funcname, "_mjit%d", unit->id); + sprint_funcname(funcname, unit); fd = rb_cloexec_open(c_file, access_mode, 0600); if (fd < 0 || (f = fdopen(fd, "w")) == NULL) { -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/