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 Reverting deb1c7b97d, fixing `sprint_funcname`'s argument in `compact_all_jit_code`. Also updating common.mk.
This commit is contained in:
parent
deb1c7b97d
commit
6e405b2611
@ -2905,6 +2905,7 @@ mjit.$(OBJEXT): $(CCAN_DIR)/list/list.h
|
|||||||
mjit.$(OBJEXT): $(CCAN_DIR)/str/str.h
|
mjit.$(OBJEXT): $(CCAN_DIR)/str/str.h
|
||||||
mjit.$(OBJEXT): $(hdrdir)/ruby.h
|
mjit.$(OBJEXT): $(hdrdir)/ruby.h
|
||||||
mjit.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
mjit.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
||||||
|
mjit.$(OBJEXT): $(hdrdir)/ruby/version.h
|
||||||
mjit.$(OBJEXT): $(top_srcdir)/internal/array.h
|
mjit.$(OBJEXT): $(top_srcdir)/internal/array.h
|
||||||
mjit.$(OBJEXT): $(top_srcdir)/internal/class.h
|
mjit.$(OBJEXT): $(top_srcdir)/internal/class.h
|
||||||
mjit.$(OBJEXT): $(top_srcdir)/internal/compilers.h
|
mjit.$(OBJEXT): $(top_srcdir)/internal/compilers.h
|
||||||
|
@ -92,6 +92,7 @@
|
|||||||
#include "ruby_assert.h"
|
#include "ruby_assert.h"
|
||||||
#include "ruby/debug.h"
|
#include "ruby/debug.h"
|
||||||
#include "ruby/thread.h"
|
#include "ruby/thread.h"
|
||||||
|
#include "ruby/version.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
@ -688,6 +689,40 @@ remove_so_file(const char *so_file, struct rb_mjit_unit *unit)
|
|||||||
#endif
|
#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_str2(p, str, len) ((char *)memcpy((p), str, (len))+(len))
|
||||||
#define append_str(p, str) append_str2(p, str, sizeof(str)-1)
|
#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))
|
#define append_lit(p, str) append_str2(p, str, rb_strlen_lit(str))
|
||||||
@ -912,8 +947,8 @@ compact_all_jit_code(void)
|
|||||||
CRITICAL_SECTION_START(3, "in compact_all_jit_code to read list");
|
CRITICAL_SECTION_START(3, "in compact_all_jit_code to read list");
|
||||||
list_for_each(&active_units.head, cur, unode) {
|
list_for_each(&active_units.head, cur, unode) {
|
||||||
void *func;
|
void *func;
|
||||||
char funcname[35]; // TODO: reconsider `35`
|
char funcname[MAXPATHLEN];
|
||||||
sprintf(funcname, "_mjit%d", cur->id);
|
sprint_funcname(funcname, cur);
|
||||||
|
|
||||||
if ((func = dlsym(handle, funcname)) == NULL) {
|
if ((func = dlsym(handle, funcname)) == NULL) {
|
||||||
mjit_warning("skipping to reload '%s' from '%s': %s", funcname, so_file, dlerror());
|
mjit_warning("skipping to reload '%s' from '%s': %s", funcname, so_file, dlerror());
|
||||||
@ -1001,7 +1036,7 @@ compile_prelude(FILE *f)
|
|||||||
static mjit_func_t
|
static mjit_func_t
|
||||||
convert_unit_to_func(struct rb_mjit_unit *unit)
|
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;
|
int fd;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
void *func;
|
void *func;
|
||||||
@ -1036,7 +1071,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
|
|||||||
memcpy(so_file, c_file, c_file_len - sizeof(c_ext));
|
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));
|
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);
|
fd = rb_cloexec_open(c_file, access_mode, 0600);
|
||||||
if (fd < 0 || (f = fdopen(fd, "w")) == NULL) {
|
if (fd < 0 || (f = fdopen(fd, "w")) == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user