Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | # Copyright 2011 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | import os |
| 6 | import re |
| 7 | from utils import command_executer |
| 8 | from utils import utils |
| 9 | |
| 10 | |
| 11 | class PerfProcessor(object): |
| 12 | class PerfResults(object): |
| 13 | def __init__(self, report, output): |
| 14 | self.report = report |
| 15 | self.output = output |
| 16 | |
| 17 | def __init__(self, logger_to_use=None): |
| 18 | self._logger = logger_to_use |
| 19 | self._ce = command_executer.GetCommandExecuter(self._logger) |
| 20 | |
| 21 | def GeneratePerfResults(self, results_dir, chromeos_root, board): |
| 22 | perf_location = os.path.join(results_dir, |
| 23 | os.path.basename(results_dir), |
| 24 | "profiling/iteration.1") |
| 25 | host_perf_location = os.path.join(chromeos_root, "chroot", |
| 26 | perf_location.lstrip("/")) |
| 27 | report = self._GeneratePerfReport(perf_location, chromeos_root, board) |
| 28 | output = self._ReadPerfOutput(host_perf_location) |
| 29 | return PerfProcessor.PerfResults(report, output) |
| 30 | |
| 31 | def ParseStatResults(self, results): |
| 32 | output = results.output |
| 33 | result = {} |
| 34 | p = re.compile("\s*([0-9.]+) +(\S+)") |
| 35 | for line in output.split("\n"): |
| 36 | match = p.match(line) |
| 37 | if match: |
| 38 | result[match.group(2)] = match.group(1) |
| 39 | return result |
| 40 | |
| 41 | def _ReadPerfOutput(self, perf_location): |
| 42 | perf_output_file = os.path.join(perf_location, "perf.out") |
| 43 | with open(perf_output_file, "rb") as f: |
| 44 | return f.read() |
| 45 | |
| 46 | def _GeneratePerfReport(self, perf_location, chromeos_root, board): |
| 47 | perf_data_file = os.path.join(perf_location, "perf.data") |
| 48 | # Attempt to build a perf report and keep it with the results. |
| 49 | command = ("/usr/sbin/perf report --symfs=/build/%s" |
| 50 | " -i %s --stdio | head -n1000" % (board, perf_data_file)) |
| 51 | _, out, _ = self._ce.ChrootRunCommand(chromeos_root, |
| 52 | command, return_output=True) |
| 53 | return out |
| 54 | |
| 55 | |
| 56 | class MockPerfProcessor(object): |
| 57 | def __init__(self): |
| 58 | pass |
| 59 | |
| 60 | def GeneratePerfReport(self, *args): |
| 61 | pass |
| 62 | |
| 63 | def ParseStatResults(self, *args): |
| 64 | return {} |