-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_trace_file.py
149 lines (119 loc) · 4.19 KB
/
read_trace_file.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from enum_sim import RecordType
from event import Record,EventRecord,StateRecord,CommunicationRecord
from event_type import EventType
def open_file(filename):
try:
f = open(filename, "r")
return f
except IOError as x:
print(x)
print("Could not open " + filename + "!")
return None
def func_sort_time(e):
return e.get_arriving_time()
def process_header(header):
cores_ = (header.split(":"))[3]
tasks_ = (header.split(":"))[5]
cores_ = [int(x) for x in cores_.replace("("," ").replace(")"," ").replace(","," ").split()]
tasks_ = [int(x) for x in tasks_.replace("("," ").replace(")"," ").replace(","," ").split()]
tasks_ = tasks_[0]
nnodes = cores_.pop(0)
node_conf = [nnodes, tasks_, cores_]
return node_conf
def read_prv_file(filename):
record_list = []
header = ""
f = open_file(filename)
if(f == None):
exit(0)
line = f.readline()
header += line
node_conf = process_header(header)
# The pointer is alread in position to start the skip
to_skip = node_conf[1] + 1
for _ in range(to_skip):
#next(f)
header += f.readline()
for line in f:
list_ = [int(x) for x in line.split(":")]
type_ = list_[0]
if(type_ == RecordType.STATE.value):
record_list.append(StateRecord(list_))
elif(type_ == RecordType.EVENT.value):
record_list.append(EventRecord(list_))
else:
record_list.append(CommunicationRecord(list_))
f.close()
return header,node_conf,record_list
def separate_trace_record(record_list_,state,event,comm):
state_list = []
event_list = []
communication_list = []
if state:
state_list = [x for x in record_list_ if isinstance(x,StateRecord)]
if event:
event_list = [x for x in record_list_ if isinstance(x,EventRecord)]
if comm:
communication_list = [x for x in record_list_ if isinstance(x,CommunicationRecord)]
return state_list,event_list,communication_list
def separate_record(record_list_):
record_list = []
communication_list = []
record_list = [x for x in record_list_ if (isinstance(x,StateRecord) or isinstance(x,EventRecord))]
communication_list = [x for x in record_list_ if isinstance(x,CommunicationRecord)]
return record_list,communication_list
def read_pcf_file(filename):
f = open_file(filename)
if(f == None):
exit(0)
state_dict = read_state(f)
event_dict = read_event_type(f)
return state_dict, event_dict
def read_state(f):
state_dict = {}
for line in f:
if line.strip() == "STATES":
break
line = f.readline().split()
while(len(line) > 0):
key = line.pop(0)
s = [str(i) for i in line]
res = " ".join(s)
state_dict[int(key)] = res
line = f.readline().split()
return state_dict
def read_event_type(f):
event_dict = {}
key=""
line = f.readline()
while(line):
if line.strip() == "EVENT_TYPE":
line = f.readline().split()
line.pop(0)
key = line.pop(0)
s = [str(i) for i in line]
res = " ".join(s)
event_dict[int(key)] = EventType(int(key),res)
line = f.readline()
if line.strip() == "VALUES":
line_list = f.readline().split()
while(len(line_list) > 1):
key_value = line_list.pop(0)
s = [str(i) for i in line_list]
res = " ".join(s)
event_dict[int(key)].set_event_type_value(int(key_value),res)
line = f.readline()
line_list = line.split()
else:
line_list = f.readline().split()
while(len(line_list) > 3):
line_list.pop(0)
key = line_list.pop(0)
s = [str(i) for i in line_list]
res = " ".join(s)
event_dict[int(key)] = EventType(int(key),res)
line = f.readline()
line_list = line.split()
else:
line = f.readline()
return event_dict