aboutsummaryrefslogtreecommitdiff
path: root/crosperf/perf_processor.py
blob: 031f35d29120ad93d1df0730c25fab7c292f23d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python

# Copyright 2011 Google Inc. All Rights Reserved.

import os
import re
from utils import command_executer
from utils import utils


class PerfProcessor(object):
  class PerfResults(object):
    def __init__(self, report, output):
      self.report = report
      self.output = output

  def __init__(self, logger_to_use=None):
    self._logger = logger_to_use
    self._ce = command_executer.GetCommandExecuter(self._logger)

  def GeneratePerfResults(self, results_dir, chromeos_root, board):
    perf_location = os.path.join(results_dir,
                                 os.path.basename(results_dir),
                                 "profiling/iteration.1")
    host_perf_location = os.path.join(chromeos_root, "chroot",
                                      perf_location.lstrip("/"))
    report = self._GeneratePerfReport(perf_location, chromeos_root, board)
    output = self._ReadPerfOutput(host_perf_location)
    return PerfProcessor.PerfResults(report, output)

  def ParseStatResults(self, results):
    output = results.output
    result = {}
    p = re.compile("\s*([0-9.]+) +(\S+)")
    for line in output.split("\n"):
      match = p.match(line)
      if match:
        result[match.group(2)] = match.group(1)
    return result

  def _ReadPerfOutput(self, perf_location):
    perf_output_file = os.path.join(perf_location, "perf.out")
    with open(perf_output_file, "rb") as f:
      return f.read()

  def _GeneratePerfReport(self, perf_location, chromeos_root, board):
    perf_data_file = os.path.join(perf_location, "perf.data")
    # Attempt to build a perf report and keep it with the results.
    command = ("/usr/sbin/perf report --symfs=/build/%s"
               " -i %s --stdio | head -n1000" % (board, perf_data_file))
    _, out, _ = self._ce.ChrootRunCommand(chromeos_root,
                                          command, return_output=True)
    return out


class MockPerfProcessor(object):
  def __init__(self):
    pass

  def GeneratePerfReport(self, *args):
    pass

  def ParseStatResults(self, *args):
    return {}