Thread: CPU information

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    6

    CPU information

    Hi everyone,
    I am trying to write a C program to collect some information about the cpu. Information needed includes memory performance, cpu performance, network performance, and file system information. Are there any libraries in C that would help me do that with as little kernel usage as possible?

    Thanks!

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    What OS?

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    6
    Unix/Linux, sorry.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Also, do you want to show what the ACTUAL values for this particular system is, or for example say that the memory "should be capable of X GB/s".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    69
    Not sure if this is what you need, but when my group and I were rewriting the command "top" this is what we used to see what processes are running/cpu they take/ram/etc.

    Code:
         #include <sys/types.h>
         #include <sys/sysctl.h>
    
         int
         sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
             size_t newlen);
    That will store alot of things you need in "void *oldp" which normally is a

    Code:
    struct kinfo_proc     *nameyouwant;

  6. #6
    Registered User
    Join Date
    Jun 2008
    Posts
    6
    Quote Originally Posted by matsp View Post
    Also, do you want to show what the ACTUAL values for this particular system is, or for example say that the memory "should be capable of X GB/s".

    --
    Mats
    I would like to display actual values such as overall memory, and free memory for example.

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    6
    Quote Originally Posted by +Azazel+ View Post
    Not sure if this is what you need, but when my group and I were rewriting the command "top" this is what we used to see what processes are running/cpu they take/ram/etc.

    Code:
         #include <sys/types.h>
         #include <sys/sysctl.h>
    
         int
         sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
             size_t newlen);
    That will store alot of things you need in "void *oldp" which normally is a

    Code:
    struct kinfo_proc     *nameyouwant;
    The script that is being used now actually calls top. But the only information we need from top is the memory information so to grep just that one line out from all the stats top calls uses up too much cpu since this script is being run constantly when ran.

    EDIT:
    Oops, didn't see that you said you were rewriting top. I'll see if I can find anything about that command. Thanks.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ah, ok, so you are not after benchmarking the system, but rather displaying the existing statistics of the system. I'm pretty sure there is a library (libstat?) that will help you do this by fishing it out of the relevant /sys and /proc pseudo-files.

    This was one of the first things when googling - it may not be the right thing for you, but I think it may lead you in the right direction.
    http://resourcemntrd.sourceforge.net/

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jun 2008
    Posts
    6
    Thanks! I'll check it out.

  10. #10
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    On a side-note, you can find this information (available memory, used memory) in the file (or pseudo-files should we say) /proc/meminfo if you are running Linux.
    I hate real numbers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. questions on multiple thread programming
    By lehe in forum C Programming
    Replies: 11
    Last Post: 03-27-2009, 07:44 AM
  3. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  4. Replies: 72
    Last Post: 11-25-2002, 05:55 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM