how to get statistics about memory usage ?

Discussion in 'C Programming' started by Christophe Lohr, Dec 2, 2005.

  1. Hi,

    Inside a program, I need to get some statistics about memory usage.
    I actually need figures given by the "ps -o vsr,rss" command.

    For the moment, I make a popen("ps...") followed of a scanf on what it
    displays. It is a little complicated, and that distorts measurements.
    Is there a better way?

    I have tried "getrusage()". However values returned are not really
    relevant for my needs.

    I also looked at "mallinfo()", without success.
    First, I do not know what is that a "block" (which size ?). Then, that does
    not count the stack size and the code size, just the malloc.
    (By the way, it's more or less a C++ code. So, are the "new" counted in
    mallinfo() ?)

    Then, how can my program know its "resident set size" and especially its
    "virtual memory size"?

    Thanks.
    Christophe
    Christophe Lohr, Dec 2, 2005
    #1
    1. Advertising

  2. Christophe Lohr

    Artie Gold Guest

    Christophe Lohr wrote:
    > Hi,
    >
    > Inside a program, I need to get some statistics about memory usage.
    > I actually need figures given by the "ps -o vsr,rss" command.
    >
    > For the moment, I make a popen("ps...") followed of a scanf on what it
    > displays. It is a little complicated, and that distorts measurements.
    > Is there a better way?
    >
    > I have tried "getrusage()". However values returned are not really
    > relevant for my needs.
    >
    > I also looked at "mallinfo()", without success.
    > First, I do not know what is that a "block" (which size ?). Then, that does
    > not count the stack size and the code size, just the malloc.
    > (By the way, it's more or less a C++ code. So, are the "new" counted in
    > mallinfo() ?)
    >
    > Then, how can my program know its "resident set size" and especially its
    > "virtual memory size"?
    >
    > Thanks.
    > Christophe


    The C language itself knows not of such things. Is is likely, however,
    that your platform provides some way of getting such information (likely
    in a reasonable way) <hint, hint>. See your documentation or post to a
    relevant newsgroup.

    HTH,
    --ag

    --
    Artie Gold -- Austin, Texas
    http://goldsays.blogspot.com (new post 8/5)
    http://www.cafepress.com/goldsays
    "If you have nothing to hide, you're not trying!"
    Artie Gold, Dec 2, 2005
    #2
    1. Advertising

  3. Christophe Lohr wrote:
    > Hi,
    >
    > Inside a program, I need to get some statistics about memory usage.
    > I actually need figures given by the "ps -o vsr,rss" command.
    >
    > For the moment, I make a popen("ps...") followed of a scanf on what it
    > displays. It is a little complicated, and that distorts measurements.
    > Is there a better way?
    >
    > I have tried "getrusage()". However values returned are not really
    > relevant for my needs.
    >
    > I also looked at "mallinfo()", without success.
    > First, I do not know what is that a "block" (which size ?). Then, that does
    > not count the stack size and the code size, just the malloc.
    > (By the way, it's more or less a C++ code. So, are the "new" counted in
    > mallinfo() ?)
    >
    > Then, how can my program know its "resident set size" and especially its
    > "virtual memory size"?
    >
    > Thanks.
    > Christophe


    This is all system specific, so OT in comp.lang.c. From what you are
    saying,
    I believe comp.unix.programmer would be a good place for you to get
    help. <OT> On Linux, May find what you want in /proc file system, you
    could ask about that in cup </OT>

    -David
    David Resnick, Dec 2, 2005
    #3
  4. "David Resnick" <> writes:
    [...]
    > This is all system specific, so OT in comp.lang.c. From what you are
    > saying,
    > I believe comp.unix.programmer would be a good place for you to get
    > help. <OT> On Linux, May find what you want in /proc file system, you
    > could ask about that in cup </OT>


    <STILL_OT>
    /proc is Linux-specific, though some other Unix-like systems may
    provide something similar.
    </STILL_OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Dec 2, 2005
    #4
  5. In article <>,
    Keith Thompson <> wrote:
    >"David Resnick" <> writes:
    >[...]
    >> This is all system specific, so OT in comp.lang.c. From what you are
    >> saying,
    >> I believe comp.unix.programmer would be a good place for you to get
    >> help. <OT> On Linux, May find what you want in /proc file system, you
    >> could ask about that in cup </OT>

    >
    ><STILL_OT>
    >/proc is Linux-specific, though some other Unix-like systems may
    >provide something similar.
    ></STILL_OT>


    That should have been:

    <WRONG>
    /proc is Linux-specific, though some other Unix-like systems may
    provide something similar.
    </WRONG>

    Solaris has /proc, as do (I believe) over Unix flavors.
    Kenny McCormack, Dec 2, 2005
    #5
  6. In article <dmpq8o$aa1$-bretagne.fr>,
    Christophe Lohr <> wrote:
    >Hi,
    >
    >Inside a program, I need to get some statistics about memory usage.
    >I actually need figures given by the "ps -o vsr,rss" command.
    >
    >For the moment, I make a popen("ps...") followed of a scanf on what it
    >displays. It is a little complicated, and that distorts measurements.
    >Is there a better way?


    Allow me to be the first to say this - and I say it from the deepness of my
    heart, with all the kindness and love one has come to associate with the
    helpful posts you get in this newsgroup:

    Not portable. Can't discuss it here. Blah, blah, blah.
    Kenny McCormack, Dec 2, 2005
    #6
  7. Christophe Lohr

    Flash Gordon Guest

    Kenny McCormack wrote:
    > In article <>,
    > Keith Thompson <> wrote:
    >> "David Resnick" <> writes:
    >> [...]
    >>> This is all system specific, so OT in comp.lang.c. From what you are
    >>> saying,
    >>> I believe comp.unix.programmer would be a good place for you to get
    >>> help. <OT> On Linux, May find what you want in /proc file system, you
    >>> could ask about that in cup </OT>

    >> <STILL_OT>
    >> /proc is Linux-specific, though some other Unix-like systems may
    >> provide something similar.
    >> </STILL_OT>

    >
    > That should have been:
    >
    > <WRONG>
    > /proc is Linux-specific, though some other Unix-like systems may
    > provide something similar.
    > </WRONG>


    No, what Keith said is correct.

    > Solaris has /proc, as do (I believe) over Unix flavors.


    Are you claiming that these Unix flavours are not like Unix?
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
    Flash Gordon, Dec 2, 2005
    #7
  8. (Kenny McCormack) writes:
    > In article <>,
    > Keith Thompson <> wrote:
    >>"David Resnick" <> writes:
    >>[...]
    >>> This is all system specific, so OT in comp.lang.c. From what you are
    >>> saying,
    >>> I believe comp.unix.programmer would be a good place for you to get
    >>> help. <OT> On Linux, May find what you want in /proc file system, you
    >>> could ask about that in cup </OT>

    >>
    >><STILL_OT>
    >>/proc is Linux-specific, though some other Unix-like systems may
    >>provide something similar.
    >></STILL_OT>

    >
    > That should have been:
    >
    > <WRONG>
    > /proc is Linux-specific, though some other Unix-like systems may
    > provide something similar.
    > </WRONG>
    >
    > Solaris has /proc, as do (I believe) over Unix flavors.


    With a *very* different interface, the details of which are, of
    course, best discussed elsewhere. Followups to /dev/null.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Dec 2, 2005
    #8
  9. Christophe Lohr

    Joe Estock Guest

    [OT] Re: how to get statistics about memory usage ?

    Kenny McCormack wrote:
    [usual crap]

    You're still alive Kenny? I thought someone would have killfiled you by now.

    Joe
    Joe Estock, Dec 2, 2005
    #9
  10. Christophe Lohr

    Mark B Guest

    "Flash Gordon" <> wrote in message
    news:-gordon.me.uk...
    > Kenny McCormack wrote:
    >> In article <>,
    >> Keith Thompson <> wrote:
    >>> "David Resnick" <> writes:
    >>> [...]
    >>>> This is all system specific, so OT in comp.lang.c. From what you are
    >>>> saying,
    >>>> I believe comp.unix.programmer would be a good place for you to get
    >>>> help. <OT> On Linux, May find what you want in /proc file system, you
    >>>> could ask about that in cup </OT>
    >>> <STILL_OT>
    >>> /proc is Linux-specific, though some other Unix-like systems may
    >>> provide something similar.
    >>> </STILL_OT>

    >>
    >> That should have been:
    >>
    >> <WRONG>
    >> /proc is Linux-specific, though some other Unix-like systems may
    >> provide something similar.
    >> </WRONG>

    >
    > No, what Keith said is correct.


    Actually, what Keith said is most definately NOT correct.

    >> Solaris has /proc, as do (I believe) over Unix flavors.

    >
    > Are you claiming that these Unix flavours are not like Unix?


    No, his claim is that: /proc is NOT linux specific... and he is right.
    Many systems (which predate Linux) also use(d) a /proc file system.
    Mark B, Dec 2, 2005
    #10
  11. Christophe Lohr

    Jordan Abel Guest

    Re: [OT] Re: how to get statistics about memory usage ?

    On 2005-12-02, Joe Estock <> wrote:
    > Kenny McCormack wrote:
    > [usual crap]
    >
    > You're still alive Kenny? I thought someone would have killfiled you by now.


    You know - i don't think you understand how a "killfile" works. It
    blocks him from being seen by the person who sets the killfile entry,
    unless someone else [you] responds to him. If you want him gone, _you_
    have to "killfile" him [i'm not sure how thunderbird 1.0.9 does it, but
    surely there's some way to ignore or mark-as-read based on from address]
    Jordan Abel, Dec 2, 2005
    #11
  12. Re: [OT] how to get statistics about memory usage ?

    "Mark B" <> writes:
    > "Flash Gordon" <> wrote in message
    > news:-gordon.me.uk...
    >> Kenny McCormack wrote:
    >>> In article <>,
    >>> Keith Thompson <> wrote:
    >>>> "David Resnick" <> writes:
    >>>> [...]
    >>>>> This is all system specific, so OT in comp.lang.c. From what you are
    >>>>> saying,
    >>>>> I believe comp.unix.programmer would be a good place for you to get
    >>>>> help. <OT> On Linux, May find what you want in /proc file system, you
    >>>>> could ask about that in cup </OT>
    >>>> <STILL_OT>
    >>>> /proc is Linux-specific, though some other Unix-like systems may
    >>>> provide something similar.
    >>>> </STILL_OT>
    >>>
    >>> That should have been:
    >>>
    >>> <WRONG>
    >>> /proc is Linux-specific, though some other Unix-like systems may
    >>> provide something similar.
    >>> </WRONG>

    >>
    >> No, what Keith said is correct.

    >
    > Actually, what Keith said is most definately NOT correct.
    >
    >>> Solaris has /proc, as do (I believe) over Unix flavors.

    >>
    >> Are you claiming that these Unix flavours are not like Unix?

    >
    > No, his claim is that: /proc is NOT linux specific... and he is right.
    > Many systems (which predate Linux) also use(d) a /proc file system.


    Sigh.

    My wording was slightly sloppy. The existence of /proc is not
    Linux-specific. The details of the interface of /proc *are*, as far
    as I know, Linux-specific (and/or specific to the system in question).
    My intent was merely to suggest that cup (comp.unix.programmer) is not
    the best place to discuss /proc, since it covers systems with widely
    varying /proc interfaces (or none at all, at least for some older
    systems). The details of /proc would be topical in one of the
    comp.os.linux.* groups, or in comp.unix.solaris, or comp.unix.aix, or
    whatever.

    This is tangentially topical here only insofar as we're trying to
    determine the best newsgroup to which to redirect the original poster
    (who is probably long gone by now).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Dec 2, 2005
    #12
  13. Re: [OT] Re: how to get statistics about memory usage ?

    Joe Estock <> writes:

    > Kenny McCormack wrote:
    > [usual crap]
    >
    > You're still alive Kenny? I thought someone would have killfiled you by now.


    Oh no! They killed Kenny!

    --

    John Devereux
    John Devereux, Dec 2, 2005
    #13
  14. Re: [OT] Re: how to get statistics about memory usage ?

    In article <vY2kf.595437$_o.124251@attbi_s71>,
    Joe Estock <> wrote:
    >Kenny McCormack wrote:
    >[usual crap]
    >
    >You're still alive Kenny? I thought someone would have killfiled you by now.
    >
    >Joe


    Like a bad penny...
    Kenny McCormack, Dec 2, 2005
    #14
  15. On Fri, 02 Dec 2005 20:17:37 +0000, in comp.lang.c , Flash Gordon
    <> wrote:

    >> Solaris has /proc, as do (I believe) over Unix flavors.


    Howevr what solaris puts in /proc is rather different.

    >Are you claiming that these Unix flavours are not like Unix?


    I think keith's point was that the contents of /proc are
    operating-system specific.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Dec 3, 2005
    #15
  16. In article <>,
    Mark McIntyre <> wrote:
    >On Fri, 02 Dec 2005 20:17:37 +0000, in comp.lang.c , Flash Gordon
    ><> wrote:
    >
    >>> Solaris has /proc, as do (I believe) over Unix flavors.

    >
    >Howevr what solaris puts in /proc is rather different.
    >
    >>Are you claiming that these Unix flavours are not like Unix?

    >
    >I think keith's point was that the contents of /proc are
    >operating-system specific.


    Which is the same as saying that trees are North-America-specific, because
    our trees are different from the trees that grow in other parts of the
    world.

    Note that, ordinarily, I'd cut him some slack - it's late, his phrasing was
    inexact - but this is clc where what we do is stomp on people for any
    possible error, no matter how microscopic. That's the game we play here,
    and I like it!
    Kenny McCormack, Dec 3, 2005
    #16
  17. Mark McIntyre <> writes:

    >On Fri, 02 Dec 2005 20:17:37 +0000, in comp.lang.c , Flash Gordon
    ><> wrote:


    >>> Solaris has /proc, as do (I believe) over Unix flavors.


    >Howevr what solaris puts in /proc is rather different.


    >>Are you claiming that these Unix flavours are not like Unix?


    >I think keith's point was that the contents of /proc are
    >operating-system specific.



    It's very interesting to note that the first reply to this topic was
    someone quickly highlighting how off-topic the topic was. The OP has
    since moved on to comp.unix.programmer, and received a helpful reply.

    Since then, we've seen about a dozen articles, some from old hands,
    continuing a debate about exactly what is, and what is not, a
    Linux-specific feature.

    Just an observation....

    --
    Chris.
    Chris McDonald, Dec 3, 2005
    #17
  18. Christophe Lohr

    pete Guest

    Chris McDonald wrote:
    >
    > Mark McIntyre <> writes:
    >
    > >On Fri, 02 Dec 2005 20:17:37 +0000, in comp.lang.c , Flash Gordon
    > ><> wrote:

    >
    > >>> Solaris has /proc, as do (I believe) over Unix flavors.

    >
    > >Howevr what solaris puts in /proc is rather different.

    >
    > >>Are you claiming that these Unix flavours are not like Unix?

    >
    > >I think keith's point was that the contents of /proc are
    > >operating-system specific.

    >
    > It's very interesting to note that the first reply to this topic was
    > someone quickly highlighting how off-topic the topic was. The OP has
    > since moved on to comp.unix.programmer, and received a helpful reply.
    >
    > Since then, we've seen about a dozen articles, some from old hands,
    > continuing a debate about exactly what is, and what is not, a
    > Linux-specific feature.
    >
    > Just an observation....


    I was thinking the same thing.

    "The off topic argument"

    --
    pete
    pete, Dec 3, 2005
    #18
  19. In article <dmqskk$ph0$>,
    Chris McDonald <> wrote:
    >Mark McIntyre <> writes:
    >
    >>On Fri, 02 Dec 2005 20:17:37 +0000, in comp.lang.c , Flash Gordon
    >><> wrote:

    >
    >>>> Solaris has /proc, as do (I believe) over Unix flavors.

    >
    >>Howevr what solaris puts in /proc is rather different.

    >
    >>>Are you claiming that these Unix flavours are not like Unix?

    >
    >>I think keith's point was that the contents of /proc are
    >>operating-system specific.

    >
    >
    >It's very interesting to note that the first reply to this topic was
    >someone quickly highlighting how off-topic the topic was. The OP has
    >since moved on to comp.unix.programmer, and received a helpful reply.
    >
    >Since then, we've seen about a dozen articles, some from old hands,
    >continuing a debate about exactly what is, and what is not, a
    >Linux-specific feature.


    It's what we do. We're not allowed to talk about anything substantive, so
    this is what we do.

    >Just an observation....


    And a good one.
    Kenny McCormack, Dec 3, 2005
    #19
  20. Christophe Lohr

    Joe Estock Guest

    Re: [OT] Re: how to get statistics about memory usage ?

    Jordan Abel wrote:
    > On 2005-12-02, Joe Estock <> wrote:
    >
    >>Kenny McCormack wrote:
    >>[usual crap]
    >>
    >>You're still alive Kenny? I thought someone would have killfiled you by now.

    >
    >
    > You know - i don't think you understand how a "killfile" works. It
    > blocks him from being seen by the person who sets the killfile entry,
    > unless someone else [you] responds to him. If you want him gone, _you_
    > have to "killfile" him [i'm not sure how thunderbird 1.0.9 does it, but
    > surely there's some way to ignore or mark-as-read based on from address]


    Thanks for the clarification Jordan. I was under the presumption that a
    killfile was controlled server side not client side.

    Joe
    Joe Estock, Dec 3, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Abdelhalim

    VHDL features Usage statistics

    Abdelhalim, May 18, 2004, in forum: VHDL
    Replies:
    3
    Views:
    691
    Abdelhalim
    May 19, 2004
  2. Wendy S
    Replies:
    2
    Views:
    6,964
  3. Stephanie Wilks
    Replies:
    8
    Views:
    1,742
    Thomas Mlynarczyk
    Feb 6, 2004
  4. Anand Pillai

    Python Usage Statistics

    Anand Pillai, Aug 31, 2004, in forum: Python
    Replies:
    4
    Views:
    4,786
    Jeff Shannon
    Sep 1, 2004
  5. Gabriel Zachmann

    Usage statistics?

    Gabriel Zachmann, Nov 5, 2004, in forum: Python
    Replies:
    1
    Views:
    413
    Andrew Dalke
    Nov 5, 2004
Loading...

Share This Page