aboutsummaryrefslogtreecommitdiffstats
path: root/parse/dir_map.py
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2012-09-27 19:03:22 -0400
committerJonathan Herman <hermanjl@cs.unc.edu>2012-09-27 19:03:22 -0400
commit7c09ec981c6e06af2e62d67a609eb53728267954 (patch)
tree76a93db7cadc452ac70eabbd52fdd87ed5fd54c4 /parse/dir_map.py
parent5554e053e9f3d5f7987d3f1d889802b211af8eab (diff)
Added script to parse directory data, create CSVs for every chagned value.
This change also makes SchedTrace and OverheadTrace events configurable.
Diffstat (limited to 'parse/dir_map.py')
-rw-r--r--parse/dir_map.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/parse/dir_map.py b/parse/dir_map.py
new file mode 100644
index 0000000..6e959f2
--- /dev/null
+++ b/parse/dir_map.py
@@ -0,0 +1,104 @@
1import os
2
3from collections import defaultdict
4from point import Type
5
6class TreeNode(object):
7 def __init__(self, parent = None):
8 self.parent = parent
9 self.children = defaultdict(lambda : TreeNode(self))
10 self.values = []
11
12class DirMap(object):
13 def to_csv(self, vals):
14 val_strs = []
15 for key in sorted(vals.keys()):
16 val_strs += ["%s=%s" % (key, vals[key])]
17 return "%s.csv" % ("_".join(val_strs))
18
19 def __init__(self, out_dir):
20 self.root = TreeNode(None)
21 self.out_dir = out_dir
22 self.values = []
23
24 def debug_update_node(self, path, keys, value):
25 self.__update_node(path, keys, value)
26
27 def __update_node(self, path, keys, value):
28 node = self.root
29
30 path += [ self.to_csv(keys) ]
31 for p in path:
32 node = node.children[p]
33
34 node.values += [value]
35
36 def add_point(self, vary, vary_value, keys, point):
37 for stat in point.get_stats():
38 summary = point[stat]
39
40 for summary_type in Type:
41 measurement = summary[summary_type]
42
43 for base_type in Type:
44 if not base_type in measurement:
45 continue
46 # Ex: wcet/avg/max/vary-type/other-stuff.csv
47 path = [ stat, summary_type, base_type, "vary-%s" % vary ]
48 result = measurement[base_type]
49
50 self.__update_node(path, keys, (vary_value, result))
51
52
53
54 def reduce(self):
55 def reduce2(node):
56 for key in node.children.keys():
57 child = node.children[key]
58 reduce2(child)
59 if not (child.children or child.values):
60 node.children.pop(key)
61
62 if len(node.values) == 1:
63 node.values = []
64
65 reduce2(self.root)
66
67 def write(self):
68 def write2(path, node):
69 out_path = "/".join(path)
70 if node.values:
71 # Leaf
72 with open("/".join(path), "w") as f:
73 arr = [",".join([str(b) for b in n]) for n in node.values]
74 f.write("\n".join(arr) + "\n")
75 elif not os.path.isdir(out_path):
76 os.mkdir(out_path)
77
78 for (key, child) in node.children.iteritems():
79 path.append(key)
80 write2(path, child)
81 path.pop()
82
83
84 write2([self.out_dir], self.root)
85
86
87 def __str__(self):
88 def str2(node, level):
89 header = " " * level
90 ret = ""
91 if not node.children:
92 return "%s%s\n" % (header, str(node.values) if node.values else "")
93 for key,child in node.children.iteritems():
94 ret += "%s/%s\n" % (header, key)
95 ret += str2(child, level + 1)
96 return ret
97
98 return "%s\n%s" % (self.out_dir, str2(self.root, 1))
99
100
101
102
103
104