C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-20-2005, 09:29 PM   #1
Registered User
 
Join Date: Aug 2005
Posts: 2
Calculating CPU Usage

Hi,

I have a question about calculating CPU usage for a certain process on Linux. I need to be able to calculate CPU utilization for a process and its threads given a PID or a name. Unfortunately, "top" is slow and my version of "ps" does not support calculating CPU usage in the raw mode. For this particular purpose, I'd like to calculate CPU usage using either system programming or by having some sort of a script that reads through /proc filesystem. Does anybody know how to do this by using any of those or other methods? Many thanks in advance.

--V
vitaliy is offline   Reply With Quote
Old 08-21-2005, 12:58 AM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
At your prompt type
time ./a.out
(or whatever your program is called)
When it exits, the shell will print out some timing information.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 08-21-2005, 09:19 AM   #3
Registered User
 
Join Date: Aug 2005
Posts: 2
This may work, unfortunately, I need real time stats update every second or so in order to plot a graph of CPU utilization. I am trying to benchmark a server and I am interested in how it handles QPS over time.

Thank you.
vitaliy is offline   Reply With Quote
Old 08-21-2005, 09:38 AM   #4
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
http://www.die.net/doc/linux/man/man2/times.2.html
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reduce CPU usage patrick22 Windows Programming 9 07-10-2009 02:13 PM
questions on multiple thread programming lehe C Programming 11 03-27-2009 07:44 AM
Net cpu usage of pthreads?! mynickmynick C++ Programming 15 09-26-2008 07:59 AM
Calculating CPU Usage smarta_982002 C Programming 7 03-20-2008 03:28 AM
CPU Usage so high X PaYnE X Windows Programming 9 12-21-2003 03:07 AM


All times are GMT -6. The time now is 08:34 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22