Skip to content

Commit 3617aaa

Browse files
authored
Merge branch 'master' into fix_popen_ref_leak
2 parents 17191c2 + bd9fce9 commit 3617aaa

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

gprofiler/hw_metrics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(
5757
perfspect_path: Optional[Path] = None,
5858
perfspect_duration: int = 60,
5959
polling_rate_seconds: int = DEFAULT_POLLING_INTERVAL_SECONDS,
60+
verbose: bool = False,
6061
):
6162
self._polling_rate_seconds = polling_rate_seconds
6263
self._stop_event = stop_event
@@ -65,6 +66,7 @@ def __init__(
6566
self._ps_process: Optional[subprocess.Popen[bytes]] = None
6667
self._perfspect_path: Optional[Path] = perfspect_path
6768
self._perfspect_duration = perfspect_duration
69+
self._verbose = verbose
6870

6971
self._ps_raw_csv_filename = PERFSPECT_DATA_DIRECTORY + "/" + platform.node() + "_metrics.csv"
7072
self._ps_summary_csv_filename = PERFSPECT_DATA_DIRECTORY + "/" + platform.node() + "_metrics_summary.csv"
@@ -93,7 +95,17 @@ def start(self) -> None:
9395
PERFSPECT_DATA_DIRECTORY,
9496
]
9597

98+
# Add --debug if verbose is enabled
99+
if self._verbose:
100+
ps_cmd.append("--debug")
101+
96102
self._ps_process = subprocess.Popen(ps_cmd, stdout=subprocess.PIPE)
103+
Thread(target=self._reap_ps_process, daemon=True).start()
104+
105+
def _reap_ps_process(self) -> None:
106+
if self._ps_process is not None:
107+
self._ps_process.wait()
108+
self._ps_process = None
97109

98110
def stop(self) -> None:
99111
if self._ps_process:

gprofiler/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def __init__(
126126
heartbeat_file_path: Optional[Path] = None,
127127
perfspect_path: Optional[Path] = None,
128128
perfspect_duration: int = 60,
129+
verbose: bool = False,
129130
):
130131
self._output_dir = output_dir
131132
self._flamegraph = flamegraph
@@ -182,6 +183,7 @@ def __init__(
182183
self._profiler_state.stop_event,
183184
perfspect_path=self._perfspect_path,
184185
perfspect_duration=self._perfspect_duration,
186+
verbose=verbose,
185187
)
186188
else:
187189
self._hw_metrics_monitor = NoopHWMetricsMonitor()
@@ -1219,15 +1221,16 @@ def main() -> None:
12191221
duration=args.duration,
12201222
profile_api_version=args.profile_api_version,
12211223
profiling_mode=args.profiling_mode,
1222-
collect_hw_metrics=args.collect_hw_metrics,
1224+
collect_hw_metrics=getattr(args, "collect_hw_metrics", False),
12231225
profile_spawned_processes=args.profile_spawned_processes,
12241226
remote_logs_handler=remote_logs_handler,
12251227
controller_process=controller_process,
12261228
processes_to_profile=processes_to_profile,
12271229
external_metadata_path=external_metadata_path,
12281230
heartbeat_file_path=heartbeat_file_path,
1229-
perfspect_path=args.tool_perfspect_path,
1230-
perfspect_duration=args.tool_perfspect_duration,
1231+
perfspect_path=perfspect_path,
1232+
perfspect_duration=getattr(args, "tool_perfspect_duration", 60),
1233+
verbose=args.verbose,
12311234
)
12321235
logger.info("gProfiler initialized and ready to start profiling")
12331236
if args.continuous:

0 commit comments

Comments
 (0)