From cbc04d226859e7ffbb9ad1ee34b6c23d43818dbb Mon Sep 17 00:00:00 2001 From: Yonatan Goldschmidt Date: Thu, 8 Apr 2021 12:11:17 +0300 Subject: [PATCH] perf: Use /tmp/gprofiler/perf-buildids as the buildid cache for perf (#17) Avoid cluttering other parts of the filesystem (by default, it uses /root/.debug). When gprofiler runs as a container, it doesn't really matter (both /root/ and /tmp are just part of the container filesystem). But we plan to allow running gprofiler as an executable, and in that case, we should keep our files in /tmp/gprofiler. --- gprofiler/perf.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gprofiler/perf.py b/gprofiler/perf.py index 5a8d33fe0..dba62404b 100644 --- a/gprofiler/perf.py +++ b/gprofiler/perf.py @@ -10,12 +10,15 @@ import psutil -from .utils import run_process, resource_path +from .utils import run_process, resource_path, TEMPORARY_STORAGE_PATH from .merge import parse_perf_script logger = logging.getLogger(__name__) +PERF_BUILDID_DIR = os.path.join(TEMPORARY_STORAGE_PATH, "perf-buildids") + + class SystemProfiler: def __init__(self, frequency: int, duration: int, stop_event: Event, storage_dir: str): logger.info(f"Initializing system profiler (frequency: {frequency}hz, duration: {duration}s)") @@ -36,16 +39,20 @@ def close(self): def run_perf(self, filename_base: str, dwarf=False): parsed_path = os.path.join(self._storage_dir, f"{filename_base}.parsed") + buildid_args = ["--buildid-dir", PERF_BUILDID_DIR] + with NamedTemporaryFile(dir=self._storage_dir) as record_file: args = ["-F", str(self._frequency), "-a", "-g", "-o", record_file.name] if dwarf: args += ["--call-graph", "dwarf"] run_process( - [resource_path("perf"), "record"] + args + ["--", "sleep", str(self._duration)], + [resource_path("perf")] + buildid_args + ["record"] + args + ["--", "sleep", str(self._duration)], stop_event=self._stop_event, ) with open(parsed_path, "w") as f: - run_process([resource_path("perf"), "script", "-F", "+pid", "-i", record_file.name], stdout=f) + run_process( + [resource_path("perf")] + buildid_args + ["script", "-F", "+pid", "-i", record_file.name], stdout=f + ) return parsed_path def profile(self):