🐛 Fix incorrect CPU percentage retrieval for the current process

This commit is contained in:
洛水居室 2023-12-16 16:55:35 +08:00
parent fd34078f76
commit 11c447484c
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -26,12 +26,13 @@ class Status(Plugin):
logger.info("用户 %s[%s] status 命令请求", user.full_name, user.id) logger.info("用户 %s[%s] status 命令请求", user.full_name, user.id)
message = update.effective_message message = update.effective_message
current_process = psutil.Process(self.pid) current_process = psutil.Process(self.pid)
psutil.cpu_percent()
await asyncio.sleep(0.1)
cpu_percent = psutil.cpu_percent()
memory = psutil.virtual_memory() memory = psutil.virtual_memory()
total_memory = memory.total total_memory = memory.total
used_memory = memory.used used_memory = memory.used
psutil.cpu_percent()
current_process.cpu_percent()
await asyncio.sleep(1)
cpu_percent = psutil.cpu_percent()
process_cpu_use = current_process.cpu_percent() process_cpu_use = current_process.cpu_percent()
process_use = current_process.memory_info() process_use = current_process.memory_info()
start_time = current_process.create_time() start_time = current_process.create_time()