1 Star 0 Fork 0

学习工作之旅/Yolo-test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
BPF-demo1.py 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
import os
import time
import psutil
import matplotlib.pyplot as plt
def get_cpu_usage():
return psutil.cpu_percent(interval=1)
def get_memory_usage():
mem = psutil.virtual_memory()
return mem.percent
def get_disk_usage():
disk = psutil.disk_usage('/')
return disk.percent
def get_file_io_stats():
disk_io_counters = psutil.disk_io_counters()
read_bytes_per_sec = disk_io_counters.read_bytes / 1024 # 转换为 KB/s
write_bytes_per_sec = disk_io_counters.write_bytes / 1024
return read_bytes_per_sec, write_bytes_per_sec
cpu_usages = []
memory_usages = []
disk_usages = []
read_speeds = []
write_speeds = []
fig, axs = plt.subplots(2, 2, figsize=(12, 8))
fig.suptitle('System Performance Monitoring')
while True:
cpu_usage = get_cpu_usage()
memory_usage = get_memory_usage()
disk_usage = get_disk_usage()
read_speed, write_speed = get_file_io_stats()
cpu_usages.append(cpu_usage)
memory_usages.append(memory_usage)
disk_usages.append(disk_usage)
read_speeds.append(read_speed)
write_speeds.append(write_speed)
os.system('clear')
print(f"CPU Usage: {cpu_usage}%")
print(f"Memory Usage: {memory_usage}%")
print(f"Disk Usage: {disk_usage}%")
print(f"File Read Speed: {read_speed} KB/s")
print(f"File Write Speed: {write_speed} KB/s")
axs[0, 0].clear()
axs[0, 0].plot(cpu_usages, label='CPU Usage', color='b')
axs[0, 0].set_title('CPU Usage')
axs[0, 0].set_ylabel('Percentage (%)')
axs[0, 1].clear()
axs[0, 1].plot(memory_usages, label='Memory Usage', color='g')
axs[0, 1].set_title('Memory Usage')
axs[0, 1].set_ylabel('Percentage (%)')
axs[1, 0].clear()
axs[1, 0].plot(disk_usages, label='Disk Usage', color='r')
axs[1, 0].set_title('Disk Usage')
axs[1, 0].set_ylabel('Percentage (%)')
axs[1, 1].clear()
axs[1, 1].plot(read_speeds, label='Read Speed', color='c')
axs[1, 1].plot(write_speeds, label='Write Speed', color='m')
axs[1, 1].set_title('File I/O Speeds')
axs[1, 1].set_ylabel('KB/s')
plt.pause(1)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qt-code-learning/yolo-test.git
git@gitee.com:qt-code-learning/yolo-test.git
qt-code-learning
yolo-test
Yolo-test
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385