pmonitor 1.4.7__tar.gz → 1.4.9__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.
Files changed (37) hide show
  1. {pmonitor-1.4.7 → pmonitor-1.4.9}/PKG-INFO +1 -1
  2. pmonitor-1.4.9/monitor/monitor_mac_vmmap.py +51 -0
  3. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/monitor_pids.py +17 -7
  4. {pmonitor-1.4.7 → pmonitor-1.4.9}/pmonitor.egg-info/PKG-INFO +1 -1
  5. {pmonitor-1.4.7 → pmonitor-1.4.9}/setup.py +1 -1
  6. pmonitor-1.4.7/monitor/monitor_mac_vmmap.py +0 -38
  7. {pmonitor-1.4.7 → pmonitor-1.4.9}/README.md +0 -0
  8. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/GpuMonitorLib.dll +0 -0
  9. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/KernelBase.dll +0 -0
  10. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/__init__.py +0 -0
  11. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/advapi32.dll +0 -0
  12. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/bcrypt.dll +0 -0
  13. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/kernel.appcore.dll +0 -0
  14. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/kernel32.dll +0 -0
  15. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/msvcirt.dll +0 -0
  16. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/msvcp140.dll +0 -0
  17. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/ntdll.dll +0 -0
  18. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/pdh.dll +0 -0
  19. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/rpcrt4.dll +0 -0
  20. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/sechost.dll +0 -0
  21. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/ucrtbased.dll +0 -0
  22. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/vcruntime140.dll +0 -0
  23. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/DLL/vcruntime140_1.dll +0 -0
  24. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/WinPidUtil.py +0 -0
  25. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/__init__.py +0 -0
  26. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/get_process_name.py +0 -0
  27. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/mac_gpu.py +0 -0
  28. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/monitor_mac.py +0 -0
  29. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/monitor_win.py +0 -0
  30. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/run_monitor.py +0 -0
  31. {pmonitor-1.4.7 → pmonitor-1.4.9}/monitor/sys_info.py +0 -0
  32. {pmonitor-1.4.7 → pmonitor-1.4.9}/pmonitor.egg-info/SOURCES.txt +0 -0
  33. {pmonitor-1.4.7 → pmonitor-1.4.9}/pmonitor.egg-info/dependency_links.txt +0 -0
  34. {pmonitor-1.4.7 → pmonitor-1.4.9}/pmonitor.egg-info/entry_points.txt +0 -0
  35. {pmonitor-1.4.7 → pmonitor-1.4.9}/pmonitor.egg-info/requires.txt +0 -0
  36. {pmonitor-1.4.7 → pmonitor-1.4.9}/pmonitor.egg-info/top_level.txt +0 -0
  37. {pmonitor-1.4.7 → pmonitor-1.4.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.2
2
2
  Name: pmonitor
3
- Version: 1.4.7
3
+ Version: 1.4.9
4
4
  Summary: pc monitor
5
5
  Home-page: UNKNOWN
6
6
  Author: cfr
@@ -0,0 +1,51 @@
1
+ import re
2
+ import asyncio
3
+
4
+
5
+ class VmMapMemory:
6
+ def __init__(self):
7
+ self.last_nonzero_memory = None
8
+
9
+ async def get_process_memory(self, pid):
10
+ cmd = ["top", "-l", "1", "-stats", "mem", "-pid", str(pid)]
11
+ try:
12
+ # 创建子进程并设置超时
13
+ proc = await asyncio.create_subprocess_exec(
14
+ *cmd,
15
+ stdout=asyncio.subprocess.PIPE,
16
+ stderr=asyncio.subprocess.DEVNULL
17
+ )
18
+
19
+ try:
20
+ stdout, _ = await asyncio.wait_for(proc.communicate(), timeout=1)
21
+ except asyncio.TimeoutError:
22
+ # 超时后确保子进程被终止
23
+ proc.kill()
24
+ await proc.wait()
25
+ raise
26
+
27
+ if proc.returncode == 0:
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
44
+ except Exception as e:
45
+ print(e)
46
+ finally:
47
+ if proc and proc.returncode is None:
48
+ proc.kill()
49
+ await proc.wait()
50
+ # 如果未能获取到有效值,返回上一次非零值或默认值 0.0
51
+ return self.last_nonzero_memory if self.last_nonzero_memory is not None else 0.0
@@ -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
- elapsed = time.time() - start_time
95
- remaining_time = max(0, self.interval / 1000 - elapsed)
96
- await asyncio.sleep(remaining_time)
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
- elapsed = time.time() - start_time
285
- time.sleep(max(0, self.interval - elapsed))
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':
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.2
2
2
  Name: pmonitor
3
- Version: 1.4.7
3
+ Version: 1.4.9
4
4
  Summary: pc monitor
5
5
  Home-page: UNKNOWN
6
6
  Author: cfr
@@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
5
5
  long_description = f.read()
6
6
 
7
7
  setup(name='pmonitor',
8
- version='1.4.7',
8
+ version='1.4.9',
9
9
  description='pc monitor',
10
10
  long_description=long_description,
11
11
  author='cfr',
@@ -1,38 +0,0 @@
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes