Author: fijal
Branch: windows-vmprof-support
Changeset: r82124:ccfe8a95ee02
Date: 2016-02-09 14:24 +0100
http://bitbucket.org/pypy/pypy/changeset/ccfe8a95ee02/

Log:    start fighting windows

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
@@ -30,11 +30,11 @@
 
 
 def setup():
+    compile_extra = ['-DRPYTHON_LL2CTYPES']
     platform.verify_eci(ExternalCompilationInfo(
-        compile_extra=['-DRPYTHON_LL2CTYPES'],
+        compile_extra=compile_extra,
         **eci_kwds))
 
-
     eci = global_eci
     vmprof_init = rffi.llexternal("vmprof_init",
                                   [rffi.INT, rffi.DOUBLE, rffi.CCHARP],
@@ -89,9 +89,11 @@
     s.c_next = vmprof_tl_stack.get_or_make_raw()
     s.c_value = unique_id
     s.c_kind = VMPROF_CODE_TAG
+    print s
     vmprof_tl_stack.setraw(s)
     return s
 
 def leave_code(s):
     vmprof_tl_stack.setraw(s.c_next)
+    print "pop"
     lltype.free(s, flavor='raw')
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
@@ -1,23 +1,21 @@
 #define _GNU_SOURCE 1
 
-
 #ifdef RPYTHON_LL2CTYPES
    /* only for testing: ll2ctypes sets RPY_EXTERN from the command-line */
-#  ifndef RPY_EXTERN
-#    define RPY_EXTERN RPY_EXPORTED
-#  endif
-#  define RPY_EXPORTED  extern __attribute__((visibility("default")))
-#  define VMPROF_ADDR_OF_TRAMPOLINE(addr)  0
+#ifndef RPY_EXTERN
+#define RPY_EXTERN RPY_EXPORTED
+#endif
+#ifdef _WIN32
+#define RPY_EXPORTED __declspec(dllexport)
+#else
+#define RPY_EXPORTED  extern __attribute__((visibility("default")))
+#endif
 
 #else
-
 #  include "common_header.h"
 #  include "structdef.h"
 #  include "src/threadlocal.h"
 #  include "rvmprof.h"
-/*#  ifndef VMPROF_ADDR_OF_TRAMPOLINE
-#   error "RPython program using rvmprof, but not calling 
vmprof_execute_code()"
-#  endif*/
 
 #endif
 
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,9 +7,6 @@
 static long profile_interval_usec = 0;
 static int opened_profile(char *interp_name);
 
-#define MAX_STACK_DEPTH   \
-    ((SINGLE_BUF_SIZE - sizeof(struct prof_stacktrace_s)) / sizeof(void *))
-
 #define MARKER_STACKTRACE '\x01'
 #define MARKER_VIRTUAL_IP '\x02'
 #define MARKER_TRAILER '\x03'
@@ -20,6 +17,9 @@
 #define VERSION_THREAD_ID '\x01'
 #define VERSION_TAG '\x02'
 
+#define MAX_STACK_DEPTH   \
+    ((SINGLE_BUF_SIZE - sizeof(struct prof_stacktrace_s)) / sizeof(void *))
+
 typedef struct prof_stacktrace_s {
     char padding[sizeof(long) - 1];
     char marker;
diff --git a/rpython/rlib/rvmprof/src/vmprof_main_win32.h 
b/rpython/rlib/rvmprof/src/vmprof_main_win32.h
--- a/rpython/rlib/rvmprof/src/vmprof_main_win32.h
+++ b/rpython/rlib/rvmprof/src/vmprof_main_win32.h
@@ -10,6 +10,20 @@
     return 0;
 }
 
+#if defined(_MSC_VER)
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include "vmprof_stack.h"
 #include "vmprof_common.h"
 #include <tlhelp32.h>
@@ -17,6 +31,8 @@
 // This file has been inspired (but not copied from since the LICENSE
 // would not allow it) from verysleepy profiler
 
+#define SINGLE_BUF_SIZE 8192
+
 volatile int thread_started = 0;
 volatile int enabled = 0;
 
@@ -55,9 +71,42 @@
     return 0;
 }
 
-int vmprof_snapshot_thread(DWORD thread_id, PyThreadState *tstate, 
prof_stacktrace_s *stack)
+int vmprof_snapshot_thread(prof_stacktrace_s *stack)
 {
-    HRESULT result;
+  void *addr;
+  vmprof_stack_t *cur;
+  long tid;
+  HANDLE hThread;
+
+#ifdef RPYTHON_LL2CTYPES
+  return 0; // not much we can do
+#else
+  OP_THREADLOCALREF_ADDR(addr);
+#ifdef RPY_TLOFS_thread_ident // compiled with threads
+  tid = *(long*)((char*)addr + RPY_TLOFS_thread_ident);
+  hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, tid);
+  if (!hThread) {
+    return -1;
+  }
+  result = SuspendThread(hThread);
+  if(result == 0xffffffff)
+    return -1; // possible, e.g. attached debugger or thread alread suspended
+  if (*(long*)((char*)addr + RPY_TLOFS_thread_ident) != tid) {
+    // swapped threads, bail
+    ResumeThread(hThread);
+    return -1;
+  }
+#endif
+  cur = *(vmprof_stack_t**)((char*)addr + RPY_TLOFS_vmprof_tl_stack);
+  if (cur) {
+    printf("%p\n", cur->kind);
+  } else {
+    printf("null\n");
+  }
+#ifdef RPY_TLOFS_thread_ident
+  ResumeThread(hThread);
+#endif
+  /*    HRESULT result;
     HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, thread_id);
     int depth;
     if (!hThread) {
@@ -74,7 +123,9 @@
     stack->count = 1;
     stack->marker = MARKER_STACKTRACE;
     ResumeThread(hThread);
-    return depth;
+    return depth;*/
+    return 0;
+#endif
 }
 
 long __stdcall vmprof_mainloop(void *arg)
@@ -82,23 +133,19 @@
     prof_stacktrace_s *stack = (prof_stacktrace_s*)malloc(SINGLE_BUF_SIZE);
     HANDLE hThreadSnap = INVALID_HANDLE_VALUE; 
     int depth;
-    PyThreadState *tstate;
 
     while (1) {
-        Sleep(profile_interval_usec * 1000);
+      //Sleep(profile_interval_usec * 1000);
+      Sleep(10);
         if (!enabled) {
             continue;
         }
-        tstate = PyInterpreterState_Head()->tstate_head;
-        while (tstate) {
-            depth = vmprof_snapshot_thread(tstate->thread_id, tstate, stack);
-            if (depth > 0) {
-                _write_all((char*)stack + offsetof(prof_stacktrace_s, marker),
-                    depth * sizeof(void *) +
-                        sizeof(struct prof_stacktrace_s) -
-                        offsetof(struct prof_stacktrace_s, marker));
-            }
-            tstate = tstate->next;
+        depth = vmprof_snapshot_thread(stack);
+        if (depth > 0) {
+          _write_all((char*)stack + offsetof(prof_stacktrace_s, marker),
+                     depth * sizeof(void *) +
+                     sizeof(struct prof_stacktrace_s) -
+                     offsetof(struct prof_stacktrace_s, marker));
         }
     }
 }
diff --git a/rpython/rlib/rvmprof/src/vmprof_stack.h 
b/rpython/rlib/rvmprof/src/vmprof_stack.h
--- a/rpython/rlib/rvmprof/src/vmprof_stack.h
+++ b/rpython/rlib/rvmprof/src/vmprof_stack.h
@@ -1,7 +1,11 @@
 #ifndef _VMPROF_STACK_H_
 #define _VMPROF_STACK_H_
 
+#ifdef _WIN32
+#define intptr_t long // XXX windows VC++ 2008 lacks stdint.h
+#else
 #include <unistd.h>
+#endif
 
 #define VMPROF_CODE_TAG 1        /* <- also in cintf.py */
 #define VMPROF_BLACKHOLE_TAG 2
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to