Skip to content

Commit ef3c38a

Browse files
committed
changes for pypy implementation
1 parent 5c71df0 commit ef3c38a

File tree

7 files changed

+43
-40
lines changed

7 files changed

+43
-40
lines changed

src/_vmprof.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#define ROUTINE_IS_PYTHON(RIP) ((unsigned long long)RIP & 0x1) == 0
2727
#define ROUTINE_IS_C(RIP) ((unsigned long long)RIP & 0x1) == 1
2828

29-
typedef uint64_t ptr_t;
30-
3129
/* This returns the address of the code object
3230
as the identifier. The mapping from identifiers to string
3331
representations of the code object is done elsewhere, namely:

src/compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <Python.h>
3+
INCLUDE_MODULE_HEADER
44

55
#if PY_MAJOR_VERSION >= 3
66
#define PyStr_AS_STRING PyBytes_AS_STRING

src/stack.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <sys/types.h>
1010
#include <stddef.h>
1111

12-
#include "_vmprof.h"
12+
#include "vmprof.h"
1313
#include "compat.h"
1414

1515
#ifdef VMP_SUPPORTS_NATIVE_PROFILING
@@ -32,11 +32,11 @@
3232

3333
#ifdef PY_TEST
3434
// for testing only!
35-
PyObject* vmprof_eval(PyFrameObject *f, int throwflag) { return NULL; }
35+
PY_EVAL_RETURN_T * vmprof_eval(PY_STACK_FRAME_T *f, int throwflag) { return NULL; }
3636
#endif
3737

3838
static int vmp_native_traces_enabled = 0;
39-
static ptr_t *vmp_ranges = NULL;
39+
static intptr_t *vmp_ranges = NULL;
4040
static ssize_t vmp_range_count = 0;
4141
static int _vmp_profiles_lines = 0;
4242

@@ -93,7 +93,7 @@ static PyFrameObject * _write_python_stack_entry(PyFrameObject * frame, void **
9393
return frame->f_back;
9494
}
9595

96-
int vmp_walk_and_record_python_stack_only(PyFrameObject *frame, void ** result,
96+
int vmp_walk_and_record_python_stack_only(PY_STACK_FRAME_T *frame, void ** result,
9797
int max_depth, int depth)
9898
{
9999
while (depth < max_depth && frame) {
@@ -114,7 +114,7 @@ int _write_native_stack(void* addr, void ** result, int depth) {
114114
}
115115
#endif
116116

117-
int vmp_walk_and_record_stack(PyFrameObject *frame, void ** result,
117+
int vmp_walk_and_record_stack(PY_STACK_FRAME_T *frame, void ** result,
118118
int max_depth, int native_skip) {
119119
// called in signal handler
120120
#ifdef VMP_SUPPORTS_NATIVE_PROFILING
@@ -179,7 +179,7 @@ int vmp_walk_and_record_stack(PyFrameObject *frame, void ** result,
179179
}
180180
top_most_frame = _write_python_stack_entry(top_most_frame, result, &depth);
181181
}
182-
} else if (vmp_ignore_ip((ptr_t)func_addr)) {
182+
} else if (vmp_ignore_ip((intptr_t)func_addr)) {
183183
// this is an instruction pointer that should be ignored,
184184
// (that is any function name in the mapping range of
185185
// cpython, but of course not extenstions in site-packages))
@@ -239,22 +239,22 @@ int _reset_vmp_ranges(void) {
239239
int max_count = 10;
240240
vmp_range_count = 0;
241241
if (vmp_ranges != NULL) { free(vmp_ranges); }
242-
vmp_ranges = malloc(max_count * sizeof(ptr_t));
242+
vmp_ranges = malloc(max_count * sizeof(intptr_t));
243243
return max_count;
244244
}
245245

246246

247-
int _resize_ranges(ptr_t ** cursor, int max_count) {
247+
int _resize_ranges(intptr_t ** cursor, int max_count) {
248248
ptrdiff_t diff = (*cursor - vmp_ranges);
249249
if (diff + 2 > max_count) {
250250
max_count *= 2;
251-
vmp_ranges = realloc(vmp_ranges, max_count*sizeof(ptr_t));
251+
vmp_ranges = realloc(vmp_ranges, max_count*sizeof(intptr_t));
252252
*cursor = vmp_ranges + diff;
253253
}
254254
return max_count;
255255
}
256256

257-
ptr_t * _add_to_range(ptr_t * cursor, ptr_t start, ptr_t end) {
257+
intptr_t * _add_to_range(intptr_t * cursor, intptr_t start, intptr_t end) {
258258
if (cursor[0] == start) {
259259
// the last range is extended, this reduces the entry count
260260
// which makes the querying faster
@@ -286,7 +286,7 @@ int vmp_read_vmaps(const char * fname) {
286286
char *start_hex = NULL, *end_hex = NULL;
287287
size_t n = 0;
288288
ssize_t size;
289-
ptr_t start, end;
289+
intptr_t start, end;
290290

291291
// assumptions to be verified:
292292
// 1) /proc/self/maps is ordered ascending by start address
@@ -296,7 +296,7 @@ int vmp_read_vmaps(const char * fname) {
296296
// candidates
297297

298298
int max_count = _reset_vmp_ranges();
299-
ptr_t * cursor = vmp_ranges;
299+
intptr_t * cursor = vmp_ranges;
300300
cursor[0] = -1;
301301
while ((size = getline(&line, &n, fd)) >= 0) {
302302
assert(line != NULL);
@@ -347,7 +347,7 @@ int vmp_read_vmaps(const char * fname) {
347347

348348
addr = 0;
349349
int max_count = _reset_vmp_ranges();
350-
ptr_t * cursor = vmp_ranges;
350+
intptr_t * cursor = vmp_ranges;
351351
cursor[0] = -1;
352352

353353
do {
@@ -405,23 +405,23 @@ void vmp_native_disable(void) {
405405
vmp_range_count = 0;
406406
}
407407

408-
int vmp_ignore_ip(ptr_t ip) {
408+
int vmp_ignore_ip(intptr_t ip) {
409409
int i = vmp_binary_search_ranges(ip, vmp_ranges, vmp_range_count);
410410
if (i == -1) {
411411
return 0;
412412
}
413413

414414
assert((i & 1) == 0 && "returned index MUST be even");
415415

416-
ptr_t v = vmp_ranges[i];
417-
ptr_t v2 = vmp_ranges[i+1];
416+
intptr_t v = vmp_ranges[i];
417+
intptr_t v2 = vmp_ranges[i+1];
418418
return v <= ip && ip <= v2;
419419
}
420420

421-
int vmp_binary_search_ranges(ptr_t ip, ptr_t * l, int count) {
422-
ptr_t * r = l + count;
423-
ptr_t * ol = l;
424-
ptr_t * or = r-1;
421+
int vmp_binary_search_ranges(intptr_t ip, intptr_t * l, int count) {
422+
intptr_t * r = l + count;
423+
intptr_t * ol = l;
424+
intptr_t * or = r-1;
425425
while (1) {
426426
ptrdiff_t i = (r-l)/2;
427427
if (i == 0) {
@@ -440,7 +440,7 @@ int vmp_binary_search_ranges(ptr_t ip, ptr_t * l, int count) {
440440
return i;
441441
}
442442
}
443-
ptr_t * m = l + i;
443+
intptr_t * m = l + i;
444444
if (ip < *m) {
445445
r = m;
446446
} else {
@@ -454,11 +454,11 @@ int vmp_ignore_symbol_count(void) {
454454
return vmp_range_count;
455455
}
456456

457-
ptr_t * vmp_ignore_symbols(void) {
457+
intptr_t * vmp_ignore_symbols(void) {
458458
return vmp_ranges;
459459
}
460460

461-
void vmp_set_ignore_symbols(ptr_t * symbols, int count) {
461+
void vmp_set_ignore_symbols(intptr_t * symbols, int count) {
462462
vmp_ranges = symbols;
463463
vmp_range_count = count;
464464
}

src/stack.h

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

3-
#include "_vmprof.h"
3+
#include "vmprof.h"
44

5-
int vmp_walk_and_record_stack(PyFrameObject *frame, void **data,
5+
int vmp_walk_and_record_stack(PY_STACK_FRAME_T * frame, void **data,
66
int max_depth, int native_skip);
77

88
int vmp_native_enabled(void);
99
int vmp_native_enable(void);
10-
int vmp_ignore_ip(ptr_t ip);
11-
int vmp_binary_search_ranges(ptr_t ip, ptr_t * l, int count);
10+
int vmp_ignore_ip(intptr_t ip);
11+
int vmp_binary_search_ranges(intptr_t ip, intptr_t * l, int count);
1212
int vmp_native_symbols_read(void);
1313
void vmp_profile_lines(int lines);
1414
int vmp_profiles_python_lines(void);
1515

1616
int vmp_ignore_symbol_count(void);
17-
ptr_t * vmp_ignore_symbols(void);
18-
void vmp_set_ignore_symbols(ptr_t * symbols, int count);
17+
intptr_t * vmp_ignore_symbols(void);
18+
void vmp_set_ignore_symbols(intptr_t * symbols, int count);
1919
void vmp_native_disable(void);
2020

2121
#ifdef __unix__

src/vmprof_common.h

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

3-
#include <Python.h>
4-
#include <stddef.h>
5-
#include <time.h>
6-
7-
#include "_vmprof.h"
3+
#ifdef RPYTHON_VMPROF
4+
# include "rvmprof.h"
5+
#else
6+
# include "_vmprof.h"
7+
#endif
88
#include "machine.h"
99
#include "compat.h"
1010

11+
#include <stddef.h>
12+
#include <time.h>
13+
1114
#ifndef VMPROF_WINDOWS
1215
#include <sys/time.h>
1316
#include "vmprof_mt.h"

src/vmprof_main.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <sys/stat.h>
3434
#include <sys/time.h>
3535

36+
#include "vmprof.h"
37+
3638
#include "stack.h"
3739
#include "vmprof_getpc.h"
3840
#include "vmprof_mt.h"
@@ -87,6 +89,7 @@ static char atfork_hook_installed = 0;
8789
* *************************************************************
8890
*/
8991

92+
#ifndef RPYTHON_VMPROF
9093
static int get_stack_trace(PyThreadState * current, void** result, int max_depth)
9194
{
9295
PyFrameObject *frame;
@@ -104,8 +107,7 @@ static int get_stack_trace(PyThreadState * current, void** result, int max_depth
104107
return vmp_walk_and_record_stack(frame, result, max_depth, 3);
105108
#endif
106109
}
107-
108-
110+
#endif
109111

110112
/* *************************************************************
111113
* the signal handler

src/vmprof_mt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <string.h>
55
#include <sys/mman.h>
66

7-
#include "_vmprof.h"
7+
INCLUDE_MODULE_HEADER
88

99
/* The idea is that we have MAX_NUM_BUFFERS available, all of size
1010
SINGLE_BUF_SIZE. Threads and signal handlers can ask to reserve a

0 commit comments

Comments
 (0)