pmonitor 1.3.3__tar.gz → 1.3.5__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.3.3 → pmonitor-1.3.5}/PKG-INFO +1 -1
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/WinPidUtil.py +15 -9
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/get_process_name.py +10 -2
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/monitor_pids.py +14 -10
- {pmonitor-1.3.3 → pmonitor-1.3.5}/pmonitor.egg-info/PKG-INFO +1 -1
- {pmonitor-1.3.3 → pmonitor-1.3.5}/setup.py +1 -1
- {pmonitor-1.3.3 → pmonitor-1.3.5}/README.md +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/GpuMonitorLib.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/KernelBase.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/__init__.py +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/advapi32.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/bcrypt.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/kernel.appcore.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/kernel32.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/msvcirt.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/msvcp140.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/ntdll.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/pdh.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/rpcrt4.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/sechost.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/ucrtbased.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/vcruntime140.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/DLL/vcruntime140_1.dll +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/__init__.py +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/exec/GpuMonitor +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/exec/__init__.py +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/monitor_mac.py +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/monitor_win.py +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/run_monitor.py +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/monitor/sys_info.py +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/pmonitor.egg-info/SOURCES.txt +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/pmonitor.egg-info/dependency_links.txt +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/pmonitor.egg-info/entry_points.txt +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/pmonitor.egg-info/top_level.txt +0 -0
- {pmonitor-1.3.3 → pmonitor-1.3.5}/setup.cfg +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import ctypes
|
|
2
2
|
from ctypes import wintypes, byref, windll
|
|
3
3
|
|
|
4
|
+
import psutil
|
|
5
|
+
|
|
4
6
|
# 定义以及初始化 API 函数和类型
|
|
5
7
|
GetSystemTimes = ctypes.windll.kernel32.GetSystemTimes
|
|
6
8
|
GetProcessTimes = ctypes.windll.kernel32.GetProcessTimes
|
|
@@ -91,6 +93,8 @@ class PidWinPerformance:
|
|
|
91
93
|
return self.filetime_to_100nano_seconds(kernel_time) + self.filetime_to_100nano_seconds(user_time)
|
|
92
94
|
|
|
93
95
|
def get_process_memory(self, pid):
|
|
96
|
+
if not psutil.pid_exists(pid):
|
|
97
|
+
return 0
|
|
94
98
|
OpenProcess = ctypes.windll.kernel32.OpenProcess
|
|
95
99
|
OpenProcess.restype = wintypes.HANDLE
|
|
96
100
|
OpenProcess.argtypes = [wintypes.DWORD, ctypes.wintypes.BOOL, wintypes.DWORD]
|
|
@@ -98,16 +102,18 @@ class PidWinPerformance:
|
|
|
98
102
|
GetProcessMemoryInfo.argtypes = [wintypes.HANDLE, ctypes.POINTER(PROCESS_MEMORY_COUNTERS_EX), wintypes.DWORD]
|
|
99
103
|
GetProcessMemoryInfo.restype = ctypes.wintypes.BOOL
|
|
100
104
|
process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, pid)
|
|
101
|
-
if
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
if psutil.Process(pid).is_running() and psutil.Process(pid).status() != psutil.STATUS_ZOMBIE:
|
|
106
|
+
if not process:
|
|
107
|
+
raise ctypes.WinError()
|
|
108
|
+
counters = PROCESS_MEMORY_COUNTERS_EX()
|
|
109
|
+
counters.cb = ctypes.sizeof(PROCESS_MEMORY_COUNTERS_EX)
|
|
110
|
+
|
|
111
|
+
if not GetProcessMemoryInfo(process, ctypes.byref(counters), counters.cb):
|
|
112
|
+
CloseHandle(process)
|
|
113
|
+
raise ctypes.WinError()
|
|
107
114
|
CloseHandle(process)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return counters
|
|
115
|
+
return counters
|
|
116
|
+
return 0
|
|
111
117
|
|
|
112
118
|
def get_io_counters(self, pid):
|
|
113
119
|
counters = IO_COUNTERS()
|
|
@@ -91,8 +91,16 @@ class ProcessName:
|
|
|
91
91
|
:return:
|
|
92
92
|
'''
|
|
93
93
|
children = set()
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
try:
|
|
95
|
+
parent_process = psutil.Process(pid)
|
|
96
|
+
for child in parent_process.children(recursive=True):
|
|
97
|
+
children.add(child.pid)
|
|
98
|
+
except psutil.NoSuchProcess:
|
|
99
|
+
# print(f"主进程 {pid} 不存在或已终止.")
|
|
100
|
+
pass
|
|
101
|
+
except Exception as e:
|
|
102
|
+
# print(f"获取子进程PID时发生错误: {e}")
|
|
103
|
+
pass
|
|
96
104
|
return children
|
|
97
105
|
|
|
98
106
|
def find_main_process_pid(self, process_name) -> None:
|
|
@@ -124,6 +124,7 @@ class PidsPerf:
|
|
|
124
124
|
p_pid = self.processUtil.find_main_process_pid(self.process_name)
|
|
125
125
|
child_pids = self.processUtil.get_children_pids(p_pid)
|
|
126
126
|
child_pids.add(p_pid) # app内所有pid
|
|
127
|
+
|
|
127
128
|
process_cpu_times_pre = {pid: pidWinPerf.get_process_cpu_time(pid) for pid in child_pids}
|
|
128
129
|
process_io_counters_pre = {pid: pidWinPerf.get_io_counters(pid) for pid in child_pids}
|
|
129
130
|
|
|
@@ -148,9 +149,6 @@ class PidsPerf:
|
|
|
148
149
|
main_gpu_committed_sum = 0 # (总使用内存)
|
|
149
150
|
main_gpu_percent_sum = 0 # (GPU内存占比)
|
|
150
151
|
|
|
151
|
-
current_pids = self.processUtil.get_children_pids(p_pid) # 获取所有子进程
|
|
152
|
-
current_pids.add(p_pid) # 将主进程及子进程添加到list中
|
|
153
|
-
|
|
154
152
|
start_time = time.time() # 记录循环开始的时间
|
|
155
153
|
system_idle_time = FILETIME()
|
|
156
154
|
system_kernel_time = FILETIME()
|
|
@@ -160,18 +158,23 @@ class PidsPerf:
|
|
|
160
158
|
byref(system_user_time))
|
|
161
159
|
system_time_post = pidWinPerf.filetime_to_100nano_seconds(
|
|
162
160
|
system_kernel_time) + pidWinPerf.filetime_to_100nano_seconds(system_user_time)
|
|
163
|
-
|
|
161
|
+
p_pid = self.processUtil.find_main_process_pid(self.process_name)
|
|
164
162
|
child_pids = self.processUtil.get_children_pids(p_pid)
|
|
165
163
|
child_pids.add(p_pid) # app内所有pid
|
|
164
|
+
child_pids = {pid for pid in child_pids if psutil.pid_exists(pid)} # 移除不存在的进程
|
|
166
165
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
try:
|
|
167
|
+
new_pids_cpu_time_pre = {pid: pidWinPerf.get_process_cpu_time(pid) for pid in child_pids if
|
|
168
|
+
pid not in process_cpu_times_pre}
|
|
169
|
+
process_cpu_times_pre.update(new_pids_cpu_time_pre)
|
|
170
|
+
new_process_io_counters_pre = {pid: pidWinPerf.get_io_counters(pid) for pid in child_pids}
|
|
171
|
+
process_io_counters_pre.update(new_process_io_counters_pre)
|
|
172
|
+
except psutil.Error as ex:
|
|
173
|
+
print(f"Error updating counters: {ex}")
|
|
172
174
|
|
|
173
175
|
# print('----------------------------------------------------------')
|
|
174
176
|
# print('pid', child_pids)
|
|
177
|
+
|
|
175
178
|
for pid in child_pids:
|
|
176
179
|
try:
|
|
177
180
|
process = psutil.Process(pid)
|
|
@@ -182,10 +185,11 @@ class PidsPerf:
|
|
|
182
185
|
# print('pid is not found')
|
|
183
186
|
mem_percent = 0
|
|
184
187
|
thread_count = 0
|
|
185
|
-
|
|
186
188
|
process_cpu_time_post = pidWinPerf.get_process_cpu_time(pid)
|
|
187
189
|
memory_info = pidWinPerf.get_process_memory(pid)
|
|
188
190
|
io_counters = pidWinPerf.get_io_counters(pid)
|
|
191
|
+
if io_counters is None or pid not in process_io_counters_pre:
|
|
192
|
+
continue
|
|
189
193
|
read_bytes_sec = (io_counters.ReadTransferCount - process_io_counters_pre[
|
|
190
194
|
pid].ReadTransferCount) / self.interval
|
|
191
195
|
write_bytes_sec = (io_counters.WriteTransferCount - process_io_counters_pre[
|
|
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
|