# -*- coding: utf-8 -*-
import time
import psutil
# 逻辑核心
cpu_no = psutil.cpu_count()
print(cpu_no)
# 物理核心
cpu_rel_no = psutil.cpu_count(logical=False)
print(cpu_rel_no)
# 统计CPU的用户/系统/空闲时间
cpu_time = psutil.cpu_times()
print(cpu_time)
# scputimes(user=130298.14, nice=0.0, system=145884.58, idle=5131330.82)
# CPU使用率,每秒刷新一次,累计10次 类似于top
for i in range(1):
start_time = time.time()
# 返回CPU的利用率, percpu为True时显示所有物理核心的利用率, interval不为0时, 则阻塞时显示interval执行的时间内的平均利用率
cpu_percent = psutil.cpu_percent(percpu=True, interval=2)
print(cpu_percent)
print(time.time()-start_time)
# 物理内存
rel_memory = psutil.virtual_memory()
print(rel_memory)
# svmem(total=17179869184, available=7014621184, percent=59.2, used=8842629120, free=358690816, active=6656806912, inactive=6598430720, wired=2185822208)
# 交换内存
swap_memory = psutil.swap_memory()
print(swap_memory)
# sswap(total=1073741824, used=245628928, free=828112896, percent=22.9, sin=61215977472, sout=161824768)
# 用户
user = psutil.users()
print(user)