|
Home > Archive > Unix Programming > March 2007 > CPU utilization on uLinux
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
CPU utilization on uLinux
|
|
| Stephan Schulz 2007-03-28, 7:18 am |
| Hi all,
I need to monitor CPU utilization on an embedded microprocessor system
(an XScale PXA270) running uLinux with BusyBox and the Pengutronix
OSELAS tool chain/build environment.
Our requirement is essentially to ensure that CPU utilization is below
75% (or, conversely, that idle is >=25%), but it would be nice to give
a regularly updated display similarly to the way top does on most
machines (i.e. as in this line from top on RHEL):
Cpu(s): 0.7% us, 0.2% sy, 0.0% ni, 99.2% id, 0.0% wa, 0.0% hi, 0.0% si
Top on the system is really BusyBox, and does not print CPU
utilization (or support many other options).
If there is any way to get the current CPU utilization, I can of
course do the rest. I've tried Googling, but nothing really useful
came up.
Thanks!
Stephan
--
-------------------------- It can be done! ---------------------------------
Please email me as schulz@eprover.org (Stephan Schulz)
----------------------------------------------------------------------------
| |
| malc@pulsesoft.com 2007-03-28, 1:18 pm |
| schulz@sunbroy2.informatik.tu-muenchen.de (Stephan Schulz) writes:
> Hi all,
>
> I need to monitor CPU utilization on an embedded microprocessor system
> (an XScale PXA270) running uLinux with BusyBox and the Pengutronix
> OSELAS tool chain/build environment.
>
> Our requirement is essentially to ensure that CPU utilization is below
> 75% (or, conversely, that idle is >=25%), but it would be nice to give
> a regularly updated display similarly to the way top does on most
> machines (i.e. as in this line from top on RHEL):
>
> Cpu(s): 0.7% us, 0.2% sy, 0.0% ni, 99.2% id, 0.0% wa, 0.0% hi, 0.0% si
>
> Top on the system is really BusyBox, and does not print CPU
> utilization (or support many other options).
>
> If there is any way to get the current CPU utilization, I can of
> course do the rest. I've tried Googling, but nothing really useful
> came up.
>
> Thanks!
Section 1.8 describes the canonical way to get this information
http://git.kernel.org/?p=linux/kern...roc.txt;hb=HEAD
Current problems with measuring cpu utilization
http://git.kernel.org/?p=linux/kern...oad.txt;hb=HEAD
Further reading
http://marc.info/?t=117480935100001&r=1&w=2
--
vale
| |
| Stephan Schulz 2007-03-29, 1:24 pm |
| In article <slrnf0kit0.cuv.schulz@sunbroy2.informatik.tu-muenchen.de>,
Stephan Schulz wrote:
>Hi all,
>
>I need to monitor CPU utilization on an embedded microprocessor system
>(an XScale PXA270) running uLinux with BusyBox and the Pengutronix
>OSELAS tool chain/build environment.
[...]
I was pointed to the /proc/stat documentation. If someone else needs
it: This script prints Busy, Idle averaged over the second every
second (not very robust, but it works).
Bye,
Stephan
#!/usr/bin/python
import sys
import re
import string
import os
def get_vec():
fp = open("/proc/stat","r")
stat = fp.readlines()
fp.close()
for l in stat:
if l[0:4] == "cpu ":
tmp = map(int, string.split(l[5:]))
idle = tmp[3]
busy = tmp[0]+tmp[1]+tmp[2]+tmp[4]+tmp[5]+tmp[6]
return (busy, idle)
return None
old = get_vec()
while 1:
os.system("sleep 1")
current = get_vec()
diff = (current[0] - old[0], current[1] - old[1])
sum = diff[0]+diff[1]
busy = float(diff[0])/sum
idle = float(diff[1])/sum
print "Busy: ", busy, "Idle:", idle
old =current
--
-------------------------- It can be done! ---------------------------------
Please email me as schulz@eprover.org (Stephan Schulz)
----------------------------------------------------------------------------
|
|
|
|
|