Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r90351:6a66210c1f40
Date: 2017-02-25 15:35 +0100
http://bitbucket.org/pypy/pypy/changeset/6a66210c1f40/

Log:    Blind fix: workaround for WSL

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
@@ -197,15 +197,30 @@
     return 0;
 }
 
+static int itimer_which = ITIMER_PROF;
+
 static int install_sigprof_timer(void)
 {
     struct itimerval timer;
     timer.it_interval.tv_sec = 0;
     timer.it_interval.tv_usec = profile_interval_usec;
     timer.it_value = timer.it_interval;
-    if (setitimer(ITIMER_PROF, &timer, NULL) != 0)
-        return -1;
-    return 0;
+    if (setitimer(itimer_which, &timer, NULL) == 0)
+        return 0;   /* normal path */
+
+    if (errno == EINVAL) {
+        /* on WSL, only ITIMER_REAL is supported */
+        if (setitimer(ITIMER_REAL, &timer, NULL) == 0) {
+            fprintf(stderr, "warning: setitimer(): ITIMER_PROF not "
+                            "available, using ITIMER_REAL instead. "
+                            "Multithreaded programs and programs "
+                            "doing a lot of I/O won't give correct "
+                            "results.\n");
+            itimer_which = ITIMER_REAL;
+            return 0;
+        }
+    }
+    return -1;
 }
 
 static int remove_sigprof_timer(void) {
@@ -214,7 +229,7 @@
     timer.it_interval.tv_usec = 0;
     timer.it_value.tv_sec = 0;
     timer.it_value.tv_usec = 0;
-    if (setitimer(ITIMER_PROF, &timer, NULL) != 0)
+    if (setitimer(itimer_which, &timer, NULL) != 0)
         return -1;
     return 0;
 }
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to