Author: fijal
Branch: 
Changeset: r80155:a2c908e95b29
Date: 2015-10-13 11:03 +0200
http://bitbucket.org/pypy/pypy/changeset/a2c908e95b29/

Log:    try to redo mac fixes

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
@@ -92,12 +92,13 @@
         PLT = ""
         size_decl = ""
         type_decl = ""
+        extra_align = ""
     else:
         PLT = "@PLT"
         type_decl = "\t.type\t%s, @function" % (tramp_name,)
         size_decl = "\t.size\t%s, .-%s" % (
             tramp_name, tramp_name)
-
+        extra_align = "\t.cfi_def_cfa_offset 8"
 
     assert detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64), (
         "rvmprof only supports x86-64 CPUs for now")
@@ -132,7 +133,7 @@
 \t.cfi_def_cfa_offset 16
 \tcall %(cont_name)s%(PLT)s
 \taddq\t$8, %%rsp
-\t.cfi_def_cfa_offset 8
+%(extra_align)s
 \tret
 \t.cfi_endproc
 %(size_decl)s
diff --git a/rpython/rlib/rvmprof/src/vmprof_main.h 
b/rpython/rlib/rvmprof/src/vmprof_main.h
--- a/rpython/rlib/rvmprof/src/vmprof_main.h
+++ b/rpython/rlib/rvmprof/src/vmprof_main.h
@@ -31,7 +31,11 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include "vmprof_getpc.h"
+#ifdef __APPLE__
+#include "libunwind.h"
+#else
 #include "vmprof_unwind.h"
+#endif
 #include "vmprof_mt.h"
 
 
@@ -39,10 +43,12 @@
 
 // functions copied from libunwind using dlopen
 
+#ifndef __APPLE__ // should be linux only probably
 static int (*unw_get_reg)(unw_cursor_t*, int, unw_word_t*) = NULL;
 static int (*unw_step)(unw_cursor_t*) = NULL;
 static int (*unw_init_local)(unw_cursor_t *, unw_context_t *) = NULL;
 static int (*unw_get_proc_info)(unw_cursor_t *, unw_proc_info_t *) = NULL;
+#endif
 
 static int profile_file = -1;
 static long prepare_interval_usec;
@@ -67,6 +73,7 @@
         return "bad value for 'interval'";
     prepare_interval_usec = (int)(interval * 1000000.0);
 
+#ifndef __APPLE__
     if (!unw_get_reg) {
         void *libhandle;
 
@@ -81,6 +88,7 @@
         if (!(unw_step = dlsym(libhandle, UNW_PREFIX  "_step")))
             goto error;
     }
+#endif
     if (prepare_concurrent_bufs() < 0)
         return "out of memory";
 
@@ -206,7 +214,12 @@
     void *ip;
     int n = 0;
     unw_cursor_t cursor;
+#ifdef __APPLE__
+    unw_context_t uc;
+    unw_getcontext(&uc);
+#else
     unw_context_t uc = *ucontext;
+#endif
 
     int ret = unw_init_local(&cursor, &uc);
     assert(ret >= 0);
diff --git a/rpython/rlib/rvmprof/src/vmprof_unwind.h 
b/rpython/rlib/rvmprof/src/vmprof_unwind.h
--- a/rpython/rlib/rvmprof/src/vmprof_unwind.h
+++ b/rpython/rlib/rvmprof/src/vmprof_unwind.h
@@ -64,8 +64,7 @@
 typedef struct unw_cursor
   {
     unw_word_t opaque[UNW_TDEP_CURSOR_LEN];
-  }
-unw_cursor_t;
+  } unw_cursor_t;
 
 #define UNW_REG_IP UNW_X86_64_RIP
 #define UNW_REG_SP UNW_X86_64_RSP
@@ -84,7 +83,7 @@
     int format;                        /* unwind-info format (arch-specific) */
     int unwind_info_size;      /* size of the information (if applicable) */
     void *unwind_info;         /* unwind-info (arch-specific) */
-  }
-unw_proc_info_t;
+  } unw_proc_info_t;
 
 // end of copy
+
diff --git a/rpython/rlib/rvmprof/test/test_rvmprof.py 
b/rpython/rlib/rvmprof/test/test_rvmprof.py
--- a/rpython/rlib/rvmprof/test/test_rvmprof.py
+++ b/rpython/rlib/rvmprof/test/test_rvmprof.py
@@ -2,6 +2,7 @@
 from rpython.tool.udir import udir
 from rpython.rlib import rvmprof
 from rpython.translator.c.test.test_genc import compile
+from rpython.rlib.objectmodel import we_are_translated
 
 
 def test_vmprof_execute_code_1():
@@ -96,7 +97,12 @@
     @rvmprof.vmprof_execute_code("xcode1", lambda code, num: code)
     def main(code, num):
         print num
-        return 42
+        s = 0
+        for i in range(num):
+            s += (i << 1)
+            if s % 32423423423 == 0:
+                print s
+        return s
 
     tmpfilename = str(udir.join('test_rvmprof'))
 
@@ -104,16 +110,37 @@
         code = MyCode()
         rvmprof.register_code(code, get_name)
         fd = os.open(tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
-        rvmprof.enable(fd, 0.5)
-        res = main(code, 5)
-        assert res == 42
+        if we_are_translated():
+            num = 100000000
+            period = 0.0001
+        else:
+            num = 10000
+            period = 0.9
+        rvmprof.enable(fd, period)
+        res = main(code, num)
+        #assert res == 499999500000
         rvmprof.disable()
         os.close(fd)
         return 0
 
+    def check_profile(filename):
+        from vmprof import read_profile
+
+        prof = read_profile(filename)
+        assert prof.get_tree().name.startswith("py:")
+        assert prof.get_tree().count
+
     assert f() == 0
     assert os.path.exists(tmpfilename)
     fn = compile(f, [], gcpolicy="minimark")
-    os.unlink(tmpfilename)
     assert fn() == 0
-    assert os.path.exists(tmpfilename)
+    try:
+        import vmprof
+    except ImportError:
+        py.test.skip("vmprof unimportable")
+    else:
+        check_profile(tmpfilename)
+    finally:
+        assert os.path.exists(tmpfilename)
+        os.unlink(tmpfilename)
+       
\ No newline at end of file
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to