Calculating CPU Usage

This is a discussion on Calculating CPU Usage within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I have a question about calculating CPU usage for a certain process on Linux. I need to be able ...

  1. #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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    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.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #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.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reduce CPU usage
    By patrick22 in forum Windows Programming
    Replies: 9
    Last Post: 07-10-2009, 02:13 PM
  2. questions on multiple thread programming
    By lehe in forum C Programming
    Replies: 11
    Last Post: 03-27-2009, 07:44 AM
  3. Net cpu usage of pthreads?!
    By mynickmynick in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2008, 07:59 AM
  4. Calculating CPU Usage
    By smarta_982002 in forum C Programming
    Replies: 7
    Last Post: 03-20-2008, 03:28 AM
  5. CPU Usage so high
    By X PaYnE X in forum Windows Programming
    Replies: 9
    Last Post: 12-21-2003, 02:07 AM

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