• 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 printing boot time performance test results."""
6
7import resultset
8
9
10def PrintRawData(reader, dirlist, keytype, keylist):
11  """Print 'bootperf' results in "raw data" format.
12
13  @param reader Function for reading results from results
14                directories.
15  @param dirlist List of directories to read results from.
16  @param keytype Selector specifying the desired key set (e.g.
17                 the boot time keyset, the disk stats keyset, etc.)
18  @param keylist List of event keys to be printed in the report.
19
20  """
21  for dir_ in dirlist:
22    results = reader(dir_)
23    keyset = results.KeySet(keytype)
24    for i in range(0, keyset.num_iterations):
25      if len(dirlist) > 1:
26        line = "%s %3d" % (results.name, i)
27      else:
28        line = "%3d" % i
29      if keylist is not None:
30        markers = keylist
31      else:
32        markers = keyset.markers
33      for stat in markers:
34        (_, v) = keyset.PrintableStatistic(keyset.RawData(stat)[i])
35        line += " %5s" % str(v)
36      print line
37
38
39def PrintStatisticsSummary(reader, dirlist, keytype, keylist):
40  """Print 'bootperf' results in "summary of averages" format.
41
42  @param reader Function for reading results from results
43                directories.
44  @param dirlist List of directories to read results from.
45  @param keytype Selector specifying the desired key set (e.g.
46                 the boot time keyset, the disk stats keyset, etc.)
47  @param keylist List of event keys to be printed in the report.
48
49  """
50  if (keytype == resultset.TestResultSet.BOOTTIME_KEYSET or
51      keytype == resultset.TestResultSet.FIRMWARE_KEYSET):
52    header = "%5s %3s  %5s %3s  %s" % (
53        "time", "s%", "dt", "s%", "event")
54    tformat = "%5s %2d%%  %5s %2d%%  %s"
55  else:
56    header = "%7s %3s  %7s %3s  %s" % (
57        "diskrd", "s%", "delta", "s%", "event")
58    tformat = "%7s %2d%%  %7s %2d%%  %s"
59  havedata = False
60  for dir_ in dirlist:
61    results = reader(dir_)
62    keyset = results.KeySet(keytype)
63    if keylist is not None:
64      markers = keylist
65    else:
66      markers = keyset.markers
67    if havedata:
68      print
69    if len(dirlist) > 1:
70      print "%s" % results.name,
71    print "(on %d cycles):" % keyset.num_iterations
72    print header
73    prevvalue = 0
74    prevstat = None
75    for stat in markers:
76      (valueavg, valuedev) = keyset.Statistics(stat)
77      valuepct = int(100 * valuedev / valueavg + 0.5)
78      if prevstat:
79        (deltaavg, deltadev) = keyset.DeltaStatistics(prevstat, stat)
80        deltapct = int(100 * deltadev / deltaavg + 0.5)
81      else:
82        deltapct = valuepct
83      (valstring, val_printed) = keyset.PrintableStatistic(valueavg)
84      delta = val_printed - prevvalue
85      (deltastring, _) = keyset.PrintableStatistic(delta)
86      print tformat % (valstring, valuepct, "+" + deltastring, deltapct, stat)
87      prevvalue = val_printed
88      prevstat = stat
89    havedata = True
90