pmonitor 1.4.7__py3-none-any.whl → 1.4.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- monitor/monitor_mac_vmmap.py +23 -10
- monitor/monitor_pids.py +17 -7
- {pmonitor-1.4.7.dist-info → pmonitor-1.4.9.dist-info}/METADATA +1 -1
- {pmonitor-1.4.7.dist-info → pmonitor-1.4.9.dist-info}/RECORD +7 -7
- {pmonitor-1.4.7.dist-info → pmonitor-1.4.9.dist-info}/WHEEL +0 -0
- {pmonitor-1.4.7.dist-info → pmonitor-1.4.9.dist-info}/entry_points.txt +0 -0
- {pmonitor-1.4.7.dist-info → pmonitor-1.4.9.dist-info}/top_level.txt +0 -0
monitor/monitor_mac_vmmap.py
CHANGED
|
@@ -3,9 +3,11 @@ import asyncio
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
class VmMapMemory:
|
|
6
|
+
def __init__(self):
|
|
7
|
+
self.last_nonzero_memory = None
|
|
8
|
+
|
|
6
9
|
async def get_process_memory(self, pid):
|
|
7
|
-
cmd = ["
|
|
8
|
-
proc = None
|
|
10
|
+
cmd = ["top", "-l", "1", "-stats", "mem", "-pid", str(pid)]
|
|
9
11
|
try:
|
|
10
12
|
# 创建子进程并设置超时
|
|
11
13
|
proc = await asyncio.create_subprocess_exec(
|
|
@@ -15,7 +17,7 @@ class VmMapMemory:
|
|
|
15
17
|
)
|
|
16
18
|
|
|
17
19
|
try:
|
|
18
|
-
stdout, _ = await asyncio.wait_for(proc.communicate(), timeout=
|
|
20
|
+
stdout, _ = await asyncio.wait_for(proc.communicate(), timeout=1)
|
|
19
21
|
except asyncio.TimeoutError:
|
|
20
22
|
# 超时后确保子进程被终止
|
|
21
23
|
proc.kill()
|
|
@@ -23,16 +25,27 @@ class VmMapMemory:
|
|
|
23
25
|
raise
|
|
24
26
|
|
|
25
27
|
if proc.returncode == 0:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
# 解析 top 输出中的内存信息
|
|
29
|
+
lines = stdout.decode().strip().split('\n')
|
|
30
|
+
if lines:
|
|
31
|
+
last_line = lines[-1].strip() # 获取最后一行
|
|
32
|
+
match = re.match(r'^([\d.]+)([GMK]?)$', last_line)
|
|
33
|
+
|
|
34
|
+
if match:
|
|
35
|
+
val, unit = float(match.group(1)), match.group(2)
|
|
36
|
+
memory_value = val * {
|
|
37
|
+
'G': 1024, 'M': 1, 'K': 1 / 1024, '': 1 / (1024 * 1024)
|
|
38
|
+
}.get(unit, 1)
|
|
39
|
+
|
|
40
|
+
if memory_value > 0:
|
|
41
|
+
self.last_nonzero_memory = memory_value
|
|
42
|
+
# 返回当前值或上一次非零值
|
|
43
|
+
return memory_value if memory_value != 0 else self.last_nonzero_memory
|
|
32
44
|
except Exception as e:
|
|
33
45
|
print(e)
|
|
34
46
|
finally:
|
|
35
47
|
if proc and proc.returncode is None:
|
|
36
48
|
proc.kill()
|
|
37
49
|
await proc.wait()
|
|
38
|
-
|
|
50
|
+
# 如果未能获取到有效值,返回上一次非零值或默认值 0.0
|
|
51
|
+
return self.last_nonzero_memory if self.last_nonzero_memory is not None else 0.0
|
monitor/monitor_pids.py
CHANGED
|
@@ -25,6 +25,7 @@ class PidsPerf:
|
|
|
25
25
|
async def get_mac_perf(self):
|
|
26
26
|
current_pid = self.processUtil.find_main_process_pid(self.process_name)
|
|
27
27
|
vm = VmMapMemory()
|
|
28
|
+
next_time = time.time() # 初始化下一次执行的时间点
|
|
28
29
|
while True:
|
|
29
30
|
start_time = time.time() # 记录循环开始时间
|
|
30
31
|
minor_cpu_sum = 0
|
|
@@ -80,7 +81,7 @@ class PidsPerf:
|
|
|
80
81
|
# minor_thread_count_sum)
|
|
81
82
|
# 获取磁盘IO
|
|
82
83
|
io_read_bytes_start, io_write_bytes_start = self.get_disk_usage()
|
|
83
|
-
time.sleep(0.1)
|
|
84
|
+
time.sleep(0.1)
|
|
84
85
|
io_read_bytes_end, io_write_bytes_end = self.get_disk_usage() # io read/write
|
|
85
86
|
io_read_bytes = io_read_bytes_end - io_read_bytes_start # io read/byte
|
|
86
87
|
io_write_bytes = io_write_bytes_end - io_write_bytes_start # io write/byte
|
|
@@ -91,9 +92,13 @@ class PidsPerf:
|
|
|
91
92
|
"memory_total": mem_total, "memory_available": mem_available}
|
|
92
93
|
json_data = json.dumps(data)
|
|
93
94
|
print(json_data)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
# 精确控制间隔
|
|
96
|
+
next_time += self.interval
|
|
97
|
+
sleep_time = next_time - time.time()
|
|
98
|
+
if sleep_time > 0:
|
|
99
|
+
await asyncio.sleep(sleep_time)
|
|
100
|
+
else:
|
|
101
|
+
next_time = time.time() # 如果超时,重置时间点
|
|
97
102
|
sys.stdout.flush()
|
|
98
103
|
|
|
99
104
|
def get_disk_usage(self):
|
|
@@ -129,6 +134,7 @@ class PidsPerf:
|
|
|
129
134
|
# 获取GPU物理内存
|
|
130
135
|
computer = Computer()
|
|
131
136
|
gpu_key = list(computer.gpu.keys())[0]
|
|
137
|
+
next_time = time.time() # 初始化下一次执行的时间点
|
|
132
138
|
while True:
|
|
133
139
|
minor_cpu_sum = 0
|
|
134
140
|
minor_workSet_mem_sum = 0
|
|
@@ -280,9 +286,13 @@ class PidsPerf:
|
|
|
280
286
|
sys.stdout.flush()
|
|
281
287
|
# 更新系统时间
|
|
282
288
|
system_time_pre = system_time_post
|
|
283
|
-
#
|
|
284
|
-
|
|
285
|
-
|
|
289
|
+
# 精确控制间隔
|
|
290
|
+
next_time += self.interval
|
|
291
|
+
sleep_time = next_time - time.time()
|
|
292
|
+
if sleep_time > 0:
|
|
293
|
+
time.sleep(sleep_time)
|
|
294
|
+
else:
|
|
295
|
+
next_time = time.time() # 如果超时,重置时间点v
|
|
286
296
|
|
|
287
297
|
async def start_perf(self):
|
|
288
298
|
if platform.system() == 'Windows':
|
|
@@ -3,8 +3,8 @@ monitor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
3
3
|
monitor/get_process_name.py,sha256=HxePo2gdrTo2Ukg4DTnYzUMdczVWywCeLCXQ-RRWyu8,3913
|
|
4
4
|
monitor/mac_gpu.py,sha256=kQDPMW04lIYPBbJw772Jh1OQxj-D4JNmdjJlP6BuR4w,2320
|
|
5
5
|
monitor/monitor_mac.py,sha256=OoptTTXTZQupzBwgGOfKNjyYAKBxDy-wI3l6T7XVE8s,4651
|
|
6
|
-
monitor/monitor_mac_vmmap.py,sha256=
|
|
7
|
-
monitor/monitor_pids.py,sha256=
|
|
6
|
+
monitor/monitor_mac_vmmap.py,sha256=Lu1AAw6auuZzuNZtASOaNBpRPOOgyzGr1jYSTErmRmo,1971
|
|
7
|
+
monitor/monitor_pids.py,sha256=Q0YDPguEhuegQF6PNk7_xm_DK3e_02FNPfhj31UFS8o,16915
|
|
8
8
|
monitor/monitor_win.py,sha256=xs5nzqqEPoDmJTegh3lQhVjjpPcOWnruWKK65ttqnTo,6161
|
|
9
9
|
monitor/run_monitor.py,sha256=HDQXHIx47ZRN4Gp0PTr0yWKVM28n8A7-NaO--_pdgso,1577
|
|
10
10
|
monitor/sys_info.py,sha256=aNultuRoQuRYPkYo397xAXVDXP07Qx5JOHtYzNmEvuc,3208
|
|
@@ -24,8 +24,8 @@ monitor/DLL/sechost.dll,sha256=1mXCrgNDRBiZ2XZk7eTpDm4oPG-x9BW4uYUVkrfvBkk,69986
|
|
|
24
24
|
monitor/DLL/ucrtbased.dll,sha256=vtmKFPEHyr2OXkrUOu3Qs1dlbKG1dxZ8ItKCkTTU5S4,2238056
|
|
25
25
|
monitor/DLL/vcruntime140.dll,sha256=AsaqDm5iRBGp8ZsDYKeGWrFZCOJgJFEOXDipwINiw1o,119888
|
|
26
26
|
monitor/DLL/vcruntime140_1.dll,sha256=fdmqAuJxxoym1fGNZR0joV1yWXFa9DMmV4993ifzdjc,49640
|
|
27
|
-
pmonitor-1.4.
|
|
28
|
-
pmonitor-1.4.
|
|
29
|
-
pmonitor-1.4.
|
|
30
|
-
pmonitor-1.4.
|
|
31
|
-
pmonitor-1.4.
|
|
27
|
+
pmonitor-1.4.9.dist-info/METADATA,sha256=S_4kV_H2DEDAC-by_50e6NwsHyJkM77D7Ga-sfrOWUE,291
|
|
28
|
+
pmonitor-1.4.9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
29
|
+
pmonitor-1.4.9.dist-info/entry_points.txt,sha256=vmlLEANgf2fZar9BeXYiKdF6GMJbVXip-SIZx5yPXDo,55
|
|
30
|
+
pmonitor-1.4.9.dist-info/top_level.txt,sha256=tGkQDkVeyKgP5Rr7acpp0df83NBAnI8up0sGwRxuuQ4,8
|
|
31
|
+
pmonitor-1.4.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|