forked from sshi27/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_reader.py
74 lines (59 loc) · 1.91 KB
/
log_reader.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
import re, json
class LogReader:
def __init__(self, path="./output.txt"):
self.path = path
def getLines(self):
stack = [""]
data = []
f = open(self.path, "r")
for line in f.readlines():
line = re.sub("^[ |]+", "", line)
if line.startswith("->"): # counter
tmp = re.split("[\[\]]", line)
data.append(stack[-1] + " " + tmp[1] + ": " + float(tmp[4].strip()))
else:
name = re.split("[\[\]]", line)[1]
if line.startswith('+'):
stack.append(stack[-1] + " " + name)
elif line.startswith('-'):
us = line[line.rfind(" ") + 1: -3]
us = int(us)
data.append(stack[-1] + ": " + us)
stack.pop()
f.close()
return data
def getData(self):
stack = []
data = None
f = open(self.path, "r")
for line in f.readlines():
line = re.sub("^[ |]+", "", line)
if line.startswith("->"):
tmp = re.split("[\[\]]", line)
counter = {
"l1": tmp[1],
"count": float(tmp[4].strip())
}
try:
counter["l2"] = tmp[3]
except:
pass
stack[-1]["counters"].append(counter)
else:
name = re.split("[\[\]]", line)[1]
if line.startswith('+'):
new = {"name": name, "time": -1, "children": [], "counters": []}
if len(stack):
stack[-1]["children"].append(new)
stack.append(new)
elif line.startswith('-'):
us = line[line.rfind(" ") + 1: -3]
us = int(us)
stack[-1]["time"] = us
if len(stack[-1]["counters"]) == 0:
del stack[-1]["counters"]
if len(stack[-1]["children"]) == 0:
del stack[-1]["children"]
data = stack.pop()
f.close()
return data