-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdrawspeed.py
62 lines (52 loc) · 1.83 KB
/
drawspeed.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
'''
author: Michael liu ([email protected])
new thread, draw network speed
'''
import threading, os
import matplotlib.pyplot as plt
from testspeed import realtime_q
from mininet.log import info
shut_down_draw = False
def get_shut_down_draw():
global shut_down_draw
return shut_down_draw
def change_shut_down_draw():
global shut_down_draw
shut_down_draw = not shut_down_draw
class Drawspeed(threading.Thread):
def __init__(self, thread_name, imagename):
threading.Thread.__init__(self, name=thread_name)
self.imagename = imagename
def draw_realtime_speed(self):
realtime_q_draw_x = []
realtime_q_draw_y = []
info('draw_realtime_speed start\n')
global shut_down_draw
image_count = 0
plt.ion()
# ax = plt.gca()
# ax.spines['bottom'].set_position(('data', 0))
# ax.spines['left'].set_position(('data', 0))
while not shut_down_draw:
if not realtime_q.empty():
[t, s] = realtime_q.get(block=True)
realtime_q_draw_x.append(t)
realtime_q_draw_y.append(s)
plt.xlabel('time(seconds)')
plt.ylabel('realtime speed(Kbps)')
plt.plot(realtime_q_draw_x, realtime_q_draw_y, 'r')
plt.pause(0.05)
#almost 10min refresh figure and save image
if len(realtime_q_draw_y)>600 and len(realtime_q_draw_x)>600:
realtime_q_draw_x = []
realtime_q_draw_y = []
image_count += 1
plt.grid()
plt.savefig(self.imagename+str(image_count)+'.png')
# plt.show()
plt.grid()
plt.savefig(self.imagename+str(image_count)+'.png')
plt.close()
def run(self):
info('%s start\n' % self.getName())
self.draw_realtime_speed()