Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PythonProfiler: expose --python-pyspy-process #932

Merged
merged 10 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 12 additions & 1 deletion gprofiler/profilers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ def __init__(
profiler_state: ProfilerState,
*,
add_versions: bool,
python_pyspy_processes: List[int],
):
super().__init__(frequency, duration, profiler_state)
self.add_versions = add_versions
self._metadata = PythonMetadata(self._profiler_state.stop_event)
self._python_pyspy_processes = python_pyspy_processes

def _make_command(self, pid: int, output_path: str, duration: int) -> List[str]:
command = [
Expand Down Expand Up @@ -275,7 +277,7 @@ def _select_processes_to_profile(self) -> List[Process]:
except Exception:
logger.exception(f"Couldn't add pid {process.pid} to list")

return filtered_procs
return filtered_procs + [Process(pid) for pid in self._python_pyspy_processes]
Jongy marked this conversation as resolved.
Show resolved Hide resolved

def _should_profile_process(self, process: Process) -> bool:
return search_proc_maps(process, DETECTED_PYTHON_PROCESSES_REGEX) is not None and not self._should_skip_process(
Expand Down Expand Up @@ -340,6 +342,13 @@ def _should_skip_process(self, process: Process) -> bool:
action="store_true",
help="Enable PyPerf in verbose mode (max verbosity)",
),
ProfilerArgument(
name="--python-pyspy-processes",
dest="python_pyspy_processes",
nargs="+",
roi-granulate marked this conversation as resolved.
Show resolved Hide resolved
type=int,
help="List of processes (by PID) to profile with py-spy." "This option forces gProfiler to ",
Jongy marked this conversation as resolved.
Show resolved Hide resolved
),
],
supported_profiling_modes=["cpu"],
)
Expand All @@ -358,6 +367,7 @@ def __init__(
python_add_versions: bool,
python_pyperf_user_stacks_pages: Optional[int],
python_pyperf_verbose: bool,
python_pyspy_processes: List[int],
):
if python_mode == "py-spy":
python_mode = "pyspy"
Expand Down Expand Up @@ -387,6 +397,7 @@ def __init__(
duration,
profiler_state,
add_versions=python_add_versions,
python_pyspy_processes=python_pyspy_processes,
)
else:
self._pyspy_profiler = None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_pyspy(
profiler_state: ProfilerState,
) -> None:
_ = assert_app_id # Required for mypy unused argument warning
with PySpyProfiler(1000, 3, profiler_state, add_versions=True) as profiler:
with PySpyProfiler(1000, 3, profiler_state, add_versions=True, python_pyspy_processes=[]) as profiler:
# not using snapshot_one_collapsed because there are multiple Python processes running usually.
process_collapsed = snapshot_pid_collapsed(profiler, application_pid)
assert_collapsed(process_collapsed)
Expand Down
Loading