Author: Richard Plangger <planri...@gmail.com>
Branch: new-jit-log
Changeset: r83107:3c69b7ad777e
Date: 2016-03-17 12:41 +0100
http://bitbucket.org/pypy/pypy/changeset/3c69b7ad777e/

Log:    revived this branch, writes all resoperations into the log (to be
        independant from the pypy code base)

diff --git a/rpython/jit/metainterp/jitlog.py b/rpython/jit/metainterp/jitlog.py
--- a/rpython/jit/metainterp/jitlog.py
+++ b/rpython/jit/metainterp/jitlog.py
@@ -1,13 +1,17 @@
 from rpython.rlib.rvmprof.rvmprof import cintf
+from rpython.jit.metainterp import resoperation as resoperations
+import struct
 
 class VMProfJitLogger(object):
 
-    MARK_BLOCK_ASM = 0x10
+    MARK_TRACED = 0x10
+    MARK_ASM = 0x11
 
-    MARK_INPUT_ARGS = 0x11
-    MARK_RESOP = 0x12
+    MARK_INPUT_ARGS = 0x12
+    MARK_RESOP = 0x13
 
-    MARK_RESOP_META = 0x13
+    MARK_RESOP_META = 0x14
+    MARK_RESOP = 0x15
 
     def __init__(self):
         self.cintf = cintf.setup()
@@ -16,31 +20,31 @@
         self.cintf.jitlog_try_init_using_env()
         if self.cintf.jitlog_filter(0x0):
             return
-        self.cintf.jitlog_write_marker(MARK_RESOP_META);
-        count = len(resoperation.opname)
-        self.cintf.jitlog_write_int(count)
-        for opnum, opname in resoperation.opname.items():
-            self.cintf.write_marker(opnum)
-            self.cintf.write_string(opname)
+        count = len(resoperations.opname)
+        mark = VMProfJitLogger.MARK_RESOP_META
+        for opnum, opname in resoperations.opname.items():
+            line = struct.pack(">h", opnum) + opname.lower()
+            self.write_marked(mark, line)
+
+    def teardown(self):
+        self.cintf.jitlog_teardown()
+
+    def write_marked(self, mark, line):
+        self.cintf.jitlog_write_marked(mark, line, len(line))
 
     def log_trace(self, tag, args, ops,
                   faildescr=None, ops_offset={}):
         if self.cintf.jitlog_filter(tag):
             return
         assert isinstance(tag, int)
-        self.cintf.jitlog_write_marker(tag);
 
         # input args
-        self.cintf.jitlog_write_marker(MARK_INPUT_ARGS);
         str_args = [arg.repr_short(arg._repr_memo) for arg in args]
-        self.cintf.jitlog_write_string(','.join(str_args))
+        self.write_marked(self.MARK_INPUT_ARGS, ','.join(str_args))
 
-        self.cintf.jitlog_write_int(len(ops))
         for i,op in enumerate(ops):
-            self.cintf.jitlog_write_marker(MARK_RESOP)
-            self.cintf.jitlog_write_marker(op.getopnum())
             str_args = [arg.repr_short(arg._repr_memo) for arg in 
op.getarglist()]
             descr = op.getdescr()
             if descr:
                 str_args += ['descr='+descr]
-            self.cintf.jitlog_write_string(','.join(str_args))
+            self.write_marked(self.MARK_RESOP, ','.join(args))
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
@@ -56,12 +56,18 @@
                                             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)
-    jitlog_init = rffi.llexternal("jitlog_write_marker", [rffi.INT, 
rffi.CHARP],
-                                  rffi.CHARP, compilation_info=eci,
-                                  save_err=rffi.RFFI_SAVE_ERRNO)
+    # jit log functions
+    jitlog_init = rffi.llexternal("jitlog_init", [rffi.INT, rffi.CCHARP],
+                                  rffi.CCHARP, compilation_info=eci)
+    jitlog_try_init_using_env = rffi.llexternal("jitlog_try_init_using_env",
+                                  [], lltype.Void, compilation_info=eci)
+    jitlog_write_marked = rffi.llexternal("jitlog_write_marked",
+                                  [rffi.INT, rffi.CCHARP, rffi.INT],
+                                  lltype.Void, compilation_info=eci)
+    jitlog_filter = rffi.llexternal("jitlog_filter", [rffi.INT], rffi.INT,
+                                    compilation_info=eci)
+    jitlog_teardown = rffi.llexternal("jitlog_teardown", [], lltype.Void,
+                                      compilation_info=eci)
 
     return CInterface(locals())
 
diff --git a/rpython/rlib/rvmprof/src/jitlog_main.h 
b/rpython/rlib/rvmprof/src/jitlog_main.h
--- a/rpython/rlib/rvmprof/src/jitlog_main.h
+++ b/rpython/rlib/rvmprof/src/jitlog_main.h
@@ -29,14 +29,13 @@
         }
         if (!colon) {
             /* JITLOG=+filename (or just 'filename') --- profiling version */
-            debug_profile = 1;
-            pypy_setup_profiling();
+            //pypy_setup_profiling();
         } else {
             /* JITLOG=prefix:filename --- conditional logging */
             int n = colon - filename;
             jitlog_prefix = malloc(n + 1);
             memcpy(jitlog_prefix, filename, n);
-            debug_prefix[n] = '\0';
+            //debug_prefix[n] = '\0';
             filename = colon + 1;
         }
         escape = strstr(filename, "%d");
@@ -55,7 +54,7 @@
         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);
+            jitlog_fd = open(filename, O_WRONLY | O_CREAT, mode);
         }
 
         if (escape) {
@@ -70,7 +69,7 @@
       }
     }
     if (!jitlog_fd) {
-        jitlog_fd = stderr;
+        jitlog_fd = 2;
         // TODO
         //if (isatty(2))
         //  {
@@ -84,7 +83,7 @@
 }
 
 RPY_EXTERN
-char *jitlog_init(int fd, char * prefix)
+char *jitlog_init(int fd, const char * prefix)
 {
     jitlog_fd = fd;
     jitlog_prefix = strdup(prefix);
@@ -92,15 +91,32 @@
 }
 
 RPY_EXTERN
-void jitlog_close(int close_fd)
+void jitlog_teardown()
 {
+    jitlog_ready = 0;
     if (jitlog_fd == -1) {
         return;
     }
-    if (close_fd) {
-        close(jitlog_fd);
+    // close the jitlog file descriptor
+    close(jitlog_fd);
+    jitlog_fd = -1;
+    // free the prefix
+    if (jitlog_prefix != NULL) {
+        free(jitlog_prefix);
     }
-    jitlog_fd = -1;
-    free(jitlog_prefix);
 }
 
+RPY_EXTERN
+void jitlog_write_marked(int tag, char * text, int length)
+{
+    if (!jitlog_ready) { return; }
+
+    char header[5];
+    header[0] = tag;
+    header[1] = (length >> 24) & 0xff;
+    header[2] = (length >> 16) & 0xff;
+    header[3] = (length >> 8) & 0xff;
+    header[4] = length & 0xff;
+    write(jitlog_fd, (const char*)&header, 5);
+    write(jitlog_fd, text, length);
+}
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
@@ -9,6 +9,8 @@
 RPY_EXTERN long vmprof_stack_pop(void*);
 RPY_EXTERN void vmprof_stack_free(void*);
 
-RPY_EXTERN char * jitlog_init(int, char*);
+RPY_EXTERN char * jitlog_init(int, const char*);
 RPY_EXTERN void jitlog_try_init_using_env(void);
-RPY_EXTERN int jitlog_filter(int tag);
+RPY_EXTERN int jitlog_filter(int);
+RPY_EXTERN void jitlog_write_marked(int, char*, int);
+RPY_EXTERN void jitlog_teardown();
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to