pmonitor 1.4.5__tar.gz → 1.4.7__tar.gz
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.
- {pmonitor-1.4.5 → pmonitor-1.4.7}/PKG-INFO +1 -1
- pmonitor-1.4.7/monitor/monitor_mac_vmmap.py +38 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/monitor_pids.py +16 -6
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/run_monitor.py +1 -1
- {pmonitor-1.4.5 → pmonitor-1.4.7}/pmonitor.egg-info/PKG-INFO +1 -1
- {pmonitor-1.4.5 → pmonitor-1.4.7}/pmonitor.egg-info/SOURCES.txt +1 -2
- {pmonitor-1.4.5 → pmonitor-1.4.7}/setup.py +1 -1
- pmonitor-1.4.5/monitor/exec/GpuMonitor +0 -0
- pmonitor-1.4.5/monitor/exec/__init__.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/README.md +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/GpuMonitorLib.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/KernelBase.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/__init__.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/advapi32.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/bcrypt.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/kernel.appcore.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/kernel32.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/msvcirt.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/msvcp140.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/ntdll.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/pdh.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/rpcrt4.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/sechost.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/ucrtbased.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/vcruntime140.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/DLL/vcruntime140_1.dll +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/WinPidUtil.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/__init__.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/get_process_name.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/mac_gpu.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/monitor_mac.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/monitor_win.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/monitor/sys_info.py +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/pmonitor.egg-info/dependency_links.txt +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/pmonitor.egg-info/entry_points.txt +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/pmonitor.egg-info/requires.txt +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/pmonitor.egg-info/top_level.txt +0 -0
- {pmonitor-1.4.5 → pmonitor-1.4.7}/setup.cfg +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import asyncio
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class VmMapMemory:
|
|
6
|
+
async def get_process_memory(self, pid):
|
|
7
|
+
cmd = ["vmmap", "--summary", str(pid)]
|
|
8
|
+
proc = None
|
|
9
|
+
try:
|
|
10
|
+
# 创建子进程并设置超时
|
|
11
|
+
proc = await asyncio.create_subprocess_exec(
|
|
12
|
+
*cmd,
|
|
13
|
+
stdout=asyncio.subprocess.PIPE,
|
|
14
|
+
stderr=asyncio.subprocess.DEVNULL
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
stdout, _ = await asyncio.wait_for(proc.communicate(), timeout=5)
|
|
19
|
+
except asyncio.TimeoutError:
|
|
20
|
+
# 超时后确保子进程被终止
|
|
21
|
+
proc.kill()
|
|
22
|
+
await proc.wait()
|
|
23
|
+
raise
|
|
24
|
+
|
|
25
|
+
if proc.returncode == 0:
|
|
26
|
+
match = re.search(r'Physical footprint:\s+([\d.]+)([GMK]?)', stdout.decode())
|
|
27
|
+
if match:
|
|
28
|
+
val, unit = float(match.group(1)), match.group(2)
|
|
29
|
+
return val * {
|
|
30
|
+
'G': 1024, 'M': 1, 'K': 1 / 1024, '': 1 / (1024 * 1024)
|
|
31
|
+
}.get(unit, 1)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
print(e)
|
|
34
|
+
finally:
|
|
35
|
+
if proc and proc.returncode is None:
|
|
36
|
+
proc.kill()
|
|
37
|
+
await proc.wait()
|
|
38
|
+
return 0.0
|
|
@@ -9,6 +9,8 @@ import ctypes
|
|
|
9
9
|
import os
|
|
10
10
|
from PyLibreHardwareMonitor.computer import Computer
|
|
11
11
|
|
|
12
|
+
from monitor.monitor_mac_vmmap import VmMapMemory
|
|
13
|
+
|
|
12
14
|
if platform.system() != 'Windows':
|
|
13
15
|
from monitor.mac_gpu import get_gpu_memory
|
|
14
16
|
|
|
@@ -20,9 +22,11 @@ class PidsPerf:
|
|
|
20
22
|
self.interval = interval
|
|
21
23
|
self.processUtil = ProcessName()
|
|
22
24
|
|
|
23
|
-
def get_mac_perf(self):
|
|
25
|
+
async def get_mac_perf(self):
|
|
24
26
|
current_pid = self.processUtil.find_main_process_pid(self.process_name)
|
|
27
|
+
vm = VmMapMemory()
|
|
25
28
|
while True:
|
|
29
|
+
start_time = time.time() # 记录循环开始时间
|
|
26
30
|
minor_cpu_sum = 0
|
|
27
31
|
minor_real_mem_sum = 0
|
|
28
32
|
minor_mem_percent_sum = 0
|
|
@@ -39,12 +43,14 @@ class PidsPerf:
|
|
|
39
43
|
mem_available = round(mem_info.available / 1024 / 1024, 2) # 剩余虚拟内存
|
|
40
44
|
|
|
41
45
|
gpu_memory_usage, gpu_memory_total, gpu_memory_free = get_gpu_memory()
|
|
42
|
-
|
|
46
|
+
# 使用 asyncio.gather 并发获取内存数据
|
|
47
|
+
memory_tasks = [vm.get_process_memory(process.pid) for process in pids_process]
|
|
48
|
+
memory_results = await asyncio.gather(*memory_tasks, return_exceptions=True)
|
|
49
|
+
for idx, process in enumerate(pids_process):
|
|
43
50
|
try:
|
|
44
51
|
cpu_percent = process.cpu_percent()
|
|
45
|
-
process_memory = process.memory_info()
|
|
46
52
|
mem_percent = u'%.2f' % (process.memory_percent()) # 内存利用率
|
|
47
|
-
real_mem =
|
|
53
|
+
real_mem = memory_results[idx] # 实际内存
|
|
48
54
|
thread_count = process.num_threads() # 线程总数
|
|
49
55
|
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
|
50
56
|
cpu_percent = 0
|
|
@@ -74,7 +80,7 @@ class PidsPerf:
|
|
|
74
80
|
# minor_thread_count_sum)
|
|
75
81
|
# 获取磁盘IO
|
|
76
82
|
io_read_bytes_start, io_write_bytes_start = self.get_disk_usage()
|
|
77
|
-
time.sleep(
|
|
83
|
+
time.sleep(0.1) # 采集间隔
|
|
78
84
|
io_read_bytes_end, io_write_bytes_end = self.get_disk_usage() # io read/write
|
|
79
85
|
io_read_bytes = io_read_bytes_end - io_read_bytes_start # io read/byte
|
|
80
86
|
io_write_bytes = io_write_bytes_end - io_write_bytes_start # io write/byte
|
|
@@ -85,6 +91,9 @@ class PidsPerf:
|
|
|
85
91
|
"memory_total": mem_total, "memory_available": mem_available}
|
|
86
92
|
json_data = json.dumps(data)
|
|
87
93
|
print(json_data)
|
|
94
|
+
elapsed = time.time() - start_time
|
|
95
|
+
remaining_time = max(0, self.interval / 1000 - elapsed)
|
|
96
|
+
await asyncio.sleep(remaining_time)
|
|
88
97
|
sys.stdout.flush()
|
|
89
98
|
|
|
90
99
|
def get_disk_usage(self):
|
|
@@ -210,6 +219,7 @@ class PidsPerf:
|
|
|
210
219
|
# 'Committed:', main_gpu_committed_sum, 'GPU Usage:',
|
|
211
220
|
# main_gpu_percent_sum)
|
|
212
221
|
main_data = {'cpu': cpu_usage, 'private': private_mem, "workset": workSet_mem,
|
|
222
|
+
'thread count': thread_count,
|
|
213
223
|
'gpu_Dedicated': round(float(main_gpu_dedicated_sum), 2),
|
|
214
224
|
'gpu_System': round(float(main_gpu_system_sum), 2),
|
|
215
225
|
'gpu_Committed': round(float(main_gpu_committed_sum), 2),
|
|
@@ -244,7 +254,7 @@ class PidsPerf:
|
|
|
244
254
|
disk_data = {'io read': minor_io_read_sum, 'io write': minor_io_write_sum}
|
|
245
255
|
other_data = {'cpu': minor_cpu_sum, 'private': round(float(minor_private_mem_sum), 2),
|
|
246
256
|
'workset': round(float(minor_workSet_mem_sum), 2),
|
|
247
|
-
'memory percent': round(float(minor_mem_percent_sum), 2),
|
|
257
|
+
# 'memory percent': round(float(minor_mem_percent_sum), 2),
|
|
248
258
|
'thread count': minor_thread_count_sum,
|
|
249
259
|
'gpu_Dedicated': round(minor_gpu_dedicated_sum, 2),
|
|
250
260
|
'gpu_System': round(minor_gpu_system_sum, 2),
|
|
@@ -5,6 +5,7 @@ monitor/__init__.py
|
|
|
5
5
|
monitor/get_process_name.py
|
|
6
6
|
monitor/mac_gpu.py
|
|
7
7
|
monitor/monitor_mac.py
|
|
8
|
+
monitor/monitor_mac_vmmap.py
|
|
8
9
|
monitor/monitor_pids.py
|
|
9
10
|
monitor/monitor_win.py
|
|
10
11
|
monitor/run_monitor.py
|
|
@@ -25,8 +26,6 @@ monitor/DLL/sechost.dll
|
|
|
25
26
|
monitor/DLL/ucrtbased.dll
|
|
26
27
|
monitor/DLL/vcruntime140.dll
|
|
27
28
|
monitor/DLL/vcruntime140_1.dll
|
|
28
|
-
monitor/exec/GpuMonitor
|
|
29
|
-
monitor/exec/__init__.py
|
|
30
29
|
pmonitor.egg-info/PKG-INFO
|
|
31
30
|
pmonitor.egg-info/SOURCES.txt
|
|
32
31
|
pmonitor.egg-info/dependency_links.txt
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|