mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 1 | import os |
| 2 | from autotest_utils import * |
| 3 | from error import * |
| 4 | |
mbligh | 7bb9dbc | 2006-04-23 18:41:40 +0000 | [diff] [blame] | 5 | class profilers: |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 6 | def __init__(self, job): |
| 7 | self.job = job |
| 8 | self.list = [] |
| 9 | self.profdir = job.autodir + '/profilers' |
| 10 | self.tmpdir = job.tmpdir |
mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 11 | |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 12 | # add a profiler |
mbligh | 9eb80ba | 2006-05-26 22:00:04 +0000 | [diff] [blame] | 13 | def add(self, profiler, *args): |
mbligh | ff88e4e | 2006-05-25 19:34:52 +0000 | [diff] [blame] | 14 | try: |
| 15 | sys.path.insert(0, self.job.profdir + '/' + profiler) |
| 16 | exec 'import ' + profiler |
| 17 | exec 'newprofiler = %s.%s(self)' % (profiler, profiler) |
| 18 | finally: |
| 19 | sys.path.pop(0) |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 20 | newprofiler.name = profiler |
| 21 | newprofiler.bindir = self.profdir + '/' + profiler |
| 22 | newprofiler.srcdir = newprofiler.bindir + '/src' |
| 23 | newprofiler.tmpdir = self.tmpdir + '/' + profiler |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 24 | update_version(newprofiler.srcdir, newprofiler.version, newprofiler.setup) |
mbligh | 9eb80ba | 2006-05-26 22:00:04 +0000 | [diff] [blame] | 25 | newprofiler.initialize(*args) |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 26 | self.list.append(newprofiler) |
mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 27 | |
| 28 | |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 29 | # remove a profiler |
| 30 | def delete(self, profiler): |
mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 31 | nukeme = None |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 32 | for p in self.list: |
mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 33 | if (p.name == profiler): |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 34 | nukeme = p |
| 35 | self.list.remove(p) |
mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 36 | |
| 37 | |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 38 | # are any profilers enabled ? |
| 39 | def present(self): |
| 40 | if self.list: |
| 41 | return 1 |
| 42 | else: |
| 43 | return 0 |
| 44 | |
| 45 | |
| 46 | # Start all enabled profilers |
| 47 | def start(self, test): |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 48 | for p in self.list: |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 49 | p.start(test) |
mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 50 | |
| 51 | |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 52 | # Stop all enabled profilers |
| 53 | def stop(self, test): |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 54 | for p in self.list: |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 55 | p.stop(test) |
mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 56 | |
| 57 | |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 58 | # Report on all enabled profilers |
| 59 | def report(self, test): |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 60 | for p in self.list: |
mbligh | 7290556 | 2006-05-25 01:30:49 +0000 | [diff] [blame] | 61 | p.report(test) |
mbligh | edf430c | 2006-04-23 06:52:09 +0000 | [diff] [blame] | 62 | |