mac下python实现vmstat
mac下没有linux/unix 的vmstat,只有vm_stat;
sh-3.2# vm_stat
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free: 191876.
Pages active: 433086.
Pages inactive: 141819.
Pages speculative: 23119.
Pages throttled: 0.
Pages wired down: 254606.
Pages purgeable: 11895.
"Translation faults": 20445131.
Pages copy-on-write: 1435992.
Pages zero filled: 10414067.
Pages reactivated: 39459.
Pages purged: 23388.
File-backed pages: 172905.
Anonymous pages: 425119.
Pages stored in compressor: 12595.
Pages occupied by compressor: 3399.
Decompressions: 5824.
Compressions: 26966.
Pageins: 1626450.
Pageouts: 4218.
Swapins: 1487.
Swapouts: 5130.
不想用下面这个复杂top命令
sh-3.2# top -l 1 -s 0 | grep PhysMem
PhysMem: 3277M used (992M wired), 817M unused.
用下面这个python
#!/usr/bin/python import subprocess
import re # Get process info
ps = subprocess.Popen(['ps', '-caxm', '-orss,comm'], stdout=subprocess.PIPE).communicate()[0]
vm = subprocess.Popen(['vm_stat'], stdout=subprocess.PIPE).communicate()[0] # Iterate processes
processLines = ps.split('\n')
sep = re.compile('[\s]+')
rssTotal = 0 # kB
for row in range(1,len(processLines)):
rowText = processLines[row].strip()
rowElements = sep.split(rowText)
try:
rss = float(rowElements[0]) * 1024
except:
rss = 0 # ignore...
rssTotal += rss # Process vm_stat
vmLines = vm.split('\n')
sep = re.compile(':[\s]+')
vmStats = {}
for row in range(1,len(vmLines)-2):
rowText = vmLines[row].strip()
rowElements = sep.split(rowText)
vmStats[(rowElements[0])] = int(rowElements[1].strip('\.')) * 4096 print 'Wired Memory:\t\t%d MB' % ( vmStats["Pages wired down"]/1024/1024 )
print 'Active Memory:\t\t%d MB' % ( vmStats["Pages active"]/1024/1024 )
print 'Inactive Memory:\t%d MB' % ( vmStats["Pages inactive"]/1024/1024 )
print 'Free Memory:\t\t%d MB' % ( vmStats["Pages free"]/1024/1024 )
print 'Real Mem Total (ps):\t%.3f MB' % ( rssTotal/1024/1024 )
sh-3.2# ./mem.py
Wired Memory: 1013 MB
Active Memory: 1951 MB
Inactive Memory: 573 MB
Free Memory: 423 MB
Real Mem Total (ps): 3180.027 MB
mac下python实现vmstat的更多相关文章
- Mac下python初学之Image库(PIL)
Mac下python 使用Image库 安装PIL,下载http://www.pythonware.com/products/pil/ 解压PIL源码包,阅读README知道需要使用python se ...
- mac下python环境pip报错[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) 的解决方法
1.mac下python环境pip报错: issuserdeMacBook-Pro:~ issuser$ pip install pyinstallerCollecting pyinstaller ...
- Mac 下 python 环境问题
一.Mac下,可能存在的 python 环境: 1.Mac系统自带的python环境在(由于不同的 mac 系统,默认自带的 python 版本可能不一样): Python 2.7.10: /Syst ...
- Mac下Python和Pycharm之virtualenv
一.python如何配置virtualenv 1.安装virtualenv pip3 install virtualenvpip install -i https://pypi.tuna.tsin ...
- mac 下 python 虚拟环境的安装和配置
前言:继续安装中,这节记录 mac 安装 python 虚拟环境,多版本共存... 1. 安装 pip -- python的包管理工具: sudo easy_install pip 安装成功,出现下面 ...
- mac下Python安装路径的说明
Python安装路径的说明 mac在安装Python时, 对不同的安装方式 不同的型号均会安装在不同的文件夹下 安装方式 路径 系统默认(2.7) /System/Library/Frameworks ...
- 在MAC下 Python+Django+mysql配置
今天在搭建Django+mysql环境的时候遇到了一点问题,记录下来. 安装环境:OS X 10.10操作系统,Python 2.7. MySQLdb其实包含在MySQL-python包中,因此无论下 ...
- [转]mac下Python升级到指定的版本
以2.7升级到3.3为例1.删除原版本a)删除系统库中的版本sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7 b) ...
- mac下python安装MySQLdb模块
参考:http://blog.csdn.net/yelyyely/article/details/41114449 1.调整到anaconda下的python 2.安装有关程序 brew instal ...
随机推荐
- 使用的组件:ckeditor
老牌Web文本编辑器,无需多言. 官网地址:http://ckeditor.com/
- SQLSERVER 2012之AlwaysOn -- 同步模式下的网卡性能优化
本文是基于上一篇<SQLServer 2012之AlwaysOn -- 指定数据同步链路,消除网络抖动导致的提交延迟问题>的问题继续进行优化:具体背景请参照上文: 前后折腾了一个多 ...
- 转载:SQL Server 2008-建立分区表(Table Partition) 转载
数据库结构和索引的是否合理在很大程度上影响了数据库的性能,但是随着数据库信息负载的增大,对数据库的性能也发生了很大的影响.可能我们的数据库在一开始有着很高的性能,但是随着数据存储量的急速增长—例如订单 ...
- Gatling->次时代性能测试利器
Gatling作为一款开源免费的性能测试工具越来越受到广大程序员的欢迎.免费当然是好的,最缺钱的就是程序员了;开源更好啊,缺啥功能.想做定制化的可以自己动手,丰衣足食.其实我最喜欢的原因是其提供了简洁 ...
- iOS 字典自动生成模型
在实际开发中,我们经常需要根据字典来建模型.每次都打那么一串代码,想想也是挺恶心的.可以自己给NSDictionary写一个分类,进行属性生成. NSDictionary+Property.h #im ...
- android mvvm初探
目前google的databinding library还处在rc版,其中编译器发挥了主要作用.目前也只是在android studio开发环境中支持. mvvm能够大大降低模块间的耦合度,在开发过程 ...
- 文件系统:Ext3和Ext4
一.ext3和ext4的区别: 1.与Ext3兼容:执行若干条命令,就能将Ext3在线迁移到Ext4,而无须重新格式化磁盘或者重新安装系统.原有Ext3数据结构照样保留, Ext4作用于新数据,当然, ...
- Android Studio 生成Release版,报Warning的解决办法
转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6242227.html 请尊重知识产权!!! 同步更新到CSDN:http://blog.csdn.net/ ...
- iOS UICollectionView的实现
ios的UICollectionView并不能在iOS6之前的版本中使用,为了兼容之前的版本需要自定义UICollectionView.写完之后发现人家已经有开源了,下过来看了看发现我是用UIScro ...
- iOS开发-- 开发环境,证书和授权文件
一.成员介绍 1. Certification(证书)证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种:1) Developer Certification(开发证书)安装在电脑 ...