|
蓝森林 http://www.lslnet.com 2006年6月6日 10:18
/proc/stat的问题
我想利用/proc/stat的内容计算cpu的利用率,看了man proc手册,解释不是很清晰,请问下面的数值都代表什么意思啊:
[code]
[root@RaulDevServer proc]# cat stat
cpu 7222422 98402 10757142 109871613 263399 12610 0
cpu0 7222422 98402 10757142 109871613 263399 12610 0
[/code]
我的机器是FC2的系统:
[code]
[root@RaulDevServer cpu]# man proc
stat kernel/system statistics. Varies with architecture. Common
entries include:
cpu 3357 0 4313 1362393
The number of jiffies (1/100ths of a second) that the
system spent in user mode, user mode with low priority
(nice), system mode, and the idle task, respectively.
The last value should be 100 times the second entry in
the uptime pseudo-file.
[/code] |
正好前段时间老板让我做了个kernel中计算CPU和MEM使用率的模块
//new example
cpu 266415 10318 32917 135954819 40804 1678 1063
cpu0 266415 10318 32917 135954819 40804 1678 1063
//前者是CPU负载合计,后者是指单CPU负载,如SMP的cpu为cpu0和cpu1
//这些是指cpu的“七大客户”(以下简称“七大”)占用的jiffies数统计,从开机计算(存在溢出问题:))
//“七大”和“top”(不要告诉我你不知道)中的“ 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% si ” 是一一对应的,可以用如下数据结构表示:
struct cpu_info
{
U64 user;
U64 system;
U64 nice;
U64 idle;
U64 iowait;
U64 irq;
U64 softirq;
};
//具体每项的意思其实就很明显了
//如何计算是个小学数学问题,就不用赘述了
//不过在kernel中直接取数据也比较方便(……)
//:)
//ytao_2004@hotmail.com |
谢谢ytao_2004 (tt) 了~~~!! |
呵呵~~能不能再问一个问题哈~~如何从内核中获取这些数据啊,写LKM吗~? |
方法比较多
是的,利用模块是比较灵活
也可以直接在kernel中做和写到proc结构中
//关键:kstat_cpu(0).cpustat.user ...
如果只是user land用,还是建议通过/proc/stat中的数据进行计算即可,没有必要这么麻烦 |
| |