python中使用psutil查看内存占用的情况
有的时候需要对python程序内存占用进行监控,这个时候可以用到psutil库,Anaconda中是自带的,如果import出错,可以用pip install psutil(安装在python中)或conda install psutil(安装在Anaconda中)
#常用的: import psutil import os info = psutil.virtual_memory() print u'内存使用:',psutil.Process(os.getpid()).memory_info().rss print u'总内存:',info.total print u'内存占比:',info.percent print u'cpu个数:',psutil.cpu_count()
其他内置的方法或属性还有:
boot_time callable collections cpu_count cpu_percent cpu_stats cpu_times cpu_times_percent disk_io_counters disk_partitions disk_usage errno functools long net_connections net_if_addrs net_if_stats net_io_counters os pid_exists pids process_iter pwd signal subprocess swap_memory sys test time traceback users version_info virtual_memory wait_procs win_service_get win_service_iter
查看windows开机时间
import time import psutil print (u'电脑开机时间:{}'.format(time.strftime('%y-%m-%d %H:%M:%S', time.localtime(psutil.boot_time()))))
相关推荐
牧码人 2020-06-14
从0到 2020-05-09
JakobHu 2020-05-09
凉白开 2020-04-20
CloasGao 2020-04-08
chaigang 2020-04-07
GuoSir 2019-12-11
jingleisi 2019-11-03
lqxqust 2016-03-28
sddfsAv 2018-08-06
linkequa 2018-06-21
ateacup 2017-10-22
hzx0 2018-06-11
ytp00ytp 2018-06-11
Yasin 2018-05-30
zhaojikun 2018-05-30
流量监控距离咯 2018-05-24
yxqfxd 2018-05-24
zlxcsdn 2018-05-24