473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2771
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Murat Tasan | last post by:
hi, i have a java application that can be fairly memory intensive. so, when i run the program, i use the -Xmx option to prevent out of memory errors. in particular, i have been using -Xmx512m,...
3
by: Ian | last post by:
Hi all, I have a problem. I have an application which needs to work with a lot of data, but not all at the same time. It is arranged as a set of objects, each with lots of data that is created...
17
by: Eternally | last post by:
Hey folks, I'm writing a simple C++ application which runs continuously. I'm running the program from the command line in Cygwin from XP, and it's cross-compatible with Linux. While running...
12
by: Fabian Knopf | last post by:
Hi @ll, my IBM DB2 server runs with 60% Cpu Usage but no task has to be done. Why this ??? Cu, Fabian
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
16
by: dfaber | last post by:
Hi all, I have been searching for a keyboard and mouse tracker on linux. I've read solutions (watch at sourceforge) which look at /proc/interrupts to check keyboard or mouse activity. I also read...
4
by: richard_l | last post by:
Hello All, I'm a newbie to Python! I am trying to develop a program that monitors the performance of an application. The kind of information I am interested in is the CPU/ Process/Thread and...
3
by: raghav82 | last post by:
I need to track the usage of one of the tool and send this information to a server.Commands to the tool are provided by the command-line of the tool. since the user can use a single command hundreds...
8
by: jacek.dziedzic | last post by:
Hi! I need to be able to track memory usage in a medium-sized application I'm developing. The only significant (memory-wise) non- local objects are of two types -- std::vector<and of a custom...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.