-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgraphEnqueues.py
More file actions
executable file
·63 lines (55 loc) · 2.24 KB
/
graphEnqueues.py
File metadata and controls
executable file
·63 lines (55 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/pypy -u
from __future__ import (absolute_import, division, print_function)
import argparse
import collections
try:
import graphviz as gv
except ImportError:
gv = None
import parseTrace
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--trace", type=str, default="trace.out",
help="trace file")
parser.add_argument("--aborted", default=False, action='store_true',
help="graph aborted tasks instead of committed ones (helps analyze aborts)")
args = parser.parse_args()
tasks, _ = parseTrace.getTasks(args.trace)
print("Trace read")
# Build enqueue graph
taskFns = set()
taskEnqueues = {}
for t in tasks[1:]:
if t.outcomeCycle == -1: continue # partial trace
taskFns.add(t.taskFn)
isCommit = t.outcome[0] == "Commit"
if isCommit == args.aborted: continue
parentFn = tasks[t.parent].taskFn if t.parent else None
if parentFn not in taskEnqueues:
taskEnqueues[parentFn] = collections.Counter()
taskEnqueues[parentFn][t.taskFn] += 1
taskFns = sorted(taskFns)
print("\nEnqueues")
print("%16s %s" % ("Parent\Child PC", ' '.join("%16x" % child for child in taskFns)))
print("%16s %s" % ("No parent", ' '.join(
"%16d" % taskEnqueues[None][child] for child in taskFns)))
for parent in taskFns:
if parent in taskEnqueues:
print("%16s %s" % ("%16x" % parent, ' '.join(
"%16d" % taskEnqueues[parent][child] for child in taskFns)))
if gv:
graph = gv.Digraph(format="png")
for child in taskFns:
if taskEnqueues[None][child]:
graph.edge("No parent", format(child, 'x'),
label=str(taskEnqueues[0][child]))
for parent in taskFns:
if parent in taskEnqueues:
for child in taskFns:
if taskEnqueues[parent][child]:
graph.edge(format(parent, 'x'), format(child, 'x'),
label=str(taskEnqueues[parent][child]))
graph.render("enqueue_graph.gv", view=False)
print("enqueue_graph.gv.png written.")
else:
print("graphviz not found")