-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.py
67 lines (58 loc) · 1.7 KB
/
demo.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 20 10:42:02 2019
@author: Macrobull
"""
from __future__ import absolute_import, division, unicode_literals
# import ysl.
from backends import tailc
from filters import thread_filter
from glog_parser import GlogParser, get_msg
from parsers import FrameParser, frame_parser
# setup source
proc = tailc('/tmp/demo.log')
glog_parser = GlogParser()
record_stream = glog_parser.process(proc.stdout)
# select one thread to parse
thread_id = None
while True:
if thread_id is None:
for record in record_stream:
match = FrameParser.REGEX.fullmatch(record.msg)
if match:
frame = FrameParser.make_frame(*match.groups())
if frame.name.startswith('Thread'):
thread_id = record.thread_id
break
else:
record_stream = thread_filter(record_stream, thread_id)
break
# plot data
import time
import matplotlib.pyplot as plt
plt.interactive(True)
ax = plt.subplot(title=f'Thread {thread_id}')
t1 = time.time()
series = dict()
msg_stream = get_msg(record_stream)
frame_stream = frame_parser(msg_stream)
for frame, document in frame_stream:
print(frame.index, document)
for key, value in document.items():
data = series.setdefault(key, [])
data.append(value)
series[key] = data[-100:]
t2 = time.time()
if t1 + 0.05 < t2:
ax.clear()
cnt = 0
for key, value in series.items():
ax.plot(value, label=key)
cnt += 1
if cnt >= 2:
break
ax.legend(loc='best')
t2 = time.time()
plt.pause(max(0.01, t1 + 0.1 - t2))
t1 = t2