• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Run iostat with a default interval of 1 second.
3"""
4import time, os, subprocess
5from autotest_lib.client.bin import profiler
6from autotest_lib.client.common_lib import utils, error
7
8
9class iostat(profiler.profiler):
10    version = 2
11
12    def initialize(self, interval = 1, options = ''):
13        # Usage: iostat [ options... ] [ <interval> [ <count> ] ]
14        # e.g, iostat -tmx 2
15        self.interval = interval
16        self.options = options
17
18
19    def start(self, test):
20        cmd = "/usr/bin/iostat %s %d" % (self.options, self.interval)
21        filename = "iostat." + time.strftime("%Y-%m-%d-%H-%M-%S")
22        logfile = open(os.path.join(test.profdir, filename), 'w')
23        p = subprocess.Popen(cmd, shell=True, stdout=logfile,
24                             stderr=subprocess.STDOUT)
25        self.pid = p.pid
26
27
28    def stop(self, test):
29        try:
30            term_profiler = "kill -15 %d" % self.pid
31            # send SIGTERM to iostat and give it a 5-sec timeout
32            utils.system(term_profiler, timeout=5)
33        except error.CmdError: # probably times out
34            pass
35        # do a ps again to see if iostat is still there
36        ps_cmd = "ps -p %d | grep iostat" % self.pid
37        out = utils.system_output(ps_cmd, ignore_status=True)
38        if out != '':
39            kill_profiler = 'kill -9 %d' % self.pid
40            utils.system(kill_profiler, ignore_status=True)
41
42
43    def report(self, test):
44        return None
45