This repository was archived by the owner on Nov 12, 2020. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcprof2allocs.py
More file actions
executable file
·107 lines (87 loc) · 2.76 KB
/
Copy pathcprof2allocs.py
File metadata and controls
executable file
·107 lines (87 loc) · 2.76 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
import sys
import json
import subprocess
from pygraphml import Attribute
from pygraphml import Graph
from pygraphml import GraphMLParser
class Node():
def __init__(self, ID):
self.ID = ID
class Edge():
def __init__(self, src, dst, weight):
self.src = src
self.dst = dst
self.weight = weight
class Value(Node):
def __init__(self, ID, pos, size, allocation_id):
Node.__init__(self, ID)
self.pos = pos
self.size = size
self.alloc_id = allocation_id
def add_to_graph(self, g):
n = g.add_node(self.ID)
n["size"] = self.size
n["pos"] = self.pos
return n
class Allocation(Node):
def __init__(self, ID, pos, size, ty, addrsp):
Node.__init__(self, ID)
self.pos = pos
self.size = size
self.ty = ty
self.addrsp = addrsp
def add_to_graph(self, g):
n = g.add_node(self.ID)
n["size"] = self.size
n["pos"] = self.pos
return n
class DirectedEdge(Edge):
def __init__(self, src, dst, weight):
Edge.__init__(self, src, dst, weight)
def add_to_graph(self, g, nodes):
g.add_edge(nodes[self.src], nodes[self.dst], directed=True)
Nodes = {}
Values = {}
Allocations = {}
args = sys.argv[1:]
g = Graph()
# Find all allocations and values
with open(args[0], 'r') as f:
for line in f:
j = json.loads(line)
if "allocation" in j:
alloc = j["allocation"]
Id = int(alloc["id"])
pos = int(alloc["pos"])
size = int(alloc["size"])
AS = json.loads(alloc["addrsp"])
AM = json.loads(alloc["mem"])
pagetype = alloc["type"]
as_type = AS["type"]
newAlloc = Allocation(Id, pos, size, pagetype, as_type)
Allocations[Id] = newAlloc
Nodes[Id] = newAlloc.add_to_graph(g)
elif "val" in j:
val = j["val"]
Id = int(val["id"])
allocation_id = int(val["allocation_id"])
size = int(val["size"])
pos = int(val["pos"])
newValue = Value(Id, pos, size, allocation_id)
Values[Id] = newValue
## Use dependences to determine connection between allocations
with open(args[0], 'r') as f:
for line in f:
j = json.loads(line)
if "dep" in j:
dep = j["dep"]
srcValId = int(dep["src_id"])
dstValId = int(dep["dst_id"])
srcAllocId = Values[srcValId].alloc_id
dstAllocId = Values[dstValId].alloc_id
weight = Allocations[srcAllocId].size
newEdge = DirectedEdge(srcAllocId, dstAllocId, weight)
newEdge.add_to_graph(g, Nodes)
parser = GraphMLParser()
parser.write(g, "cprof.graphml")