• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Routines for reading performance results from a directory.
6
7The directory should match the format created by the 'bootperf'
8script; see comments in that script for a summary of the layout.
9
10"""
11
12import fnmatch
13import os
14import re
15
16import resultset
17
18
19_PERF_KEYVAL_PATTERN = re.compile("(.*){perf}=(.*)\n")
20
21
22def _ReadKeyvalFile(results, file_):
23  """Read an autotest keyval file, and process the results.
24
25  The `file_` parameter is a file object with contents in autotest
26  perf keyval format:
27      <keyname>{perf}=<value>
28
29  Each iteration of the test is terminated with a single blank line,
30  including the last iteration.  Each iteration's results are added
31  to the `results` parameter, which should be an instance of
32  TestResultSet.
33
34  @param results A TestResultSet where the result data will be
35                 collected.
36  @param file_ File object for the results file to be read.
37
38  """
39  kvd = {}
40  for line in iter(file_):
41    if line == "\n":
42      results.AddIterationResults(kvd)
43      kvd = {}
44      continue
45    m = _PERF_KEYVAL_PATTERN.match(line)
46    if m is None:
47      continue
48    kvd[m.group(1)] = m.group(2)
49
50
51_RESULTS_PATH = "summary/platform_BootPerfServer/results/keyval"
52
53
54def ReadResultsDirectory(dir_):
55  """Process results from a 'bootperf' output directory.
56
57  The accumulated results are returned in a newly created
58  TestResultSet object.
59
60  @param dir_ The directory containing the test results keyval file.
61
62  """
63  res_set = resultset.TestResultSet(dir_)
64  dirlist = fnmatch.filter(os.listdir(dir_), "run.???")
65  dirlist.sort()
66  for rundir in dirlist:
67    keyval_path = os.path.join(dir_, rundir, _RESULTS_PATH)
68    try:
69      kvf = open(keyval_path)
70    except IOError:
71      continue
72    _ReadKeyvalFile(res_set, kvf)
73  res_set.FinalizeResults()
74  return res_set
75