• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2What's eating the battery life of my laptop? Why isn't it many more
3hours? Which software component causes the most power to be burned?
4These are important questions without a good answer... until now.
5"""
6import time, os
7from autotest_lib.client.bin import utils, profiler
8
9class powertop(profiler.profiler):
10    version = 1
11    preserve_srcdir = True
12
13    # filenames: list of filenames to cat
14    def setup(self, *args, **dargs):
15        os.chdir(self.srcdir)
16        utils.make()
17
18
19    def start(self, test):
20        self.child_pid = os.fork()
21        if self.child_pid:                      # parent
22            return None
23        else:                                   # child
24            powertop = os.path.join(self.srcdir, 'powertop') + ' -d'
25            outputfile = os.path.join(test.profdir, 'powertop')
26            while True:
27                output = open(outputfile, 'a')
28                output.write(time.asctime() + '\n')
29                data = utils.system_output('%s >> %s' % (powertop, outputfile))
30                output.write(data)
31                output.write('\n=========================\n')
32                output.close()
33
34
35    def stop(self, test):
36        os.kill(self.child_pid, 15)
37
38
39    def report(self, test):
40        return None
41