Skip to content

Commit

Permalink
perf: Use /tmp/gprofiler/perf-buildids as the buildid cache for perf (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Jongy authored Apr 8, 2021
1 parent c2e9f4f commit cbc04d2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions gprofiler/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand All @@ -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):
Expand Down

0 comments on commit cbc04d2

Please sign in to comment.