reporting memory usage

This is a discussion on reporting memory usage within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm looking for a way to report the memory usage of my process. I'd like to do something like: ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    8

    reporting memory usage

    Hi,

    I'm looking for a way to report the memory usage of my process. I'd like to do something like:

    Code:
    std::cout << "memory usage at point xyz: " << GetMyMemoryUsage() << std::endl;
    Is there a way to do this independent of the operating system? If not, I'm looking for ways to do that on SunOS, Linux and Windows.

    Further it would be interesting to report which part of the process is in main memory and how much is swapped out.

    Thanks,

    Michael

  2. #2
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    Here's something, what i have used to use...

    http://www.gnu.org/software/libc/man...arameters.html

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Here's an excerpt from the Windows XP Source Code (Release 1.0.3978)

    Code:
    #include <stdlib>
    #include <time>
    
    int GetMyMemoryUsage
    {
         int usage;
         srand(time(NULL));
         usage=rand();
         return usage;
    }

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    8
    Thanks for the link, tjohnsson. It actually points to information about how to query page sizes etc., that's not quite what I was looking for. I'm rather interested in the current memory usage of my process. However, not far from you link (maybe you actually intended to send me that one :-) I found some information about getrusage():

    http://www.gnu.org/software/libc/man...source%20Usage

    It seems that this function might provide me with the information I'm looking for, however, I'm not quite sure about how to use it properly.

    I think ru_ixrss + ru_idrss + ru_isrss is basically what I'm looking for, is this correct? I didn't really understand how this values are represented ("expressed in kilobytes times ticks of execution"). What are "ticks of execution" and what do they have to do with memory usage?

    Thanks,

    Michael

  5. #5
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70

    Thumbs up

    Quote Originally Posted by kuhnmi
    Thanks for the link, tjohnsson. It actually points to information about how to query page sizes etc., that's not quite what I was looking for. I'm rather interested in the current memory usage of my process. However, not far from you link (maybe you actually intended to send me that one :-) I found some information about getrusage():
    Actually i didn't read your question carefully enough so link has it purpose here. but anyway.
    getrusage(); atleast on my machine returns only zeros to these fields where to get information about process or child process
    memory usage.
    it propably needs something compiled to kernel like acct needs, to
    get these information from kernel.

    go look /proc/"any pid"/ there's lot of information about running processes. like vmstat, status. i bet you can find there what you wanna know about process memory usage.
    if you wanna get information from current running process
    /proc/self is always symbolic link to it's folder.

    run: man proc
    to see these files fields meaning.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  3. calculate memory consumption and cpu usage
    By GermanDev in forum C++ Programming
    Replies: 18
    Last Post: 12-14-2008, 04:32 PM
  4. how much memory usage for my program?
    By elninio in forum Linux Programming
    Replies: 4
    Last Post: 08-01-2008, 03:58 PM
  5. Memory Usage
    By ghe1 in forum Linux Programming
    Replies: 0
    Last Post: 03-18-2002, 08:43 AM

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