Find the answer to your Linux question:
Results 1 to 7 of 7
How can I calculate the cpu time (or % used) for a multithreaded process in Linux using data maintained by the proc filesystem. I have found, in practice, that utime ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    4

    calculating cpu time (or %) for a multithreaded app in Linux


    How can I calculate the cpu time (or % used) for a multithreaded process in Linux using data maintained by the proc filesystem. I have found, in practice, that utime and stime do not seem to report correct results for multithreaded apps...

  2. #2
    Just Joined!
    Join Date
    Oct 2005
    Location
    Mass
    Posts
    52

    Re: calculating cpu time (or %) for a multithreaded app in Linux

    Quote Originally Posted by rnicholus
    How can I calculate the cpu time (or % used) for a multithreaded process in Linux using data maintained by the proc filesystem. I have found, in practice, that utime and stime do not seem to report correct results for multithreaded apps...
    I'm gonna take a stab at this one and say that, since threads are maintained by the library (e.g. pthreads) and not the operating system itself, you can't depend on proc for that type of information (at least in GNU/Linux)

    hopes this helps you at least a little

  3. #3
    Just Joined!
    Join Date
    Sep 2005
    Posts
    4
    so, how can I get this info from say, a non-shell program (such as a java console app)

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Oct 2005
    Location
    Mass
    Posts
    52
    Quote Originally Posted by rnicholus
    so, how can I get this info from say, a non-shell program (such as a java console app)
    OHHH now that's easy.. use a java profiler like jprofiler
    http://www.ej-technologies.com/produ.../overview.html

    it's commercial but it really is a godsend

  6. #5
    Just Joined!
    Join Date
    Oct 2005
    Posts
    9
    Friend

    I had just started to study multithread programming in Linux, so take the advice with a (big) grain of salt... So far as I remember, if you are using 'linuxthreads', each thread will appear as a process in your system.

    So the percentage of CPU usage will appear em TOP or other like program. A way to grab the stats of your program (using shell) could be:
    $ps aux | grep "name_of_you_executable"

    You could browse the source of 'sar' program, since it does read /proc file system to get the whole stats of system. It's finally clean piece of code (well at least in OSS standards) written in C, so you could learn some tricks there to programmatically grab stats of system.

    If you are using NPTL (Native Posix Thread Library) a contribution from Red Hat (and default in RH, Fedora, etc), it seems the behaviour is different: each thread will not appear as distinct process. You will be able to see only the main process that hosts the several threads.

    Best regards


    Savago

  7. #6
    Just Joined!
    Join Date
    Sep 2005
    Posts
    4

    sar

    What is this "sar" program, and where can I find it in my Linux filesystem?

  8. #7
    Just Joined!
    Join Date
    Oct 2005
    Posts
    9
    Friend

    'sar' is part of 'sysstat', a package with several programs to colect data and make analysis of performance in Linux systems. Sysstat will provide you with this apps: sar, iostat, mpstat.

    Do a google search and you will be able to find several links to download it.


    Savago

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •