From 44a45c0656912f7a22b216d452ada52d1b0caa09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Sat, 14 Mar 2020 00:00:02 +0000 Subject: [PATCH] out/run.sh: write before execution --- README.adoc | 9 ++++++++- common.py | 3 ++- run | 3 +-- shell_helpers.py | 11 +++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.adoc b/README.adoc index 350cdd6..feda5a1 100644 --- a/README.adoc +++ b/README.adoc @@ -12445,7 +12445,14 @@ Profiling builds as of 3cea7d9ce49bda49c50e756339ff1287fd55df77 both use: `-g -O * `prof` uses `-pg` for gprof * `perf` uses `-lprofile` for google-pprof -See also: <>. +Profiling techniques are discussed in more detail at: <>. + +For the `prof` build, you can get the `gmon.out` file with: + +.... +./run --arch aarch64 --emulator gem5 --userland userland/c/hello.c --gem5-build-type prof +gprof "$(./getvar --arch aarch64 gem5_executable)" > tmp.gprof +.... ==== gem5 clang build diff --git a/common.py b/common.py index a5a9fb3..4542909 100644 --- a/common.py +++ b/common.py @@ -944,7 +944,8 @@ Incompatible archs are skipped. else: env['guest_terminal_file'] = env['qemu_termout_file'] env['trace_txt_file'] = env['qemu_trace_txt_file'] - env['run_cmd_file'] = join(env['run_dir'], 'run.sh') + env['run_cmd_file_basename'] = 'run.sh' + env['run_cmd_file'] = join(env['run_dir'], env['run_cmd_file_basename']) # Linux kernel. if not env['_args_given']['linux_build_dir']: diff --git a/run b/run index 570ca04..cfcf974 100755 --- a/run +++ b/run @@ -840,14 +840,13 @@ Extra options to append at the end of the emulator command line. out_file = self.env['termout_file'] exit_status = self.sh.run_cmd( cmd, - cmd_file=self.env['run_cmd_file'], + cmd_files=[self.env['run_cmd_file'], os.path.join(self.env['out_dir'], self.env['run_cmd_file_basename'])], extra_env=extra_env, out_file=out_file, raise_on_failure=False, show_stdout=show_stdout, stdin_path=self.env['stdin_file'], ) - self.sh.cp(self.env['run_cmd_file'], self.env['out_dir'], quiet=True) if self.env['debug_vm_rr']: rr_cmd = ['rr', 'replay', LF, '-o', '-q', LF] for arg in shlex.split(self.env['debug_vm_args']): diff --git a/shell_helpers.py b/shell_helpers.py index 65805d7..ddf19c4 100644 --- a/shell_helpers.py +++ b/shell_helpers.py @@ -243,6 +243,7 @@ class ShellHelpers: cmd, cwd=None, cmd_file=None, + cmd_files=None, extra_env=None, extra_paths=None, force_oneline=False, @@ -268,7 +269,11 @@ class ShellHelpers: ) if not self.quiet: self._print_thread_safe('+ ' + cmd_string) + if cmd_files is None: + cmd_files = [] if cmd_file is not None: + cmd_files.append(cmd_file) + for cmd_file in cmd_files: os.makedirs(os.path.dirname(cmd_file), exist_ok=True) with open(cmd_file, 'w') as f: f.write('#!/usr/bin/env bash\n') @@ -287,6 +292,7 @@ class ShellHelpers: self, cmd, cmd_file=None, + cmd_files=None, out_file=None, show_stdout=True, show_cmd=True, @@ -310,6 +316,10 @@ class ShellHelpers: :param cmd_file: if not None, write the command to be run to that file :type cmd_file: str + :param cmd_files: if not None, write the command to be run to all files in this list + cmd_file gets appended to that list if given. + :type cmd_files: List[str] + :param out_file: if not None, write the stdout and stderr of the command the file :type out_file: str @@ -358,6 +368,7 @@ class ShellHelpers: cmd, cwd=cwd, cmd_file=cmd_file, + cmd_files=cmd_files, extra_env=extra_env, extra_paths=extra_paths, stdin_path=stdin_path