-
Notifications
You must be signed in to change notification settings - Fork 0
/
M_Performance_monitor.py
102 lines (73 loc) · 2.27 KB
/
M_Performance_monitor.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
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
##############################
# import
##############################
import wx
import wx.lib.plot as plot
import psutil
import GUI_Performance_monitor
##############################
# GUI的函数桥接
##############################
class CalcFrame(GUI_Performance_monitor.Main):
def __init__(self, parent):
# 定义主函数
GUI_Performance_monitor.Main.__init__(self, parent)
global plotter_CPU, plotter_RAM, data_CPU, data_RAM
data_CPU = []
data_RAM = []
plotter_CPU = plot.PlotCanvas(self)
plotter_CPU.SetInitialSize(size=(500, 210))
plotter_CPU.SetEnableAntiAliasing(True)
plotter_RAM = plot.PlotCanvas(self)
plotter_RAM.SetInitialSize(size=(500, 210))
plotter_RAM.SetEnableAntiAliasing(True)
plotter_RAM.Move(0,220)
def PFM_Tick(self, event):
""" 计时器-性能监视器 """
Line1 = psutil.swap_memory()
Line2 = psutil.cpu_times_percent()
CPU_text = str(Line2.user) + "%" # 合并字符串
RAM_text = str(Line1.percent) + "%"
CPU_int = Line2.user
RAM_int = Line1.percent
global data_CPU, data_RAM
if len(data_CPU) < 10: # CPU数据处理
data_CPU.append([len(data_CPU) + 1,CPU_int])
else:
del data_CPU[0]
data_cacheMiX = []
for i in range(0, len(data_CPU)):
data_cache = data_CPU[i]
data_cache = data_cache[1]
data_cacheMiX.append([i + 1, data_cache])
data_CPU = data_cacheMiX
data_CPU.append([len(data_CPU) + 1,CPU_int])
if len(data_RAM) < 10: # RAM数据处理
data_RAM.append([len(data_RAM) + 1,RAM_int])
else:
del data_RAM[0]
data_cacheMiX = []
for i in range(0, len(data_RAM)):
data_cache = data_RAM[i]
data_cache = data_cache[1]
data_cacheMiX.append([i + 1, data_cache])
data_RAM = data_cacheMiX
data_RAM.append([len(data_RAM) + 1,RAM_int])
line_CPU = plot.PolyLine(data_CPU, colour='red', width=2)
line_RAM = plot.PolyLine(data_RAM, colour='blue', width=2)
gc= plot.PlotGraphics([line_CPU], 'CPU', 'time', '')
plotter_CPU.Draw(gc)
gc= plot.PlotGraphics([line_RAM], 'RAM', 'time', '')
plotter_RAM.Draw(gc)
def Close(self, event):
self.Destroy()
##############################
# 主函数
##############################
def main():
app = wx.App(False)
frame = CalcFrame(None)
frame.Show(True)
app.MainLoop()
if __name__ == "__main__":
main()