diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-02-22 17:10:46 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2011-02-22 17:10:46 -0500 |
commit | 20eada0aec9734ced5c3bd33c923ecf00f103380 (patch) | |
tree | b072aa7fb77b66648dbb24280a00c0bd8dc0f9b8 | |
parent | 9cf757f31f18455dc342be342a048a3d9f489e28 (diff) |
convert extracted trends to schedcat overhead profiles
-rwxr-xr-x | distill_schedcat_profiles.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/distill_schedcat_profiles.py b/distill_schedcat_profiles.py new file mode 100755 index 0000000..fa3c482 --- /dev/null +++ b/distill_schedcat_profiles.py | |||
@@ -0,0 +1,86 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | |||
4 | from plot import decode | ||
5 | from util import load_csv_file, write_csv_file | ||
6 | |||
7 | |||
8 | from os.path import splitext, basename | ||
9 | from optparse import make_option as o, OptionParser | ||
10 | from collections import defaultdict | ||
11 | |||
12 | options = None | ||
13 | opts = [ | ||
14 | # output options | ||
15 | o('-p', '--prefix', action='store', dest='prefix'), | ||
16 | o('-t', '--tag', action='store', dest='tag'), | ||
17 | ] | ||
18 | |||
19 | defaults = { | ||
20 | # output options | ||
21 | 'prefix' : '', | ||
22 | 'tag' : '', | ||
23 | } | ||
24 | |||
25 | |||
26 | class DataFile(object): | ||
27 | def __init__(self, fname): | ||
28 | bname = basename(fname) | ||
29 | name, ext = splitext(bname) | ||
30 | self.conf = decode(name) | ||
31 | self.sched = self.conf['scheduler'] | ||
32 | self.overhead = self.conf['overhead'] | ||
33 | self.host = self.conf['host'] | ||
34 | self.name = name | ||
35 | self.data = load_csv_file(fname) | ||
36 | |||
37 | |||
38 | def group_by_scheduler(files): | ||
39 | g = defaultdict(list) | ||
40 | for f in files: | ||
41 | g[f.sched].append(f) | ||
42 | return g | ||
43 | |||
44 | NUM_INDEX = 2 | ||
45 | WC_INDEX = 5 | ||
46 | AVG_INDEX = 6 | ||
47 | |||
48 | def write_profiles(files): | ||
49 | host = files[0].host | ||
50 | sched = files[0].sched | ||
51 | num = len(files[0].data) | ||
52 | |||
53 | def row(i, idx): | ||
54 | return [int(files[0].data[i][NUM_INDEX])] + [f.data[i][idx] for f in files] | ||
55 | |||
56 | avg = [row(i, AVG_INDEX) for i in xrange(num)] | ||
57 | wc = [row(i, WC_INDEX) for i in xrange(num)] | ||
58 | header = ['NUM_TASKS'] + [f.overhead.replace('-', '_') for f in files] | ||
59 | |||
60 | avg_name = '%soh_host=%s_scheduler=%s_stat=avg%s.csv' % \ | ||
61 | (options.prefix, host, sched, options.tag) | ||
62 | wc_name = '%soh_host=%s_scheduler=%s_stat=wc%s.csv' % \ | ||
63 | (options.prefix, host, sched, options.tag) | ||
64 | |||
65 | print 'Generating %s.' % (avg_name) | ||
66 | write_csv_file(avg_name, [header] + avg, width=15) | ||
67 | print 'Generating %s.' % (wc_name) | ||
68 | write_csv_file(wc_name, [header] + wc, width=15) | ||
69 | |||
70 | if __name__ == '__main__': | ||
71 | parser = OptionParser(option_list=opts) | ||
72 | parser.set_defaults(**defaults) | ||
73 | (options, files) = parser.parse_args() | ||
74 | |||
75 | try: | ||
76 | data = [] | ||
77 | for f in files: | ||
78 | try: | ||
79 | data.append(DataFile(f)) | ||
80 | except IOError as err: | ||
81 | print "Skipping %s.\n(%s)" % (f, err) | ||
82 | groups = group_by_scheduler(data) | ||
83 | for sched in groups: | ||
84 | write_profiles(groups[sched]) | ||
85 | except KeyboardInterrupt: | ||
86 | pass | ||