Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CPU utilization on uLinux

1 view
Skip to first unread message

Stephan Schulz

unread,
Mar 28, 2007, 7:04:00 AM3/28/07
to
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 sch...@eprover.org (Stephan Schulz)
----------------------------------------------------------------------------

ma...@pulsesoft.com

unread,
Mar 28, 2007, 10:06:05 AM3/28/07
to
sch...@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/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/filesystems/proc.txt;hb=HEAD

Current problems with measuring cpu utilization
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/cpu-load.txt;hb=HEAD

Further reading
http://marc.info/?t=117480935100001&r=1&w=2

--
vale

Stephan Schulz

unread,
Mar 29, 2007, 11:11:59 AM3/29/07
to
In article <slrnf0kit0...@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

0 new messages