Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Speed up :mod:`profiling.sampling` on macOS by mapping the target process's
memory pages into the profiler with ``mach_vm_remap`` instead of copying
them on every sample.
16 changes: 12 additions & 4 deletions Modules/_remote_debugging/frame_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,18 @@ read_last_profiled_anchor(RemoteUnwinderObject *unwinder,
// remote-memory read.
if (seq_offset == frame_offset + sizeof(uintptr_t)) {
uintptr_t live_anchor[2];
if (_Py_RemoteDebug_ReadRemoteMemory(&unwinder->handle,
thread_state_addr + frame_offset,
sizeof(live_anchor),
live_anchor) < 0) {
int rc = _Py_RemoteDebug_AliasedReadRemoteMemory(&unwinder->handle,
thread_state_addr + frame_offset,
sizeof(live_anchor),
live_anchor);
if (rc < 0) {
return -1;
}
if (rc > 0
&& _Py_RemoteDebug_ReadRemoteMemory(&unwinder->handle,
thread_state_addr + frame_offset,
sizeof(live_anchor),
live_anchor) < 0) {
return -1;
}
anchor->frame = live_anchor[0];
Expand Down
4 changes: 2 additions & 2 deletions Modules/_remote_debugging/frames.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ process_single_stack_chunk(
return -1;
}

if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, chunk_addr, current_size, this_chunk) < 0) {
if (_Py_RemoteDebug_ReadRemoteMemory(&unwinder->handle, chunk_addr, current_size, this_chunk) < 0) {
PyMem_RawFree(this_chunk);
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read stack chunk");
return -1;
Expand Down Expand Up @@ -65,7 +65,7 @@ process_single_stack_chunk(
}
this_chunk = tmp;

if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, chunk_addr, actual_size, this_chunk) < 0) {
if (_Py_RemoteDebug_ReadRemoteMemory(&unwinder->handle, chunk_addr, actual_size, this_chunk) < 0) {
PyMem_RawFree(this_chunk);
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to reread stack chunk with correct size");
return -1;
Expand Down
21 changes: 21 additions & 0 deletions Modules/_remote_debugging/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,27 @@ read_interp_state_and_maybe_thread_frame(
{
prefetch->tstate = NULL;
prefetch->frame = NULL;
int aliased = _Py_RemoteDebug_AliasedReadRemoteMemory(
&unwinder->handle, interpreter_addr, INTERP_STATE_BUFFER_SIZE,
interp_state_buffer);
if (aliased < 0) {
return -1;
}
if (aliased == 0) {
if (prefetch->tstate_addr != 0) {
size_t tstate_size = (size_t)unwinder->debug_offsets.thread_state.size;
int rc = _Py_RemoteDebug_AliasedReadRemoteMemory(
&unwinder->handle, prefetch->tstate_addr, tstate_size,
tstate_buffer);
if (rc == 0) {
prefetch->tstate = tstate_buffer;
}
else if (rc < 0) {
PyErr_Clear();
}
}
return 0;
}
if (prefetch->tstate_addr != 0) {
size_t tstate_size = (size_t)unwinder->debug_offsets.thread_state.size;
_Py_RemoteReadSegment segments[3] = {
Expand Down
15 changes: 12 additions & 3 deletions Modules/_remote_debugging/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ read_thread_state_and_maybe_frame(
int *frame_read)
{
*frame_read = 0;
int aliased = _Py_RemoteDebug_AliasedReadRemoteMemory(
&unwinder->handle, tstate_addr, tstate_size, tstate_buffer);
if (aliased <= 0) {
return aliased;
}
if (predicted_frame_addr != 0) {
_Py_RemoteReadSegment segments[2] = {
{tstate_addr, tstate_buffer, tstate_size},
Expand Down Expand Up @@ -380,11 +385,15 @@ unwind_stack_for_thread(
}
}
else {
int rc = _Py_RemoteDebug_ReadRemoteMemory(
&unwinder->handle,
int unused_frame_read = 0;
int rc = read_thread_state_and_maybe_frame(
unwinder,
*current_tstate,
(size_t)unwinder->debug_offsets.thread_state.size,
local_ts);
local_ts,
0,
NULL,
&unused_frame_read);
if (rc < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read thread state");
goto error;
Expand Down
Loading
Loading