-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine_timestamp.py
173 lines (126 loc) · 6.15 KB
/
combine_timestamp.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import os
import shutil
import re
LOG_FILE_EXTENSION = ".log"
#INITIATOR_PATTERN = "Initiator"
#RESPONDER_PATTERN = "Responder"
INITIATOR_PATTERN = "GB_New_I"
RESPONDER_PATTERN = "GB_New_R"
COMBINE_PATTERN = "combined"
def parse_log(packet_dict, role, file):
cur_seq_num = -1
with open(file, errors='ignore') as file_obj:
line = file_obj.readline()
while line:
seq_num_re = re.search("SEQ NUM (\d+)", line)
if seq_num_re:
cur_seq_num = int(seq_num_re.group(1))
if not cur_seq_num in packet_dict:
packet_dict[cur_seq_num] = {}
if cur_seq_num in packet_dict:
poll_re = re.search("Poll (.*)", line)
if poll_re:
packet_dict[cur_seq_num][role + "_poll"] = poll_re.group(1)
response_re = re.search("Response (.*)", line)
if response_re:
packet_dict[cur_seq_num][role + "_response"] = response_re.group(1)
final_re = re.search("Final (.*)", line)
if final_re:
packet_dict[cur_seq_num][role + "_final"] = final_re.group(1)
line = file_obj.readline()
if __name__ == '__main__':
for root, dirs, files in os.walk(".", topdown=False):
print("\n\n")
print("folder:{}, files:{}".format(root, files))
responder_file_list = []
initiator_file_list = []
angle_list = []
file_list = files
for file in file_list:
print(file)
if not file.endswith(LOG_FILE_EXTENSION):
continue
if re.search(RESPONDER_PATTERN, file):
responder_file_list.append(file)
if re.search(INITIATOR_PATTERN, file):
initiator_file_list.append(file)
if len(responder_file_list) == 0:
continue
responder_file_list.sort(key= lambda file:int(file.split('_')[-1].replace('.log', '')))
initiator_file_list.sort(key= lambda file:int(file.split('_')[-1].replace('.log', '')))
print(responder_file_list)
print(initiator_file_list)
print("len(responder_file_list):%d" %(len(responder_file_list)))
print("len(initiator_file_list):%d" %(len(initiator_file_list)))
assert(len(responder_file_list) == len(initiator_file_list))
for file in responder_file_list:
angle_list.append(file.split('_')[-1].replace('.log', ''))
print(angle_list)
for index, angle in enumerate(angle_list):
packet_dict = {}
# angle_dir = os.path.join(root, angle)
# os.makedirs(angle_dir, exist_ok=True)
initiator_path = os.path.join(root, initiator_file_list[index])
responder_path = os.path.join(root, responder_file_list[index])
parse_log(packet_dict, "initiator", initiator_path)
parse_log(packet_dict, "responder", responder_path)
combined_timestamp_file = os.path.join(root, "combined_" + angle + ".log")
with open(combined_timestamp_file, 'w') as file_obj:
for seq_num, value in packet_dict.items():
# print(packet, value)
if "initiator_poll" in value and "initiator_response" in value and "initiator_final" in value and "responder_poll" in value and "responder_response" in value and "responder_final" in value:
timestamp_str = "%d %s %s %s %s %s %s\n" %(seq_num, value["initiator_poll"], value["responder_poll"], value["responder_response"], value["initiator_response"], value["initiator_final"], value["responder_final"])
print("%s" %timestamp_str)
file_obj.write(timestamp_str)
for root, dirs, files in os.walk(".", topdown=False):
responder_file_list = []
initiator_file_list = []
combined_list = []
angle_list = []
file_list = files
for file in file_list:
print(file)
if not file.endswith(LOG_FILE_EXTENSION):
continue
if re.search(RESPONDER_PATTERN, file):
responder_file_list.append(file)
if re.search(INITIATOR_PATTERN, file):
initiator_file_list.append(file)
if re.search(COMBINE_PATTERN, file):
combined_list.append(file)
if len(responder_file_list) == 0:
continue
responder_file_list.sort(key= lambda file:int(file.split('_')[-1].replace('.log', '')))
initiator_file_list.sort(key= lambda file:int(file.split('_')[-1].replace('.log', '')))
combined_list.sort(key= lambda file:int(file.split('_')[-1].replace('.log', '')))
print(responder_file_list)
print(initiator_file_list)
print(combined_list)
print("len(responder_file_list):%d" %(len(responder_file_list)))
print("len(initiator_file_list):%d" %(len(initiator_file_list)))
assert(len(responder_file_list) == len(initiator_file_list))
for file in responder_file_list:
angle_list.append(file.split('_')[-1].replace('.log', ''))
print(angle_list)
for index, angle in enumerate(angle_list):
packet_dict = {}
angle_dir = os.path.join(root, angle)
os.makedirs(angle_dir, exist_ok=True)
initiator_path = os.path.join(root, initiator_file_list[index])
responder_path = os.path.join(root, responder_file_list[index])
combined_path = os.path.join(root, combined_list[index])
parse_log(packet_dict, "initiator", initiator_path)
parse_log(packet_dict, "responder", responder_path)
shutil.move(initiator_path, angle_dir)
shutil.move(responder_path, angle_dir)
shutil.move(combined_path, angle_dir)
'''
sequence {
i_poll_tx
r_poll_rx
r_response_tx
i_response_rx
i_final_tx
r_final_rx
}
'''