2015-04-22 86 views
0

我正在阅读有关计算进程的CPU使用情况。pcpu是什么意思,为什么乘以1000?

seconds = utime/Hertz 

total_time = utime + stime 

IF include_dead_children 
    total_time = total_time + cutime + cstime 
ENDIF 

seconds = uptime - starttime/Hertz 

pcpu = (total_time * 1000/Hertz)/seconds 

print: "%CPU" pcpu/10 "." pcpu % 10 

我不明白的是,由“秒”的算法是指时间花在电脑做多兴趣的过程等操作,以及前。因为正常运行时间是我们计算机运行的时间,启动时间意味着我们[感兴趣]进程开始的时间。

那么我们为什么要把total_time除以seconds [计算机花时间做其他事情]得到pcpu?这没有意义。

变量的标准含义:

# Name  Description 
14 utime  CPU time spent in user code, measured in jiffies 
15 stime  CPU time spent in kernel code, measured in jiffies 
16 cutime CPU time spent in user code, including time from children 
17 cstime CPU time spent in kernel code, including time from children 
22 starttime Time when the process started, measured in jiffies 

/proc/uptime :The uptime of the system (seconds), and the amount of time spent in idle process (seconds). 

Hertz  :Number of clock ticks per second 
+0

由于我们不知道“utime”,“hertz”,“stime”,“cutime”,“ctimes”,“uptime”,“starttime”等的定义,回答这个问题需要做出相当多的假设。如果你能详细说明你的变量是什么以及它们包含什么值(或者它们来自哪里,至少)...... – twalberg

+0

这些是标准术语。但是,我会为你更新这个问题。 – complextea

回答

0

现在,您已经提供了每个变量代表,这里的一对伪代码一些意见:

seconds = utime/Hertz 

上面一行是没有意义的,因为seconds的新值在稍后被覆盖几行之前从未使用过。因为这两个utimestime

total_time = utime + stime 

总运行时间的过程中,以jiffies的(用户+系统),是。

IF include_dead_children 
    total_time = total_time + cutime + cstime 
ENDIF 

这应该可能只是说total_time = cutime + cstime,因为这些定义似乎表明,例如, cutime已包含utime,加上儿童在用户模式下的时间。所以,正如所写的,这通过两次包括来自这个过程的贡献而夸大了价值。或者,定义是错误的...无论如何,total_time仍然在jiffies。

seconds = uptime - starttime/Hertz 

uptime已经在秒; starttime/Hertzstarttime从jiffies转换为秒,因此seconds本质上变成了“自启动此过程以来的秒数”。

pcpu = (total_time * 1000/Hertz)/seconds 

total_time仍然以jiffies,所以total_time/Hertz转换,要秒,这是由过程中消耗CPU的秒数。除以seconds之后,如果它是浮点运算,则会自进程开始以来提供缩放的CPU使用百分比。由于它不是,所以它的缩放比例为1000,分辨率为1/10%。为了保持准确性,缩放必须尽早使用圆括号完成。

print: "%CPU" pcpu/10 "." pcpu % 10 

而这个撤销的缩放比例,除以pcpu当由如图10所示,并在这看起来像一个浮点值的格式打印这些值求出被除数和余数。

+0

因此,我们可以说'pcpu'是过程实际利用CPU的过程中“年龄”的百分比吗? – complextea

+1

是的。它不是像“顶部”那样的“即时”CPU使用率百分比(反正它并不是瞬时的,测量的时间间隔仍然很短),而是基于总CPU使用率与总数的百分比为该过程运行挂钟时间。 – twalberg