bootperf-bin: drop old local copy
This was been moved to autotest a while back and further updated there.
Drop this copy as nothing seems to reference it.
BUG=None
TEST=precq passes
Change-Id: I63d2be0bec2c9b30d64c8c426bce78d93ba7b642
Reviewed-on: https://chromium-review.googlesource.com/1163139
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Richard Barnette <jrbarnette@google.com>
diff --git a/bootperf-bin/bootperf b/bootperf-bin/bootperf
deleted file mode 100755
index f01f160..0000000
--- a/bootperf-bin/bootperf
+++ /dev/null
@@ -1,245 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# Wrapper to run the platform_BootPerfServer autotest, and store the
-# results for later analysis by the 'showbootdata' script.
-#
-# NOTE: This script must be run from inside the chromeos build
-# chroot environment.
-#
-
-# --- BEGIN COMMON.SH BOILERPLATE ---
-# Load common CrOS utilities. Inside the chroot this file is installed in
-# /usr/lib/crosutils. Outside the chroot we find it relative to the script's
-# location.
-find_common_sh() {
- local common_paths=(/usr/lib/crosutils "$(dirname "$(readlink -f "$0")")/..")
- local path
-
- SCRIPT_ROOT=
- for path in "${common_paths[@]}"; do
- if [ -r "${path}/common.sh" ]; then
- SCRIPT_ROOT=${path}
- break
- fi
- done
-}
-
-find_common_sh
-. "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1)
-# --- END COMMON.SH BOILERPLATE ---
-
-# TODO(jrbarnette) The log files produced in this script will be
-# stored inside the chroot. So, from outside the chroot, this
-# script doesn't work. I don't know if this is easy to fix, but
-# you're welcome to try. Let me know how it goes. :-)
-assert_inside_chroot
-
-DEFINE_string output_dir "" "output directory for results" o
-DEFINE_string board "" "name of board we are testing"
-DEFINE_boolean keep_logs "$FLAGS_FALSE" "keep autotest results" k
-
-RUN_TEST="test_that"
-TEST='f:.*/platform_BootPerfServer/control'
-TMP_RESULTS="$(mktemp -d /tmp/bootperf.XXXXXX)"
-RESULTS_ROOT=results-1-experimental_BootPerfServer
-RESULTS_DIR=platform_BootPerfServer/results
-RESULTS_KEYVAL=$RESULTS_DIR/keyval
-RESULTS_SUMMARY_FILES=(
- $RESULTS_DIR
- keyval
- platform_BootPerfServer/keyval
- platform_BootPerfServer/platform_BootPerf/keyval
- platform_BootPerfServer/platform_BootPerf/status
- platform_BootPerfServer/status
- platform_BootPerfServer/status.log
- platform_BootPerfServer/sysinfo/cmdline
- platform_BootPerfServer/sysinfo/cpuinfo
- platform_BootPerfServer/sysinfo/modules
- platform_BootPerfServer/sysinfo/uname
- platform_BootPerfServer/sysinfo/version
- status.log
-)
-
-# Structure of a results directory:
-# $RUNDIR.$ITER/ - directory
-# $RUNDIR_LOG - file
-# $RUNDIR_SUMMARY/ - directory
-# $RUNDIR_ALL_RESULTS/ - optional directory
-# $KEYVAL_SUMMARY/ - file
-# If you add any other content under the results directory, you'll
-# probably need to change extra_files(), below.
-RUNDIR=run
-RUNDIR_LOG=log.txt
-RUNDIR_SUMMARY=summary
-RUNDIR_ALL_RESULTS=logs
-KEYVAL_SUMMARY=results_keyval
-
-
-# Usage/help function. This function is known to the shflags library,
-# and mustn't be renamed.
-flags_help() {
- cat <<END_USAGE >&2
-usage: $(basename $0) [ <options> ] <ip-address> [ <count> ]
-Options:
- --output_dir <directory>
- --o <directory> Specify output directory for results
-
- --board <BOARDNAME> name of board we are testing (e.g. daisy)
-
- --[no]keep_logs
- -k Keep [don't keep] autotest log files
-Summary:
- Run the platform_BootPerfServer autotest, and store results in the
- given destination directory. The test target is specified by
- <ip-address>.
-
- By default, the test is run once; if <count> is given, the test is
- run that many times. Note that the platform_BootPerfServer test
- reboots the target 10 times, so the total number of reboots will
- be 10*<count>.
-
- If the destination directory doesn't exist, it is created. If the
- destination directory already holds test results, additional
- results are added in without overwriting earlier results.
-
- If no destination is specified, the current directory is used,
- provided that the directory is empty, or has been previously used
- as a destination directory for this command.
-
- By default, only a summary subset of the log files created by
- autotest is preserved; with --keep_logs the (potentially large)
- autotest logs are preserved with the test results.
-END_USAGE
- return $FLAGS_TRUE
-}
-
-usage() {
- if [ $# -gt 0 ]; then
- error "$(basename $0): $*"
- echo >&2
- fi
- flags_help
- exit 1
-}
-
-# List any files in the current directory not created as output
-# from running this script.
-extra_files() {
- ls | grep -v "^$RUNDIR[.]...\$" |
- grep -v $KEYVAL_SUMMARY
-}
-
-# Main function to run the boot performance test. Run the boot
-# performance test for the given count, putting output into the
-# current directory.
-#
-# Arguments are <ip-address> and <count> arguments, as for the main
-# command.
-#
-# We terminate test runs if "test_that" ever fails to produce the
-# results keyval file; generally this is the result of a serious
-# error (e.g. disk full) that won't go away if we just plow on.
-run_boot_test() {
- local remote="$1"
- local count="${2:-1}"
-
- local iter=$(expr "$(echo $RUNDIR.???)" : '.*\(...\)')
- if [ "$iter" != "???" ]; then
- iter=$(echo $iter | awk '{printf "%03d\n", $1 + 1}')
- else
- iter=000
- fi
-
- i=0
- while [ $i -lt $count ]; do
- local iter_rundir=$RUNDIR.$iter
- local logfile=$(pwd)/$iter_rundir/$RUNDIR_LOG
- local summary_dir=$iter_rundir/$RUNDIR_SUMMARY
- local all_results_dir=$iter_rundir/$RUNDIR_ALL_RESULTS
-
- mkdir $iter_rundir
- echo "$(date '+%T') - $logfile"
-
- $RUN_TEST --results_dir="$TMP_RESULTS" \
- "$remote" $BOARD $TEST >$logfile 2>&1
- if [ ! -e "$TMP_RESULTS/$RESULTS_ROOT/$RESULTS_KEYVAL" ]; then
- error "No results file; terminating test runs."
- error "Check $logfile for output from the test run,"
- error "and see $TMP_RESULTS for full test logs and output."
- return
- fi
- mkdir $summary_dir
- tar cf - -C $TMP_RESULTS/$RESULTS_ROOT "${RESULTS_SUMMARY_FILES[@]}" |
- tar xf - -C $summary_dir
- if [ $FLAGS_keep_logs -eq $FLAGS_TRUE ]; then
- mv $TMP_RESULTS $all_results_dir
- chmod 755 $all_results_dir
- else
- rm -rf $TMP_RESULTS
- fi
- i=$(expr $i + 1)
- iter=$(echo $iter | awk '{printf "%03d\n", $1 + 1}')
- done
- date '+%T'
- cat $RUNDIR.???/$RUNDIR_SUMMARY/$RESULTS_KEYVAL >$KEYVAL_SUMMARY
-}
-
-# Main routine - check validity of the (already parsed) command line
-# options. 'cd' to the results directory, if it was specified. If
-# all the arguments checks pass, hand control to run_boot_test
-main() {
- if [ $# -lt 1 ]; then
- usage "Missing target host address"
- elif [ $# -gt 2 ]; then
- usage "Too many arguments"
- fi
-
- if [ -n "${FLAGS_board}" ]; then
- BOARD="--board=${FLAGS_board}"
- fi
-
- if [ -n "${FLAGS_output_dir}" ]; then
- if [ ! -d "${FLAGS_output_dir}" ]; then
- if ! mkdir "${FLAGS_output_dir}"; then
- usage "Unable to create ${FLAGS_output_dir}"
- fi
- fi
- cd "${FLAGS_output_dir}" ||
- usage "No permissions to chdir to ${FLAGS_output_dir}"
- elif [ -n "$(extra_files)" ]; then
- error "No results directory specified, and current directory"
- error "contains contents other than run results."
- error "You can override this error by using the --output_dir option"
- usage
- fi
-
- # Check the count argument.
- # N.B. the test [ "$2" -eq "$2" ] tests whether "$2" is valid as a
- # number; when it fails it will also report a syntax error (which
- # we suppress).
- if [ -n "$2" ]; then
- if ! [ "$2" -eq "$2" ] 2>/dev/null || [ "$2" -le 0 ]; then
- usage "<count> argument must be a positive number"
- fi
- fi
-
- run_boot_test "$@"
-}
-
-# shflags defines --help implicitly; if it's used on the command
-# line FLAGS will invoke flags_help, set FLAGS_help to TRUE, and
-# then return false. To avoid printing help twice, we have to check
-# for that case here.
-if ! FLAGS "$@"; then
- if [ ${FLAGS_help} -eq ${FLAGS_TRUE} ]; then
- exit 0
- else
- usage
- fi
-fi
-
-eval main "${FLAGS_ARGV}"
diff --git a/bootperf-bin/perfprinter.py b/bootperf-bin/perfprinter.py
deleted file mode 100644
index 4d33ddf..0000000
--- a/bootperf-bin/perfprinter.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""Routines for printing boot time performance test results."""
-
-import resultset
-
-
-def PrintRawData(reader, dirlist, keytype, keylist):
- """Print 'bootperf' results in "raw data" format."""
- for dir_ in dirlist:
- results = reader(dir_)
- keyset = results.KeySet(keytype)
- for i in range(0, keyset.num_iterations):
- if len(dirlist) > 1:
- line = "%s %3d" % (results.name, i)
- else:
- line = "%3d" % i
- if keylist is not None:
- markers = keylist
- else:
- markers = keyset.markers
- for stat in markers:
- (_, v) = keyset.PrintableStatistic(keyset.RawData(stat)[i])
- line += " %5s" % str(v)
- print line
-
-
-def PrintStatisticsSummary(reader, dirlist, keytype, keylist):
- """Print 'bootperf' results in "summary of averages" format."""
- if (keytype == resultset.TestResultSet.BOOTTIME_KEYSET or
- keytype == resultset.TestResultSet.FIRMWARE_KEYSET):
- header = "%5s %3s %5s %3s %s" % (
- "time", "s%", "dt", "s%", "event")
- tformat = "%5s %2d%% %5s %2d%% %s"
- else:
- header = "%7s %3s %7s %3s %s" % (
- "diskrd", "s%", "delta", "s%", "event")
- tformat = "%7s %2d%% %7s %2d%% %s"
- havedata = False
- for dir_ in dirlist:
- results = reader(dir_)
- keyset = results.KeySet(keytype)
- if keylist is not None:
- markers = keylist
- else:
- markers = keyset.markers
- if havedata:
- print
- if len(dirlist) > 1:
- print "%s" % results.name,
- print "(on %d cycles):" % keyset.num_iterations
- print header
- prevvalue = 0
- prevstat = None
- for stat in markers:
- (valueavg, valuedev) = keyset.Statistics(stat)
- valuepct = int(100 * valuedev / valueavg + 0.5)
- if prevstat:
- (deltaavg, deltadev) = keyset.DeltaStatistics(prevstat, stat)
- deltapct = int(100 * deltadev / deltaavg + 0.5)
- else:
- deltapct = valuepct
- (valstring, val_printed) = keyset.PrintableStatistic(valueavg)
- delta = val_printed - prevvalue
- (deltastring, _) = keyset.PrintableStatistic(delta)
- print tformat % (valstring, valuepct, "+" + deltastring, deltapct, stat)
- prevvalue = val_printed
- prevstat = stat
- havedata = True
diff --git a/bootperf-bin/resultsdir.py b/bootperf-bin/resultsdir.py
deleted file mode 100644
index 942a275..0000000
--- a/bootperf-bin/resultsdir.py
+++ /dev/null
@@ -1,68 +0,0 @@
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""Routines for reading performance results from a directory.
-
-The directory should match the format created by the 'bootperf'
-script; see comments in that script for a summary of the layout.
-
-"""
-
-import fnmatch
-import os
-import re
-
-import resultset
-
-
-_PERF_KEYVAL_PATTERN = re.compile("(.*){perf}=(.*)\n")
-
-
-def _ReadKeyvalFile(results, file_):
- """Read an autotest keyval file, and process the results.
-
- The `file_` parameter is a file object with contents in autotest
- perf keyval format:
- <keyname>{perf}=<value>
-
- Each iteration of the test is terminated with a single blank line,
- including the last iteration. Each iteration's results are added
- to the `results` parameter, which should be an instance of
- TestResultSet.
-
- """
- kvd = {}
- for line in iter(file_):
- if line == "\n":
- results.AddIterationResults(kvd)
- kvd = {}
- continue
- m = _PERF_KEYVAL_PATTERN.match(line)
- if m is None:
- continue
- kvd[m.group(1)] = m.group(2)
-
-
-_RESULTS_PATH = "summary/platform_BootPerfServer/results/keyval"
-
-
-def ReadResultsDirectory(dir_):
- """Process results from a 'bootperf' output directory.
-
- The accumulated results are returned in a newly created
- TestResultSet object.
-
- """
- res_set = resultset.TestResultSet(dir_)
- dirlist = fnmatch.filter(os.listdir(dir_), "run.???")
- dirlist.sort()
- for rundir in dirlist:
- keyval_path = os.path.join(dir_, rundir, _RESULTS_PATH)
- try:
- kvf = open(keyval_path)
- except IOError:
- continue
- _ReadKeyvalFile(res_set, kvf)
- res_set.FinalizeResults()
- return res_set
diff --git a/bootperf-bin/resultset.py b/bootperf-bin/resultset.py
deleted file mode 100644
index 6e78e93..0000000
--- a/bootperf-bin/resultset.py
+++ /dev/null
@@ -1,260 +0,0 @@
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""Classes and functions for managing platform_BootPerf results.
-
-Results from the platform_BootPerf test in the ChromiumOS autotest
-package are stored as performance 'keyvals', that is, a mapping
-of names to numeric values. For each iteration of the test, one
-set of keyvals is recorded.
-
-This module currently tracks three kinds of keyval results: the boot
-time results, the disk read results, and firmware time results.
-These results are stored with keyval names such as
-'seconds_kernel_to_login', 'rdbytes_kernel_to_login', and
-'seconds_power_on_to_kernel'. These keyvals record an accumulated
-total measured from a fixed time in the past, e.g.
-'seconds_kernel_to_login' records the total seconds from kernel
-startup to login screen ready.
-
-The boot time keyval names all start with the prefix
-'seconds_kernel_to_', and record time in seconds since kernel
-startup.
-
-The disk read keyval names all start with the prefix
-'rdbytes_kernel_to_', and record bytes read from the boot device
-since kernel startup.
-
-The firmware keyval names all start with the prefix
-'seconds_power_on_to_', and record time in seconds since CPU
-power on.
-
-"""
-
-import math
-
-
-def _ListStats(list_):
- # Utility function - calculate the average and (sample) standard
- # deviation of a list of numbers. Result is float, even if the
- # input list is full of int's
- sum_ = 0.0
- sumsq = 0.0
- for v in list_:
- sum_ += v
- sumsq += v * v
- n = len(list_)
- avg = sum_ / n
- var = (sumsq - sum_ * avg) / (n - 1)
- if var < 0.0:
- var = 0.0
- dev = math.sqrt(var)
- return (avg, dev)
-
-
-def _DoCheck(dict_):
- # Utility function - check the that all keyvals occur the same
- # number of times. On success, return the number of occurrences;
- # on failure return None
- check = map(len, dict_.values())
- if not check:
- return None
- for i in range(1, len(check)):
- if check[i] != check[i-1]:
- return None
- return check[0]
-
-
-def _KeyDelta(dict_, key0, key1):
- # Utility function - return a list of the vector difference between
- # two keyvals.
- return map(lambda a, b: b - a, dict_[key0], dict_[key1])
-
-
-class TestResultSet(object):
- """A set of boot time and disk usage result statistics.
-
- Objects of this class consist of three sets of result statistics:
- the boot time statistics, the disk statistics, and the firmware
- time statistics.
-
- Class TestResultsSet does not interpret or store keyval mappings
- directly; iteration results are processed by attached _KeySet
- objects, one for each of the three types of result keyval. The
- _KeySet objects are kept in a dictionary; they can be obtained
- by calling the KeySet with the name of the keyset desired.
- Various methods on the KeySet objects will calculate statistics on
- the results, and provide the raw data.
-
- """
-
- # The names of the available KeySets, to be used as arguments to
- # KeySet().
- BOOTTIME_KEYSET = "time"
- DISK_KEYSET = "disk"
- FIRMWARE_KEYSET = "firmware"
-
- def __init__(self, name):
- self.name = name
- self._keysets = {
- self.BOOTTIME_KEYSET : _TimeKeySet(),
- self.DISK_KEYSET : _DiskKeySet(),
- self.FIRMWARE_KEYSET : _FirmwareKeySet(),
- }
-
- def AddIterationResults(self, runkeys):
- """Add keyval results from a single iteration.
-
- A TestResultSet is constructed by repeatedly calling
- AddIterationResults(), iteration by iteration. Iteration
- results are passed in as a dictionary mapping keyval attributes
- to values. When all iteration results have been added,
- FinalizeResults() makes the results available for analysis.
-
- """
-
- for keyset in self._keysets.itervalues():
- keyset.AddIterationResults(runkeys)
-
- def FinalizeResults(self):
- """Make results available for analysis.
-
- A TestResultSet is constructed by repeatedly feeding it results,
- iteration by iteration. Iteration results are passed in as a
- dictionary mapping keyval attributes to values. When all iteration
- results have been added, FinalizeResults() makes the results
- available for analysis.
-
- """
-
- for keyset in self._keysets.itervalues():
- keyset.FinalizeResults()
-
- def KeySet(self, keytype):
- """Return the boot time statistics result set."""
- return self._keysets[keytype]
-
-
-class _KeySet(object):
- """Container for a set of related statistics.
-
- _KeySet is an abstract superclass for containing collections of
- a related set of performance statistics. Statistics are stored
- as a dictionary (`_keyvals`) mapping keyval names to lists of
- values. The lists are indexed by the iteration number.
-
- The mapped keyval names are shortened by stripping the prefix
- that identifies the type of keyval (keyvals that don't start with
- the proper prefix are ignored). So, for example, with boot time
- keyvals, 'seconds_kernel_to_login' becomes 'login' (and
- 'rdbytes_kernel_to_login' is ignored).
-
- A list of all valid keyval names is stored in the `markers`
- instance variable. The list is sorted by the ordering of the
- average of the corresponding values. Each iteration is required
- to contain the same set of keyvals. This is enforced in
- FinalizeResults() (see below).
-
- """
-
- def __init__(self):
- self._keyvals = {}
-
- def AddIterationResults(self, runkeys):
- """Add results for one iteration."""
-
- for key, value in runkeys.iteritems():
- if not key.startswith(self.PREFIX):
- continue
- shortkey = key[len(self.PREFIX):]
- keylist = self._keyvals.setdefault(shortkey, [])
- keylist.append(self._ConvertVal(value))
-
- def FinalizeResults(self):
- """Finalize this object's results.
-
- This method makes available the `markers` and `num_iterations`
- instance variables. It also ensures that every keyval occurred
- in every iteration by requiring that all keyvals have the same
- number of data points.
-
- """
-
- count = _DoCheck(self._keyvals)
- if count is None:
- self.num_iterations = 0
- self.markers = []
- return False
- self.num_iterations = count
- keylist = map(lambda k: (sum(self._keyvals[k]), k),
- self._keyvals.keys())
- keylist.sort(key=lambda tp: tp[0])
- self.markers = map(lambda tp: tp[1], keylist)
- return True
-
- def RawData(self, key):
- """Return the list of values for the given marker key."""
- return self._keyvals[key]
-
- def DeltaData(self, key0, key1):
- """Return vector difference of the values of the given keys."""
- return _KeyDelta(self._keyvals, key0, key1)
-
- def Statistics(self, key):
- """Return the average and standard deviation of the key's values."""
- return _ListStats(self._keyvals[key])
-
- def DeltaStatistics(self, key0, key1):
- """Return the average and standard deviation of the differences
- between two keys.
-
- """
- return _ListStats(self.DeltaData(key0, key1))
-
-
-class _TimeKeySet(_KeySet):
- """Concrete subclass of _KeySet for boot time statistics."""
-
- PREFIX = 'seconds_kernel_to_'
-
- # Time-based keyvals are reported in seconds and get converted to
- # milliseconds
- TIME_SCALE = 1000
-
- def _ConvertVal(self, value):
- # We want to return the nearest exact integer here. round()
- # returns a float, and int() truncates its results, so we have
- # to combine them.
- return int(round(self.TIME_SCALE * float(value)))
-
- def PrintableStatistic(self, value):
- v = int(round(value))
- return ("%d" % v, v)
-
-
-class _FirmwareKeySet(_TimeKeySet):
- """Concrete subclass of _KeySet for firmware time statistics."""
-
- PREFIX = 'seconds_power_on_to_'
-
- # Time-based keyvals are reported in seconds and get converted to
- # milliseconds
- TIME_SCALE = 1000
-
-
-class _DiskKeySet(_KeySet):
- """Concrete subclass of _KeySet for disk read statistics."""
-
- PREFIX = 'rdbytes_kernel_to_'
-
- # Disk read keyvals are reported in bytes and get converted to
- # MBytes (1 MByte = 1 million bytes, not 2**20)
- DISK_SCALE = 1.0e-6
-
- def _ConvertVal(self, value):
- return self.DISK_SCALE * float(value)
-
- def PrintableStatistic(self, value):
- v = round(value, 1)
- return ("%.1fM" % v, v)
diff --git a/bootperf-bin/showbootdata b/bootperf-bin/showbootdata
deleted file mode 100755
index 009698a..0000000
--- a/bootperf-bin/showbootdata
+++ /dev/null
@@ -1,158 +0,0 @@
-#!/usr/bin/python
-
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""A command to display summary statistics from runs of 'bootperf'.
-
-Command line options allow selecting from one of three sets of
-performance statistics: boot time statistics (selected by
---timestats) measure time spent since kernel startup; disk statistics
-(selected by --diskstats) measure total bytes read from the boot
-device since kernel startup; firmware time statistics (selected by
---firmware) measure time spent since CPU power on.
-
-The various statistics are recorded as cumulative time (or disk read)
-since kernel startup (or CPU power on), sampled when specific events
-occur during boot. Events include such things as 'startup', the
-moment when the upstart 'startup' job begins running, and 'login',
-when the Chrome OS login screen is displayed. By default, all
-recorded events are included in the output; command line options
-allow restricting the view to a selected subset of events.
-
-Separate command line options allow selecting from one of two
-different display modes. When --averages is selected, the display
-shows the average value and sample standard deviation (as a percent
-of the average) for all selected events. The --averages display
-also calculates the difference (in time or bytes) between adjacent
-events, and shows the average and sample standard deviation of the
-differences.
-
-The --rawdata display shows the raw data value associated with each
-event for each boot: Each line of output represents the event values
-for one boot cycle.
-
-"""
-
-import sys
-import optparse
-
-import perfprinter
-import resultsdir
-import resultset
-
-
-_USAGE = "%prog [options] [results-directory ...]"
-_DESCRIPTION = """\
-Summarize boot time performance results. The result directory
-arguments are directories previously specified as output for the
-'bootperf' script.
-"""
-
-
-def _SetupOptions():
- optparser = optparse.OptionParser(usage=_USAGE, description=_DESCRIPTION)
-
- optgroup = optparse.OptionGroup(
- optparser, "Selecting boot time or disk statistics (choose one)")
- optgroup.add_option(
- "-t", "--timestats", action="store_true",
- dest="use_timestats",
- help="use statistics for time since kernel startup (default)")
- optgroup.add_option(
- "-d", "--diskstats", action="store_true",
- dest="use_diskstats",
- help="use statistics for bytes read since kernel startup")
- optgroup.add_option(
- "-f", "--firmwarestats", action="store_true",
- dest="use_firmware",
- help="use statistics for firmware startup times")
- optparser.add_option_group(optgroup)
- optparser.set_defaults(use_diskstats=False)
- optparser.set_defaults(use_timestats=False)
- optparser.set_defaults(use_firmware=False)
-
- optgroup = optparse.OptionGroup(optparser, "Event selection")
- optgroup.add_option(
- "-e", "--event", action="append",
- dest="eventnames",
- help="restrict statistics to the comma-separated list of events")
- optparser.add_option_group(optgroup)
-
- optgroup = optparse.OptionGroup(
- optparser, "Display mode selection (choose one)")
- optgroup.add_option(
- "-a", "--averages", action="store_true",
- dest="print_averages",
- help="display a summary of the averages of chosen statistics (default)")
- optgroup.add_option(
- "-r", "--rawdata", action="store_true",
- dest="print_raw",
- help="display raw data from all boot iterations")
- optparser.add_option_group(optgroup)
- optparser.set_defaults(print_averages=False)
- optparser.set_defaults(print_raw=False)
- return optparser
-
-
-def _ProcessDisplayOptions(options):
- display_count = 0
- if options.print_averages:
- display_count += 1
- printfunc = perfprinter.PrintStatisticsSummary
- if options.print_raw:
- display_count += 1
- printfunc = perfprinter.PrintRawData
- if display_count == 0:
- printfunc = perfprinter.PrintStatisticsSummary
- elif display_count > 1:
- print >>sys.stderr, "Can't use -a and -r together.\n"
- return None
- return printfunc
-
-
-def _ProcessKeysetOptions(options):
- keyset_count = 0
- keyset_type = resultset.TestResultSet.BOOTTIME_KEYSET
- if options.use_timestats:
- keyset_count += 1
- keyset_type = resultset.TestResultSet.BOOTTIME_KEYSET
- if options.use_diskstats:
- keyset_count += 1
- keyset_type = resultset.TestResultSet.DISK_KEYSET
- if options.use_firmware:
- keyset_count += 1
- keyset_type = resultset.TestResultSet.FIRMWARE_KEYSET
- if keyset_count > 1:
- print >>sys.stderr, "Can use only one of -t, -d, or -f.\n"
- keyset_type = None
- return keyset_type
-
-
-def _ProcessKeylistOptions(options):
- if not options.eventnames:
- return None
- keylist = []
- for kl in options.eventnames:
- keylist.extend(kl.split(','))
- return keylist
-
-
-def main(argv):
- optparser = _SetupOptions()
- (options, args) = optparser.parse_args(argv)
- printfunc = _ProcessDisplayOptions(options)
- keyset_type = _ProcessKeysetOptions(options)
- keylist = _ProcessKeylistOptions(options)
- if printfunc is None or keyset_type is None:
- optparser.print_help()
- sys.exit(1)
- if not args:
- args = ["."]
- printfunc(resultsdir.ReadResultsDirectory,
- args, keyset_type, keylist)
-
-
-if __name__ == "__main__":
- main(sys.argv[1:])