pmonitor 1.4.7__py3-none-any.whl → 1.4.8__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.
@@ -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 = ["vmmap", "--summary", str(pid)]
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=5)
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
- 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)
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
- return 0.0
50
+ # 如果未能获取到有效值,返回上一次非零值或默认值 0.0
51
+ return self.last_nonzero_memory if self.last_nonzero_memory is not None else 0.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pmonitor
3
- Version: 1.4.7
3
+ Version: 1.4.8
4
4
  Summary: pc monitor
5
5
  Home-page: UNKNOWN
6
6
  Author: cfr
@@ -3,7 +3,7 @@ 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=t-qB5i8b_OKapu21F8LwrxH35FeoCovSsfpGNVYVkWo,1261
6
+ monitor/monitor_mac_vmmap.py,sha256=Lu1AAw6auuZzuNZtASOaNBpRPOOgyzGr1jYSTErmRmo,1971
7
7
  monitor/monitor_pids.py,sha256=1Bmemd-cf1NkrcCbKwOg-56fDgxSGLXam-EGmr_5AWU,16531
8
8
  monitor/monitor_win.py,sha256=xs5nzqqEPoDmJTegh3lQhVjjpPcOWnruWKK65ttqnTo,6161
9
9
  monitor/run_monitor.py,sha256=HDQXHIx47ZRN4Gp0PTr0yWKVM28n8A7-NaO--_pdgso,1577
@@ -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.7.dist-info/METADATA,sha256=OoCVnvaCS5oN5QM8vPHAxlRAgG25-6xrwKqe_ehmS7A,291
28
- pmonitor-1.4.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
29
- pmonitor-1.4.7.dist-info/entry_points.txt,sha256=vmlLEANgf2fZar9BeXYiKdF6GMJbVXip-SIZx5yPXDo,55
30
- pmonitor-1.4.7.dist-info/top_level.txt,sha256=tGkQDkVeyKgP5Rr7acpp0df83NBAnI8up0sGwRxuuQ4,8
31
- pmonitor-1.4.7.dist-info/RECORD,,
27
+ pmonitor-1.4.8.dist-info/METADATA,sha256=cHkAUgHDu0voEx1JNF_q1qbPo7YGVzlt6_h4J53KZRs,291
28
+ pmonitor-1.4.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
29
+ pmonitor-1.4.8.dist-info/entry_points.txt,sha256=vmlLEANgf2fZar9BeXYiKdF6GMJbVXip-SIZx5yPXDo,55
30
+ pmonitor-1.4.8.dist-info/top_level.txt,sha256=tGkQDkVeyKgP5Rr7acpp0df83NBAnI8up0sGwRxuuQ4,8
31
+ pmonitor-1.4.8.dist-info/RECORD,,