pmonitor 1.5.5__py3-none-any.whl → 1.5.7__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.
Binary file
monitor/monitor_pids.py CHANGED
@@ -1,4 +1,3 @@
1
- import psutil
2
1
  import time
3
2
  import json
4
3
  from monitor.get_process_name import *
@@ -7,7 +6,7 @@ import asyncio
7
6
  import platform
8
7
  import ctypes
9
8
  import os
10
- from PyLibreHardwareMonitor.computer import Computer
9
+ from monitor.monitor_mac_vmmap import VmMapMemory
11
10
 
12
11
  if platform.system() != 'Windows':
13
12
  from monitor.mac_gpu import get_gpu_memory
@@ -20,9 +19,13 @@ class PidsPerf:
20
19
  self.interval = interval
21
20
  self.processUtil = ProcessName()
22
21
 
23
- def get_mac_perf(self):
22
+ async def get_mac_perf(self):
24
23
  current_pid = self.processUtil.find_main_process_pid(self.process_name)
24
+ vm = VmMapMemory()
25
+ next_time = time.time() # 初始化下一次执行的时间点
26
+ first_iteration = True # 标志变量,用于跳过第一次循环
25
27
  while True:
28
+ start_time = time.time() # 记录循环开始时间
26
29
  minor_cpu_sum = 0
27
30
  minor_real_mem_sum = 0
28
31
  minor_mem_percent_sum = 0
@@ -40,12 +43,21 @@ class PidsPerf:
40
43
  mem_available = round(mem_info.available / 1024 / 1024, 2) # 剩余虚拟内存
41
44
 
42
45
  gpu_memory_usage, gpu_memory_total, gpu_memory_free = get_gpu_memory()
46
+ # 使用 asyncio.gather 并发获取内存数据
47
+ vm.update_pids(current_pids)
48
+
49
+ if first_iteration:
50
+ first_iteration = False # 第一次循环后将标志置为 False
51
+ await asyncio.sleep(self.interval / 1000) # 等待一段时间以确保数据稳定
52
+ continue # 跳过第一次循环
53
+
43
54
  for process in pids_process:
44
55
  try:
45
56
  cpu_percent = process.cpu_percent()
46
57
  process_memory = process.memory_info()
47
58
  mem_percent = u'%.2f' % (process.memory_percent()) # 内存利用率
48
- real_mem = round(process_memory.rss / 1024 / 1024, 2) # 实际内存
59
+ vm_memory_data = json.loads(vm.get_current_json())
60
+ real_mem = vm_memory_data.get(str(process.pid), 0) # 默认值为 0(如果未找到对应 PID)
49
61
  vss_mem = round(process_memory.vms / 1024 / 1024, 2) # 虚拟内存
50
62
  thread_count = process.num_threads() # 线程总数
51
63
  except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
@@ -79,7 +91,7 @@ class PidsPerf:
79
91
  # minor_thread_count_sum)
80
92
  # 获取磁盘IO
81
93
  io_read_bytes_start, io_write_bytes_start = self.get_disk_usage()
82
- time.sleep(self.interval)
94
+ time.sleep(0.1)
83
95
  io_read_bytes_end, io_write_bytes_end = self.get_disk_usage() # io read/write
84
96
  io_read_bytes = io_read_bytes_end - io_read_bytes_start # io read/byte
85
97
  io_write_bytes = io_write_bytes_end - io_write_bytes_start # io write/byte
@@ -90,6 +102,13 @@ class PidsPerf:
90
102
  "memory_total": mem_total, "memory_available": mem_available}
91
103
  json_data = json.dumps(data)
92
104
  print(json_data)
105
+ # 精确控制间隔
106
+ next_time += self.interval
107
+ sleep_time = next_time - time.time()
108
+ if sleep_time > 0:
109
+ await asyncio.sleep(sleep_time)
110
+ else:
111
+ next_time = time.time() # 如果超时,重置时间点
93
112
  sys.stdout.flush()
94
113
 
95
114
  def get_disk_usage(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pmonitor
3
- Version: 1.5.5
3
+ Version: 1.5.7
4
4
  Summary: pc monitor
5
5
  Author: cfr
6
6
  Author-email: 1354592998@qq.com
@@ -4,11 +4,11 @@ monitor/get_process_name.py,sha256=HxePo2gdrTo2Ukg4DTnYzUMdczVWywCeLCXQ-RRWyu8,3
4
4
  monitor/mac_gpu.py,sha256=kQDPMW04lIYPBbJw772Jh1OQxj-D4JNmdjJlP6BuR4w,2320
5
5
  monitor/monitor_mac.py,sha256=OoptTTXTZQupzBwgGOfKNjyYAKBxDy-wI3l6T7XVE8s,4651
6
6
  monitor/monitor_mac_vmmap.py,sha256=2ZLhig5ymY6XU7bZGnHM9VIK-d5DAqWOFItIfv7KDPE,3819
7
- monitor/monitor_pids.py,sha256=VqgN4puRMDXzNukiHVrZp-gsYKswUiFkuvhPRo56sII,16772
7
+ monitor/monitor_pids.py,sha256=kqMOsYVqkrB6uh0LoifvO3w0bBmpUH7XrLw0tSmTFdk,17755
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
11
- monitor/DLL/GpuMonitorLib.dll,sha256=t1Y4h7Hoxz2s9Ziiofrp7xgfpuQiMafxnRVW0TcmmuY,68608
11
+ monitor/DLL/GpuMonitorLib.dll,sha256=V4nPPvQ0JRVKFdhpIL7Q5da8-KpbThqr7WIMxMKxrKU,66560
12
12
  monitor/DLL/KernelBase.dll,sha256=MSJ2WSh-2Lk6yFVLX_a8G2EnNuaOtJGpfg-Vw9HY_go,3860744
13
13
  monitor/DLL/LibreHardwareMonitorLib.dll,sha256=XSzcprSY4xSH3i5DhngO6mYtVmC3GJvu9-0X9UKwPbU,790528
14
14
  monitor/DLL/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -25,8 +25,8 @@ monitor/DLL/sechost.dll,sha256=1mXCrgNDRBiZ2XZk7eTpDm4oPG-x9BW4uYUVkrfvBkk,69986
25
25
  monitor/DLL/ucrtbased.dll,sha256=vtmKFPEHyr2OXkrUOu3Qs1dlbKG1dxZ8ItKCkTTU5S4,2238056
26
26
  monitor/DLL/vcruntime140.dll,sha256=AsaqDm5iRBGp8ZsDYKeGWrFZCOJgJFEOXDipwINiw1o,119888
27
27
  monitor/DLL/vcruntime140_1.dll,sha256=fdmqAuJxxoym1fGNZR0joV1yWXFa9DMmV4993ifzdjc,49640
28
- pmonitor-1.5.5.dist-info/METADATA,sha256=n_TzAaS9o3NXsebViiGZE6UgmFOAOcjMjrb3ZjWhot0,427
29
- pmonitor-1.5.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
30
- pmonitor-1.5.5.dist-info/entry_points.txt,sha256=RiT4cQ3f8vsU3HSGbQrMROCHMi7eOFzdh-k0g7TzoFE,54
31
- pmonitor-1.5.5.dist-info/top_level.txt,sha256=tGkQDkVeyKgP5Rr7acpp0df83NBAnI8up0sGwRxuuQ4,8
32
- pmonitor-1.5.5.dist-info/RECORD,,
28
+ pmonitor-1.5.7.dist-info/METADATA,sha256=iih0wvjnWstOzhRqT8XZU1kFU_5uKiT0BnFnlZbD9N4,427
29
+ pmonitor-1.5.7.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
30
+ pmonitor-1.5.7.dist-info/entry_points.txt,sha256=RiT4cQ3f8vsU3HSGbQrMROCHMi7eOFzdh-k0g7TzoFE,54
31
+ pmonitor-1.5.7.dist-info/top_level.txt,sha256=tGkQDkVeyKgP5Rr7acpp0df83NBAnI8up0sGwRxuuQ4,8
32
+ pmonitor-1.5.7.dist-info/RECORD,,