Skip to content

Commit f943707

Browse files
committed
do not sample stack if the frame provided is NULL,
cancel buffer if compare and swap of current code failed (impressed me, how can that error be in the code base that long)
1 parent f3449cf commit f943707

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/_vmprof.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static int emit_code_object(PyCodeObject *co)
7979
if (sz > MAX_FUNC_NAME / 2) sz = MAX_FUNC_NAME / 2;
8080
snprintf(buf + sz, MAX_FUNC_NAME / 2, ":%d:%s", co_firstlineno,
8181
co_filename);
82-
return vmprof_register_virtual_function(buf, CODE_ADDR_TO_UID(co), 500000);
82+
return vmprof_register_virtual_function(buf, CODE_ADDR_TO_UID(co), 500);
8383
}
8484

8585
static int _look_for_code_object(PyObject *o, void *all_codes)

src/vmp_stack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ int vmp_walk_and_record_stack(PY_STACK_FRAME_T *frame, void ** result,
196196
// PyPy saves the information of an address in the same way as line information
197197
// is saved in CPython. _write_python_stack_entry for details.
198198
//
199+
if (frame == NULL) {
200+
return 0;
201+
}
199202
#ifdef VMP_SUPPORTS_NATIVE_PROFILING
200203
intptr_t func_addr;
201204
unw_cursor_t cursor;

src/vmprof_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ int vmprof_register_virtual_function(char *code_name, intptr_t code_uid,
470470
if (!__sync_bool_compare_and_swap(&current_codes, NULL, p)) {
471471
/* failed, flush it */
472472
commit_buffer(vmp_profile_fileno(), p);
473+
} else {
474+
cancel_buffer(p);
473475
}
474476
return 0;
475477
}

0 commit comments

Comments
 (0)