• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Sets up a subprocses to cat a file on a specified interval
3
4Defaults options:
5job.profilers.add('catprofile', ['/proc/meminfo','/proc/uptime'],
6                  outfile=monitor, interval=1)
7"""
8import time, os
9from autotest_lib.client.bin import profiler
10
11class catprofile(profiler.profiler):
12    version = 1
13
14    # filenames: list of filenames to cat
15    def initialize(self, filenames = ['/proc/meminfo', '/proc/slabinfo'],
16                            outfile = 'monitor', interval = 1):
17        self.filenames = filenames
18        self.outfile = outfile
19        self.interval = interval
20
21
22    def start(self, test):
23        self.child_pid = os.fork()
24        if self.child_pid:                      # parent
25            return None
26        else:                                   # child
27            while 1:
28                lines = []
29                for filename in self.filenames:
30                    input = open(filename, 'r')
31                    lines += '\n----- %s -----\n' % filename
32                    lines += input.readlines()
33                    input.close
34                outfile = test.profdir + '/' + self.outfile
35                output = open(outfile, 'a')
36                output.write(time.asctime() + '\n')
37                output.writelines(lines)
38                output.write('\n=========================\n')
39                output.close()
40                time.sleep(self.interval)
41
42
43    def stop(self, test):
44        os.kill(self.child_pid, 15)
45
46
47    def report(self, test):
48        return None
49