forked from ValdikSS/aceproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashstream-parser.py
More file actions
124 lines (94 loc) · 3.49 KB
/
hashstream-parser.py
File metadata and controls
124 lines (94 loc) · 3.49 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import sys
import io
import csv
import datetime
time_marker = 0x00
def main():
reference = datalog(sys.argv[1])
comparison = datalog(sys.argv[2])
sync=0
#We assume the reference contains all data contained in the comparison
for hash in reference:
try:
if comparison.next() != hash:
comparison.back()
if sync > 10:
#if reference.position() > 205940 and reference.position() < 205955:
print("Lost sync at: ref:{} ({}) cmp:{} ({}) \n".format(reference.position(), reference.peek(),comparison.position(), comparison.peek()))
sync = 0
continue
else:
#if reference.position() > 205500 and reference.position() < 206500:
if reference.position() % 10000 == 0:
print("Synchronized: ref:{} cmp:{} sync:{} \n".format(reference.position(), comparison.position(),sync))
#comparison.next()
sync+=1
comparison.set_datapoint_value(comparison.cur_timestamp - reference.cur_timestamp)
except StopIteration:
break
print("finished, writing results\n")
print((comparison.timelength, len(comparison.delaydata), len(comparison.bandwidth)))
with open(sys.argv[3], 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=['timestamp','delay','bandwidth'], dialect='excel')
writer.writeheader()
for x in range(0,comparison.timelength-10):
writer.writerow({'timestamp': x+comparison.starttime, 'delay': comparison.delaydata[x], 'bandwidth': comparison.bandwidth[x]})
#print results
#for val in comparison.delaydata:
# print((val,)
class datalog:
fd = 0
cur_timestamp = 0
time_marker = b'\x00'
starttime =0
timelength = 0
pos = 0
cur_bw = 0;
delaydata = []
bandwidth = []
def position(self):
return self.pos
def __init__(self, filename):
self.fd = open(filename, 'rb',buffering=2*18)
self.starttime = int.from_bytes(self.fd.read(8),byteorder='big')
print( filename + "started at "+ datetime.datetime.fromtimestamp(self.starttime/10).strftime('%Y-%m-%d %H:%M:%S'))
# self.timelength = int.frombytes(fd.read(4))
#self.timelength = 10000
self.cur_timestamp =self.starttime
self.delaydata = [0]
self.bandwidth = [0]
def __iter__(self):
return self
def __next__(self):
byte = self.fd.read(1);
while byte == self.time_marker:
self.cur_timestamp += 1
self.timelength += 1
self.bandwidth = self.bandwidth + [0]
self.bandwidth[self.cur_timestamp-self.starttime] = self.cur_bw
self.cur_bw = 0
self.set_datapoint_value(0)
byte = self.fd.read(1)
if byte == b'' :
raise StopIteration()
else:
self.pos+=1
self.cur_bw += 1
return byte
def next(self):
return self.__next__()
def peek(self):
#return self.fd.peek(1)
byte = self.fd.read(1)
if byte == '':
raise StopIteration()
self.fd.seek(-1,1)
return byte
def back(self):
self.pos-=1
self.fd.seek(-1,1)
def set_datapoint_value(self,val):
self.delaydata = self.delaydata + [0];
self.delaydata[self.cur_timestamp-self.starttime] = val
if __name__ == "__main__":
main()