• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import logging
7
8from autotest_lib.client.bin import test
9from autotest_lib.client.common_lib import error, utils
10from autotest_lib.client.cros import service_stopper
11
12class hardware_MemoryThroughput(test.test):
13    """Autotest for measuring memory throughput.
14
15    This uses mem_bw with different parameters to measure memory and cache
16    throughput.
17
18    Private Attributes:
19      _results: dict containing keyvals with throughput measurements
20      _services: service_stopper.ServiceStopper object
21    """
22    version = 1
23
24    def _run_benchmarks(self, test, warmup, num_iterations, parallel, sizes):
25        """Run the benchmark.
26
27        This runs the bw_mem benchmark from lmbench 3 and fills out results.
28        Args:
29          test: string containing either rd, rdwr, cp, bzero, or bcopy
30          warmup:  integer amount of time to spend warming up in microseconds.
31          num_iterations: integer number of times to run the benchmark on each
32            size.
33          parallel: integer number of instances to run in parallel
34          sizes: list of integer sizes in bytes to run
35        """
36        r = {}
37
38        for size in sizes:
39            cmd = 'bw_mem -P %d -W %d -N %d %d %s 2>&1' % (parallel, warmup,
40                                                           num_iterations,
41                                                           size, test)
42            logging.debug('cmd: %s', cmd)
43            out = utils.system_output(cmd)
44            logging.debug('Output: %s', out)
45
46            lines = out.splitlines()
47            if len(lines) != 1:
48                raise error.TestFail('invalid amount of output from bw_mem')
49
50            s = lines[0].split()
51            if len(s) == 2:
52                bw = float(s[1])
53                if bw <= 0:
54                    raise error.TestFail('invalid throughput %f' % bw)
55                key = ('MB_per_second_' + test + '-' +
56                       str(parallel) + '-thread-' +
57                       str(size / 1024) + 'KB')
58                self._results[key] = bw
59            else:
60                raise error.TestFail('invalid output line %s' % lines[0])
61
62
63    def initialize(self):
64        super(hardware_MemoryThroughput, self).initialize()
65        self._results = {}
66        stop = [ 'ui' ]
67        stop.extend(service_stopper.ServiceStopper.POWER_DRAW_SERVICES)
68        self._services = service_stopper.ServiceStopper(stop)
69        self._services.stop_services()
70
71
72    def run_once(self, test='bcopy', warmup=100, num_iterations=20,
73                 parallel=1, sizes= [ 4096, 192 * 1024, 32 * 1024 * 1024 ]):
74        self._run_benchmarks(test, warmup, num_iterations, parallel,
75                             sizes)
76        self.write_perf_keyval(self._results)
77
78
79    def cleanup(self):
80        self._services.restore_services()
81        super(hardware_MemoryThroughput, self).cleanup()
82