Index: client/profilers/perf/perf.py |
diff --git a/client/profilers/perf/perf.py b/client/profilers/perf/perf.py |
index e6f9bb71afd441cf1b42e416087e476b0d1b629f..b9ad34f7a5982d0f6a3449318aba0dd8726d6183 100644 |
--- a/client/profilers/perf/perf.py |
+++ b/client/profilers/perf/perf.py |
@@ -13,11 +13,12 @@ from autotest_lib.client.bin import profiler, os_dep, utils |
class perf(profiler.profiler): |
version = 1 |
- def initialize(self, events=["cycles","instructions"]): |
+ def initialize(self, events=["cycles","instructions"], trace=False): |
if type(events) == str: |
self.events = [events] |
else: |
self.events = events |
+ self.trace = trace |
self.perf_bin = os_dep.command('perf') |
perf_help = utils.run('%s report help' % self.perf_bin, |
ignore_status=True).stderr |
@@ -25,7 +26,7 @@ class perf(profiler.profiler): |
for line in perf_help.split('\n'): |
a = "sort by key(s):" |
if a in line: |
- line = line.strip(a) |
+ line = line.replace(a, "") |
self.sort_keys = [k.rstrip(",") for k in line.split() if |
k.rstrip(",") != 'dso'] |
if not self.sort_keys: |
@@ -34,8 +35,12 @@ class perf(profiler.profiler): |
def start(self, test): |
self.logfile = os.path.join(test.profdir, "perf") |
- cmd = ("%s record -a -o %s" % |
+ cmd = ("exec %s record -a -o %s" % |
(self.perf_bin, self.logfile)) |
+ if "parent" in self.sort_keys: |
+ cmd += " -g" |
+ if self.trace: |
+ cmd += " -R" |
for event in self.events: |
cmd += " -e %s" % event |
self._process = subprocess.Popen(cmd, shell=True, |
@@ -57,6 +62,16 @@ class perf(profiler.profiler): |
p = subprocess.Popen(cmd, shell=True, stdout=outfile, |
stderr=subprocess.STDOUT) |
p.wait() |
+ |
+ if self.trace: |
+ tracefile = os.path.join(test.profdir, 'trace') |
+ cmd = ("%s trace -i %s" % (self.perf_bin, self.logfile,)) |
+ |
+ outfile = open(tracefile, 'w') |
+ p = subprocess.Popen(cmd, shell=True, stdout=outfile, |
+ stderr=subprocess.STDOUT) |
+ p.wait() |
+ |
# The raw detailed perf output is HUGE. We cannot store it by default. |
perf_log_size = os.stat(self.logfile)[stat.ST_SIZE] |
logging.info('Removing %s after generating reports (saving %s bytes).', |