Skip to content

Commit e4e99e5

Browse files
authored
Merge pull request #198 from timpalpant/master
Use PyFrame_GetLineNumber to get line numbers
2 parents 8fb8187 + 3f75fbf commit e4e99e5

File tree

1 file changed

+2
-27
lines changed

1 file changed

+2
-27
lines changed

src/vmp_stack.c

+2-27
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ int vmp_profiles_python_lines(void) {
8282

8383
static PY_STACK_FRAME_T * _write_python_stack_entry(PY_STACK_FRAME_T * frame, void ** result, int * depth, int max_depth)
8484
{
85-
int len;
86-
int addr;
87-
int j;
88-
uint64_t line;
89-
char *lnotab;
90-
9185
#ifndef RPYTHON_VMPROF // pypy does not support line profiling
9286
if (vmp_profiles_python_lines()) {
9387
// In the line profiling mode we save a line number for every frame.
@@ -99,27 +93,8 @@ static PY_STACK_FRAME_T * _write_python_stack_entry(PY_STACK_FRAME_T * frame, vo
9993

10094
// NOTE: the profiling overhead can be reduced by storing co_lnotab in the dump and
10195
// moving this computation to the reader instead of doing it here.
102-
lnotab = PyStr_AS_STRING(frame->f_code->co_lnotab);
103-
104-
if (lnotab != NULL) {
105-
line = (uint64_t)frame->f_lineno;
106-
addr = 0;
107-
108-
len = (int)PyStr_GET_SIZE(frame->f_code->co_lnotab);
109-
110-
for (j = 0; j < len; j += 2) {
111-
addr += lnotab[j];
112-
if (addr > frame->f_lasti) {
113-
break;
114-
}
115-
line += lnotab[j+1];
116-
}
117-
result[*depth] = (void*) line;
118-
*depth = *depth + 1;
119-
} else {
120-
result[*depth] = (void*) 0;
121-
*depth = *depth + 1;
122-
}
96+
result[*depth] = (void*) (int64_t) PyFrame_GetLineNumber(frame);
97+
*depth = *depth + 1;
12398
}
12499
result[*depth] = (void*)CODE_ADDR_TO_UID(FRAME_CODE(frame));
125100
*depth = *depth + 1;

0 commit comments

Comments
 (0)