OLD | NEW |
---|---|
1 """ | 1 """ |
2 perf is a tool included in the linux kernel tree that | 2 perf is a tool included in the linux kernel tree that |
3 supports functionality similar to oprofile and more. | 3 supports functionality similar to oprofile and more. |
4 | 4 |
5 @see: http://lwn.net/Articles/310260/ | 5 @see: http://lwn.net/Articles/310260/ |
6 """ | 6 """ |
7 | 7 |
8 import time, os, stat, subprocess, signal | 8 import time, os, stat, subprocess, signal |
9 import logging | 9 import logging |
10 from autotest_lib.client.bin import profiler, os_dep, utils | 10 from autotest_lib.client.bin import profiler, os_dep, utils |
11 | 11 |
12 | 12 |
13 class perf(profiler.profiler): | 13 class perf(profiler.profiler): |
14 version = 1 | 14 version = 1 |
15 | 15 |
16 def initialize(self, events="cycles,instructions"): | 16 def initialize(self, events=["cycles","instructions"]): |
17 self.events = events | 17 if type(events) == str: |
18 self.events = [events] | |
19 else: | |
20 self.events = events | |
18 self.perf_bin = os_dep.command('perf') | 21 self.perf_bin = os_dep.command('perf') |
19 perf_help = utils.run('%s report help' % self.perf_bin, | 22 perf_help = utils.run('%s report help' % self.perf_bin, |
20 ignore_status=True).stderr | 23 ignore_status=True).stderr |
21 self.sort_keys = None | 24 self.sort_keys = None |
22 for line in perf_help.split('\n'): | 25 for line in perf_help.split('\n'): |
23 a = "sort by key(s):" | 26 a = "sort by key(s):" |
24 if a in line: | 27 if a in line: |
25 line = line.strip(a) | 28 line = line.strip(a) |
26 self.sort_keys = [k.rstrip(",") for k in line.split() if | 29 self.sort_keys = [k.rstrip(",") for k in line.split() if |
27 k.rstrip(",") != 'dso'] | 30 k.rstrip(",") != 'dso'] |
28 if not self.sort_keys: | 31 if not self.sort_keys: |
29 self.sort_keys = ['comm', 'cpu'] | 32 self.sort_keys = ['comm', 'cpu'] |
30 | 33 |
31 | 34 |
32 def start(self, test): | 35 def start(self, test): |
33 self.logfile = os.path.join(test.profdir, "perf") | 36 self.logfile = os.path.join(test.profdir, "perf") |
34 cmd = ("%s record -a -o %s -e %s" % | 37 cmd = ("%s record -a -o %s" % |
35 (self.perf_bin, self.logfile, self.events)) | 38 (self.perf_bin, self.logfile)) |
39 for event in self.events: | |
40 cmd += " -e %s" % event | |
truty1
2011/04/20 17:36:42
This is a change to the perf bin interface. I hop
| |
36 self._process = subprocess.Popen(cmd, shell=True, | 41 self._process = subprocess.Popen(cmd, shell=True, |
37 stderr=subprocess.STDOUT) | 42 stderr=subprocess.STDOUT) |
38 | 43 |
39 | 44 |
40 def stop(self, test): | 45 def stop(self, test): |
41 os.kill(self._process.pid, signal.SIGINT) | 46 os.kill(self._process.pid, signal.SIGINT) |
42 self._process.wait() | 47 self._process.wait() |
43 | 48 |
44 | 49 |
45 def report(self, test): | 50 def report(self, test): |
46 for key in self.sort_keys: | 51 for key in self.sort_keys: |
47 reportfile = os.path.join(test.profdir, '%s.comm' % key) | 52 reportfile = os.path.join(test.profdir, '%s.comm' % key) |
48 cmd = ("%s report -i %s --sort %s,dso" % (self.perf_bin, | 53 cmd = ("%s report -i %s --sort %s,dso" % (self.perf_bin, |
49 self.logfile, | 54 self.logfile, |
50 key)) | 55 key)) |
51 outfile = open(reportfile, 'w') | 56 outfile = open(reportfile, 'w') |
52 p = subprocess.Popen(cmd, shell=True, stdout=outfile, | 57 p = subprocess.Popen(cmd, shell=True, stdout=outfile, |
53 stderr=subprocess.STDOUT) | 58 stderr=subprocess.STDOUT) |
54 p.wait() | 59 p.wait() |
55 # The raw detailed perf output is HUGE. We cannot store it by default. | 60 # The raw detailed perf output is HUGE. We cannot store it by default. |
56 perf_log_size = os.stat(self.logfile)[stat.ST_SIZE] | 61 perf_log_size = os.stat(self.logfile)[stat.ST_SIZE] |
57 logging.info('Removing %s after generating reports (saving %s bytes).', | 62 logging.info('Removing %s after generating reports (saving %s bytes).', |
58 self.logfile, perf_log_size) | 63 self.logfile, perf_log_size) |
59 os.unlink(self.logfile) | 64 os.unlink(self.logfile) |
OLD | NEW |