From b69e3ca78fb78b3ea70e382421005ee773f6b09c Mon Sep 17 00:00:00 2001 From: Artur Sarlo Date: Fri, 21 Nov 2025 21:22:14 +0000 Subject: [PATCH 1/2] Fix hw_metrics module to correctly call PerfSpect and add PerfSpect dependencies to dockerfiles --- container.Dockerfile | 2 ++ gprofiler/hw_metrics.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/container.Dockerfile b/container.Dockerfile index 346ecdd1d..d744518c5 100644 --- a/container.Dockerfile +++ b/container.Dockerfile @@ -4,6 +4,8 @@ ARG ARCH ARG EXE_PATH=build/${ARCH}/gprofiler # lets gProfiler know it is running in a container ENV GPROFILER_IN_CONTAINER=1 +# Install sudo and bash for PerfSpect to run with full functionality +RUN apk add --no-cache sudo bash COPY ${EXE_PATH} /gprofiler RUN chmod +x /gprofiler diff --git a/gprofiler/hw_metrics.py b/gprofiler/hw_metrics.py index 5877134a8..357d8d702 100644 --- a/gprofiler/hw_metrics.py +++ b/gprofiler/hw_metrics.py @@ -91,10 +91,21 @@ def start(self) -> None: str(self._perfspect_duration), "--output", PERFSPECT_DATA_DIRECTORY, - "--noroot", ] - self._ps_process = subprocess.Popen(ps_cmd, stdout=subprocess.PIPE) + # Clean environment to avoid PyInstaller LD_LIBRARY_PATH pollution + # that causes sudo to fail with library loading errors + env = os.environ.copy() + if 'LD_LIBRARY_PATH' in env: + ld_paths = env['LD_LIBRARY_PATH'].split(':') + # Filter out paths that contain _MEI (PyInstaller temp directories) + cleaned_paths = [p for p in ld_paths if '_MEI' not in p] + if cleaned_paths: + env['LD_LIBRARY_PATH'] = ':'.join(cleaned_paths) + else: + del env['LD_LIBRARY_PATH'] + + self._ps_process = subprocess.Popen(ps_cmd, stdout=subprocess.PIPE, env=env) # nosec B603 def stop(self) -> None: if self._ps_process: From 64e0ebd9e22474badff07f07012257794213dc89 Mon Sep 17 00:00:00 2001 From: Artur Sarlo Date: Mon, 24 Nov 2025 18:22:33 +0000 Subject: [PATCH 2/2] Fix pyininstaller to include hidden imports --- pyinstaller.spec | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyinstaller.spec b/pyinstaller.spec index 60f77b8e4..8289df379 100644 --- a/pyinstaller.spec +++ b/pyinstaller.spec @@ -6,7 +6,13 @@ a = Analysis(scripts=['pyi_build.py'], pathex=['/app'], binaries=[], datas=[('gprofiler/resources', 'gprofiler/resources')], - hiddenimports=[], + hiddenimports=[ + 'backports', + 'backports.tarfile', + 'jaraco.text', + 'jaraco.context', + 'jaraco.functools', + ], hookspath=[], runtime_hooks=[], excludes=['readline'],