-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.py
42 lines (33 loc) · 1.3 KB
/
analyze.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
import os
from encoding.decode import decode
# Get the directory of the current script
current_dir = os.path.dirname(os.path.abspath(__file__))
# Default file name
DUMP_FILE_PATH = "data/mempool_drop.txt"
print("Line {} has length {}".format(line[0], len(line[1])))
if input("See line content? (y/n)") == "y":
decoded = decode(line[1])
deserialized = decoded.deserialize()
print("Deserialized: {}".format(deserialized))
if __name__ == "__main__":
print("Analyzing dump file: {}".format(DUMP_FILE_PATH))
# open file
file = open(DUMP_FILE_PATH, "r")
# read file
lines = list(enumerate([line.strip() for line in file.readlines()]))
print("Read {} lines".format(len(lines)))
# sort lines by length
lines.sort(key=lambda x: len(x[1]), reverse=True)
# print longest line lengths
print("Longest lines:")
for i in range(10):
line_number, line = lines[i]
print("Line {} has length {}".format(line_number, len(line)))
decoded = decode(line)
deserialized = decoded.deserialize()
print(deserialized, file=open(
f"line_{line_number}_deserialized.txt", "w"))
input("Press any key to see next line...")
for line in lines:
process_line(line)
input("Press any key to see next line...")