QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1692|回复: 7

请教/stat数据怎么计算cpu利用率?

[复制链接]
发表于 2003-5-29 15:51:02 | 显示全部楼层 |阅读模式
两个问题:
1。/proc/stat中的关于cpu利用率:
            cpu  139242 3367 14152 16989586
                  cpu0 139242 3367 14152 16989586
     我知道这四个数据分别是user  nice system idle的,但是怎么算利用率呢?

2。这个/stat文件是怎么更新的?多长时间写入一次数据呢?


谢谢
发表于 2003-5-29 21:21:02 | 显示全部楼层
我想这个很容易获得吧,内核里都有相关的统计变量,只不过我不知道linux的具体变量名称是什么。
回复

使用道具 举报

 楼主| 发表于 2003-5-29 21:33:55 | 显示全部楼层
  说具体点就好了
回复

使用道具 举报

发表于 2003-5-29 22:02:25 | 显示全部楼层
can u find iostat or mpstat code to read it? u will gain more.
if u get
user1 system1 nice1 idle1
user2 system2 nice2 idle2

then (idle2-idl1)/[(idle2-idle1)+(user2-user1)+(nice2-nice1)+(system2-system1)] is the idle rate, am i right?

when u read stat, it will check kernel variables. the value in kernel variables are kept changed.
回复

使用道具 举报

 楼主| 发表于 2003-5-29 22:47:24 | 显示全部楼层
user1 system1 nice1 idle1
user2 system2 nice2 idle2
这是指两次测得的值么?如果我想测上一秒的cpu利用率,是不是就是隔一秒读一次stat得到上述的值,然后用你说的方法就可以了?

cpu 139242 3367 14152 16989586 里面的数字到底什么意思啊?
是不是从你上次查看stat文件(因为你不是说查看一次改变一次么?)到这次的cpu时间的统计?

谢谢指点。
回复

使用道具 举报

发表于 2003-5-29 22:50:39 | 显示全部楼层
yes, u read it every one second and check the difference.

it change when u read it. but i do not mean it is the value since last read, it is teh value since u boot.
回复

使用道具 举报

发表于 2003-6-3 20:07:46 | 显示全部楼层
这个/stat文件是怎么更新的?多长时间写入一次数据呢?
---files in proc fs will not exist util we want to read it.
回复

使用道具 举报

发表于 2003-6-4 09:44:48 | 显示全部楼层
nod, read the procfs doc can let u know how it works
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-6-29 13:39 , Processed in 0.229098 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表