Skip to content

Commit

Permalink
CR: use set, ensure no Process objs dups
Browse files Browse the repository at this point in the history
  • Loading branch information
roi-granulate committed Oct 15, 2024
1 parent 8f5fdc7 commit a41d05c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gprofiler/profilers/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _profile_process(self, process: Process, duration: int, spawned: bool) -> Pr
return ProfileData(parsed, appid, app_metadata, container_name)

def _select_processes_to_profile(self) -> List[Process]:
filtered_procs = []
filtered_procs = set()
if is_windows():
all_processes = [x for x in pgrep_exe("python")]
else:
Expand All @@ -272,13 +272,14 @@ def _select_processes_to_profile(self) -> List[Process]:
for process in all_processes:
try:
if not self._should_skip_process(process):
filtered_procs.append(process)
filtered_procs.add(process)
except NoSuchProcess:
pass
except Exception:
logger.exception(f"Couldn't add pid {process.pid} to list")

return filtered_procs + [Process(pid) for pid in self._python_pyspy_process]
filtered_procs.update([Process(pid) for pid in self._python_pyspy_process])
return list(filtered_procs)

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

0 comments on commit a41d05c

Please sign in to comment.