Author: Richard Plangger <planri...@gmail.com> Branch: new-jit-log Changeset: r82567:2e7a4736bf22 Date: 2016-02-26 16:20 +0100 http://bitbucket.org/pypy/pypy/changeset/2e7a4736bf22/
Log: added jitlog as a replacement of the current PYPYLOG, does not run yet diff --git a/rpython/jit/metainterp/jitlog.py b/rpython/jit/metainterp/jitlog.py new file mode 100644 --- /dev/null +++ b/rpython/jit/metainterp/jitlog.py @@ -0,0 +1,22 @@ +from rpython.rlib.rvmprof.rvmprof import cintf + +class VMProfJitLogger(object): + def __init__(self): + self.cintf = cintf.setup() + + def _ensure_init(self): + self.cintf.jitlog_try_init_using_env() + + self.cintf.write_marker(BinaryJitLogger.JIT_META_MARKER) + count = len(resoperation.opname) + assert count < 256 + self.cintf.write_marker(count) + for opnum, opname in resoperation.opname.items(): + self.cintf.write_byte(opnum) + self.cintf.write_string(opnum) + + def log_loop(self, operations): + pass + + def _log_resoperation(self, op): + pass diff --git a/rpython/jit/metainterp/optimizeopt/__init__.py b/rpython/jit/metainterp/optimizeopt/__init__.py --- a/rpython/jit/metainterp/optimizeopt/__init__.py +++ b/rpython/jit/metainterp/optimizeopt/__init__.py @@ -54,6 +54,7 @@ debug_start("jit-optimize") inputargs = compile_data.start_label.getarglist() try: + metainterp.jitlog.log_loop(inputargs, compile_data.operations, memo) metainterp_sd.logger_noopt.log_loop(inputargs, compile_data.operations, memo=memo) diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py --- a/rpython/jit/metainterp/pyjitpl.py +++ b/rpython/jit/metainterp/pyjitpl.py @@ -13,6 +13,7 @@ from rpython.jit.metainterp.logger import Logger from rpython.jit.metainterp.optimizeopt.util import args_dict from rpython.jit.metainterp.resoperation import rop, OpHelpers, GuardResOp +from rpython.jit.metainterp import jitlog from rpython.rlib import nonconst, rstack from rpython.rlib.debug import debug_start, debug_stop, debug_print from rpython.rlib.debug import have_debug_prints, make_sure_not_resized @@ -1717,12 +1718,14 @@ class MetaInterpStaticData(object): logger_noopt = None logger_ops = None + jitlog = None def __init__(self, cpu, options, ProfilerClass=EmptyProfiler, warmrunnerdesc=None): self.cpu = cpu self.stats = self.cpu.stats self.options = options + self.jitlog = jitlog.VMProfJitLogger() self.logger_noopt = Logger(self) self.logger_ops = Logger(self, guard_number=True) diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py --- a/rpython/rlib/rvmprof/cintf.py +++ b/rpython/rlib/rvmprof/cintf.py @@ -51,6 +51,11 @@ [rffi.INT], lltype.Void, compilation_info=eci, _nowrapper=True) + + jitlog_init = rffi.llexternal("jitlog_init", [rffi.INT, rffi.CHARP], + rffi.CHARP, compilation_info=eci, + save_err=rffi.RFFI_SAVE_ERRNO) + return CInterface(locals()) diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py --- a/rpython/rlib/rvmprof/rvmprof.py +++ b/rpython/rlib/rvmprof/rvmprof.py @@ -109,12 +109,20 @@ if p_error: raise VMProfError(rffi.charp2str(p_error)) + self.enable_jitlog(fileno, "") + self._gather_all_code_objs() res = self.cintf.vmprof_enable() if res < 0: raise VMProfError(os.strerror(rposix.get_saved_errno())) self.is_enabled = True + def enable_jitlog(self, fileno, regexp): + # initialize the jit log + p_error = self.cintf.jitlog_init(fileno, regexp) + if p_error: + raise VMProfError(rffi.charp2str(p_error)) + def disable(self): """Disable vmprof. Raises VMProfError if something goes wrong. diff --git a/rpython/rlib/rvmprof/src/jitlog_main.h b/rpython/rlib/rvmprof/src/jitlog_main.h new file mode 100644 --- /dev/null +++ b/rpython/rlib/rvmprof/src/jitlog_main.h @@ -0,0 +1,96 @@ +#include <string.h> + +static int jitlog_fd = -1; +static char * jitlog_prefix = NULL; +static int jitlog_ready = 0; + +RPY_EXTERN +void jitlog_try_init_using_env(void) { + if (jitlog_ready) { return; } + + char *filename = getenv("JITLOG"); + + if (filename && filename[0]) { + char *newfilename = NULL, *escape; + char *colon = strchr(filename, ':'); + if (filename[0] == '+') { + filename += 1; + colon = NULL; + } + if (!colon) { + /* JITLOG=+filename (or just 'filename') --- profiling version */ + debug_profile = 1; + pypy_setup_profiling(); + } else { + /* JITLOG=prefix:filename --- conditional logging */ + int n = colon - filename; + debug_prefix = malloc(n + 1); + memcpy(debug_prefix, filename, n); + debug_prefix[n] = '\0'; + filename = colon + 1; + } + escape = strstr(filename, "%d"); + if (escape) { + /* a "%d" in the filename is replaced with the pid */ + newfilename = malloc(strlen(filename) + 32); + if (newfilename != NULL) { + char *p = newfilename; + memcpy(p, filename, escape - filename); + p += escape - filename; + sprintf(p, "%ld", (long)getpid()); + strcat(p, escape + 2); + filename = newfilename; + } + } + if (strcmp(filename, "-") != 0) { + // mode is 775 + mode_t mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH; + jitlog_fd = open(filename, O_WRONLY | O_CREATE, mode); + } + + if (escape) { + free(newfilename); /* if not null */ + /* the env var is kept and passed to subprocesses */ + } else { +#ifndef _WIN32 + unsetenv("JITLOG"); +#else + putenv("JITLOG="); +#endif + } + } + if (!jitlog_fd) { + jitlog_fd = stderr; + // TODO + //if (isatty(2)) + // { + // debug_start_colors_1 = "\033[1m\033[31m"; + // debug_start_colors_2 = "\033[31m"; + // debug_stop_colors = "\033[0m"; + // } + } + + jitlog_ready = 1; +} + +RPY_EXTERN +char *jitlog_init(int fd, char * prefix) +{ + jitlog_fd = fd; + jitlog_prefix = strdup(prefix); + return NULL; +} + +RPY_EXTERN +void jitlog_close(int close_fd) +{ + if (jitlog_fd == -1) { + return; + } + if (close_fd) { + close(jitlog_fd); + } + jitlog_fd = -1; + free(jitlog_prefix); +} + diff --git a/rpython/rlib/rvmprof/src/rvmprof.c b/rpython/rlib/rvmprof/src/rvmprof.c --- a/rpython/rlib/rvmprof/src/rvmprof.c +++ b/rpython/rlib/rvmprof/src/rvmprof.c @@ -16,12 +16,12 @@ # include "structdef.h" # include "src/threadlocal.h" # include "rvmprof.h" - #endif #if defined(__unix__) || defined(__APPLE__) #include "vmprof_main.h" +#include "jitlog_main.h" #else #include "vmprof_main_win32.h" #endif diff --git a/rpython/rlib/rvmprof/src/rvmprof.h b/rpython/rlib/rvmprof/src/rvmprof.h --- a/rpython/rlib/rvmprof/src/rvmprof.h +++ b/rpython/rlib/rvmprof/src/rvmprof.h @@ -8,3 +8,6 @@ RPY_EXTERN int vmprof_stack_append(void*, long); RPY_EXTERN long vmprof_stack_pop(void*); RPY_EXTERN void vmprof_stack_free(void*); + +RPY_EXTERN char * jitlog_init(int, char*); +RPY_EXTERN void jitlog_try_init_using_env(void); diff --git a/rpython/rlib/rvmprof/src/vmprof_common.h b/rpython/rlib/rvmprof/src/vmprof_common.h --- a/rpython/rlib/rvmprof/src/vmprof_common.h +++ b/rpython/rlib/rvmprof/src/vmprof_common.h @@ -7,11 +7,7 @@ static long profile_interval_usec = 0; static int opened_profile(char *interp_name); -#define MARKER_STACKTRACE '\x01' -#define MARKER_VIRTUAL_IP '\x02' -#define MARKER_TRAILER '\x03' -#define MARKER_INTERP_NAME '\x04' /* deprecated */ -#define MARKER_HEADER '\x05' +#include "vmprof_markers.h" #define VERSION_BASE '\x00' #define VERSION_THREAD_ID '\x01' diff --git a/rpython/rlib/rvmprof/src/vmprof_markers.h b/rpython/rlib/rvmprof/src/vmprof_markers.h new file mode 100644 --- /dev/null +++ b/rpython/rlib/rvmprof/src/vmprof_markers.h @@ -0,0 +1,10 @@ +#pragma once + +#define MARKER_STACKTRACE '\x01' +#define MARKER_VIRTUAL_IP '\x02' +#define MARKER_TRAILER '\x03' +#define MARKER_INTERP_NAME '\x04' /* deprecated */ +#define MARKER_HEADER '\x05' + +#define MARKER_JITLOG_META '\x06' + _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit