Skip to content

Commit 44231d9

Browse files
committed
copy over changes made to pypy
1 parent 1deccf5 commit 44231d9

File tree

8 files changed

+395
-65
lines changed

8 files changed

+395
-65
lines changed

src/_vmprof.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
#include <signal.h>
1010

1111
#include "_vmprof.h"
12-
#include "vmprof_common.h"
1312

13+
static volatile int is_enabled = 0;
1414
static destructor Original_code_dealloc = 0;
1515
static PyObject* (*_default_eval_loop)(PyFrameObject *, int) = 0;
1616

1717
#if VMPROF_UNIX
1818
#include "trampoline.h"
1919
#include "machine.h"
2020
#include "symboltable.h"
21-
#include "vmprof_unix.h"
21+
#include "vmprof_main.h"
2222
#else
23-
#include "vmprof_win.h"
23+
#include "vmprof_main_win32.h"
2424
#endif
2525
#include "vmp_stack.h"
2626

@@ -156,7 +156,7 @@ void emit_all_code_objects(PyObject * seen_code_ids)
156156

157157
static void cpyprof_code_dealloc(PyObject *co)
158158
{
159-
if (vmprof_is_enabled()) {
159+
if (is_enabled) {
160160
emit_code_object((PyCodeObject *)co);
161161
/* xxx error return values are ignored */
162162
}
@@ -187,7 +187,7 @@ static PyObject *enable_vmprof(PyObject* self, PyObject *args)
187187
return NULL;
188188
}
189189

190-
if (vmprof_is_enabled()) {
190+
if (is_enabled) {
191191
PyErr_SetString(PyExc_ValueError, "vmprof is already enabled");
192192
return NULL;
193193
}
@@ -217,13 +217,13 @@ static PyObject *enable_vmprof(PyObject* self, PyObject *args)
217217
return NULL;
218218
}
219219

220-
vmprof_set_enabled(1);
220+
is_enabled = 1;
221221

222222
Py_RETURN_NONE;
223223
}
224224

225225
static PyObject * vmp_is_enabled(PyObject *module, PyObject *noargs) {
226-
if (vmprof_is_enabled()) {
226+
if (is_enabled) {
227227
Py_RETURN_TRUE;
228228
}
229229
Py_RETURN_FALSE;
@@ -237,7 +237,7 @@ disable_vmprof(PyObject *module, PyObject *noargs)
237237
return NULL;
238238
}
239239

240-
vmprof_set_enabled(0);
240+
is_enabled = 0;
241241

242242
if (PyErr_Occurred())
243243
return NULL;
@@ -362,7 +362,7 @@ start_sampling(PyObject *module, PyObject *noargs)
362362
#ifdef VMPROF_UNIX
363363
static PyObject * vmp_get_profile_path(PyObject *module, PyObject *noargs) {
364364
PyObject * o;
365-
if (vmprof_is_enabled()) {
365+
if (is_enabled) {
366366
char buffer[4096];
367367
buffer[0] = 0;
368368
ssize_t buffer_len = vmp_fd_to_path(vmp_profile_fileno(), buffer, 4096);
@@ -382,19 +382,21 @@ static PyObject *
382382
insert_real_time_thread(PyObject *module, PyObject * noargs) {
383383
ssize_t thread_count;
384384

385-
if (!vmprof_is_enabled()) {
385+
if (!is_enabled) {
386386
PyErr_SetString(PyExc_ValueError, "vmprof is not enabled");
387387
return NULL;
388388
}
389389

390-
if (vmprof_get_signal_type() != SIGALRM) {
390+
if (signal_type != SIGALRM) {
391391
PyErr_SetString(PyExc_ValueError, "vmprof is not in real time mode");
392392
return NULL;
393393
}
394394

395-
vmprof_aquire_lock();
395+
while (__sync_lock_test_and_set(&spinlock, 1)) {
396+
}
397+
396398
thread_count = insert_thread(pthread_self(), -1);
397-
vmprof_release_lock();
399+
__sync_lock_release(&spinlock);
398400

399401
return PyLong_FromSsize_t(thread_count);
400402
}
@@ -403,19 +405,21 @@ static PyObject *
403405
remove_real_time_thread(PyObject *module, PyObject * noargs) {
404406
ssize_t thread_count;
405407

406-
if (!vmprof_is_enabled()) {
408+
if (!is_enabled) {
407409
PyErr_SetString(PyExc_ValueError, "vmprof is not enabled");
408410
return NULL;
409411
}
410412

411-
if (vmprof_get_signal_type() != SIGALRM) {
413+
if (signal_type != SIGALRM) {
412414
PyErr_SetString(PyExc_ValueError, "vmprof is not in real time mode");
413415
return NULL;
414416
}
415417

416-
vmprof_aquire_lock();
418+
while (__sync_lock_test_and_set(&spinlock, 1)) {
419+
}
420+
417421
thread_count = remove_thread(pthread_self(), -1);
418-
vmprof_release_lock();
422+
__sync_lock_release(&spinlock);
419423

420424
return PyLong_FromSsize_t(thread_count);
421425
}

src/machine.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const char * vmp_machine_os_name(void)
2727
#endif
2828
#elif __linux__
2929
return "linux";
30-
#elif __FreeBSD__
31-
return "freebsd"
3230
#else
3331
#error "Unknown compiler"
3432
#endif
@@ -40,7 +38,7 @@ long vmp_fd_to_path(int fd, char * buffer, long buffer_len)
4038
char proffs[24];
4139
(void)snprintf(proffs, 24, "/proc/self/fd/%d", fd);
4240
return readlink(proffs, buffer, buffer_len);
43-
#elif defined(VMPROF_UNIX) && !defined(__FreeBSD__)
41+
#elif defined(VMPROF_UNIX)
4442
fcntl(fd, F_GETPATH, buffer);
4543
return strlen(buffer);
4644
#endif

src/vmp_stack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static void * libhandle = NULL;
523523

524524
int vmp_native_enable(void) {
525525
#ifdef VMPROF_LINUX
526-
if (libhandle == NULL) {
526+
if (!unw_get_reg) {
527527
if ((libhandle = dlopen(LIBUNWIND, RTLD_LAZY | RTLD_LOCAL)) == NULL) {
528528
goto bail_out;
529529
}
@@ -570,7 +570,6 @@ void vmp_native_disable(void) {
570570
vmprof_error = dlerror();
571571
fprintf(stderr, "could not close libunwind at runtime. error: %s\n", vmprof_error);
572572
}
573-
libhandle = NULL;
574573
}
575574

576575
vmp_native_traces_enabled = 0;

src/vmprof.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
#pragma once
22

3-
#define _GNU_SOURCE 1
4-
5-
#ifndef RPYTHON_VMPROF
6-
#include <Python.h>
7-
#endif
8-
93
#ifdef VMPROF_UNIX
104
#include <unistd.h>
115
#endif
@@ -85,7 +79,3 @@ int IS_VMPROF_EVAL(void * ptr);
8579

8680
#endif
8781

88-
void set_current_codes(void * to);
89-
int opened_profile(const char *interp_name, int memory, int proflines, int native, int real_time);
90-
void flush_codes(void);
91-

0 commit comments

Comments
 (0)