469,271 Members | 934 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

track cpu usage of linux application

Hi,

I would like to track the cpu usage of a couple of
programs using python. Maybe it works somehow with
piping 'top' to python read the cpu load for a greped
application and clocking the the first and last
appearence. Is that a good approach or does anyone have
a more elegant way to do that?

Greetings!
Fabian

May 14 '07 #1
2 2649
Fabian Braennstroem <f.************@gmx.dewrote:
Hi,
I would like to track the cpu usage of a couple of
programs using python. Maybe it works somehow with
piping 'top' to python read the cpu load for a greped
application and clocking the the first and last
appearence. Is that a good approach or does anyone have
a more elegant way to do that?
Greetings!
Fabian
If you're on a Linux system you might be far better accessing
the /proc/$PID/stat files directly. The values you'd find therein
are documented:

http://www.die.net/doc/linux/man/man5/proc.5.html

(among other places).

Of course you could write you code to look for file and fall back
to use the 'ps' command if it fails. In addition you can supply
arguments to the 'ps' command to limit it to reporting just on the
process(es) in which you are interested ... and to eliminate the
header line and irrelevant columns of output.
--
Jim Dennis,
Starshine: Signed, Sealed, Delivered

May 14 '07 #2
Hi,
thanks to both! I will take a look at the proc files!

* James T. Dennis <ja******@idiom.comwrote:
Fabian Braennstroem <f.************@gmx.dewrote:
>Hi,
> I would like to track the cpu usage of a couple of
programs using python. Maybe it works somehow with
piping 'top' to python read the cpu load for a greped
application and clocking the the first and last
appearence. Is that a good approach or does anyone have
a more elegant way to do that?
>Greetings!
Fabian

If you're on a Linux system you might be far better accessing
the /proc/$PID/stat files directly. The values you'd find therein
are documented:

http://www.die.net/doc/linux/man/man5/proc.5.html

(among other places).

Of course you could write you code to look for file and fall back
to use the 'ps' command if it fails. In addition you can supply
arguments to the 'ps' command to limit it to reporting just on the
process(es) in which you are interested ... and to eliminate the
header line and irrelevant columns of output.
Greetings!
Fabian

May 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Murat Tasan | last post: by
17 posts views Thread by Eternally | last post: by
12 posts views Thread by Fabian Knopf | last post: by
8 posts views Thread by Adrian | last post: by
16 posts views Thread by dfaber | last post: by
8 posts views Thread by jacek.dziedzic | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.