Skip to content

Commit 0f4bd60

Browse files
committed
add faq entry, fix windows parsing
1 parent 7bc1627 commit 0f4bd60

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

docs/faq.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ Frequently Asked Questions
99

1010
* **What do the colors on vmprof.com mean?**: For plain CPython there is no particular meaning, we might change
1111
that in the future. For PyPy we have a color coding to show at which state the VM sampled (e.g. JIT, Warmup, ...).
12+
13+
* **My Windows profile is malformed?**: Please ensure that you open the file in binary mode. Otherwise Windows
14+
will transform `\n` to `\r\n`.

src/vmprof_common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ static struct profbuf_s *volatile current_codes;
4848
* is 4, but fails on win32
4949
*/
5050
typedef struct prof_stacktrace_s {
51+
#ifdef VMPROF_WINDOWS
52+
// if padding is 8 bytes, then on both 32bit and 64bit, the
53+
// stack field is aligned
54+
char padding[sizeof(void*) - 1];
55+
#else
5156
char padding[sizeof(long) - 1];
57+
#endif
5258
char marker;
5359
long count, depth;
5460
void *stack[];

src/vmprof_main_win32.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ long __stdcall vmprof_mainloop(void *arg)
8686
continue;
8787
depth = vmprof_snapshot_thread(tstate->thread_id, tstate, stack);
8888
if (depth > 0) {
89-
// see note in vmprof_common.h on the prof_stacktrace_s struct why
90-
// there are two vmpr_write_all calls
91-
vmp_write_all((char*)stack + offsetof(prof_stacktrace_s, marker), SIZEOF_PROF_STACKTRACE);
92-
vmp_write_all((char*)stack->stack, depth * sizeof(void*));
89+
vmp_write_all((char*)stack + offsetof(prof_stacktrace_s, marker),
90+
SIZEOF_PROF_STACKTRACE + depth * sizeof(void*));
9391
}
9492
}
9593
}
@@ -121,4 +119,5 @@ int vmprof_disable(void)
121119
RPY_EXTERN
122120
void vmprof_ignore_signals(int ignored)
123121
{
122+
enabled = !ignored;
124123
}

vmprof/test/cpuburn.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import os
23
from time import time
34
import vmprof
@@ -48,7 +49,10 @@ def test():
4849

4950
PROFILE_FILE = 'vmprof_cpuburn.dat'
5051

51-
outfd = os.open(PROFILE_FILE, os.O_RDWR | os.O_CREAT | os.O_TRUNC)
52+
flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC
53+
if sys.platform == 'win32':
54+
flags |= os.O_BINARY
55+
outfd = os.open(PROFILE_FILE, flags)
5256
vmprof.enable(outfd, period=0.01)
5357
test()
5458
vmprof.disable()

0 commit comments

Comments
 (0)