how to get statistics about memory usage ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christophe Lohr

    #1

    how to get statistics about memory usage ?

    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
  • Artie Gold

    #2
    Re: how to get statistics about memory usage ?

    Christophe Lohr wrote:[color=blue]
    > 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[/color]

    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!"

    Comment

    • David Resnick

      #3
      Re: how to get statistics about memory usage ?

      Christophe Lohr wrote:[color=blue]
      > 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[/color]

      This is all system specific, so OT in comp.lang.c. From what you are
      saying,
      I believe comp.unix.progr ammer 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

      Comment

      • Keith Thompson

        #4
        Re: how to get statistics about memory usage ?

        "David Resnick" <lndresnick@gma il.com> writes:
        [...][color=blue]
        > This is all system specific, so OT in comp.lang.c. From what you are
        > saying,
        > I believe comp.unix.progr ammer 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>[/color]

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

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <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.

        Comment

        • Kenny McCormack

          #5
          Re: how to get statistics about memory usage ?

          In article <lnsltbe4ht.fsf @nuthaus.mib.or g>,
          Keith Thompson <kst-u@mib.org> wrote:[color=blue]
          >"David Resnick" <lndresnick@gma il.com> writes:
          >[...][color=green]
          >> This is all system specific, so OT in comp.lang.c. From what you are
          >> saying,
          >> I believe comp.unix.progr ammer 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>[/color]
          >
          ><STILL_OT>
          >/proc is Linux-specific, though some other Unix-like systems may
          >provide something similar.
          ></STILL_OT>[/color]

          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.

          Comment

          • Kenny McCormack

            #6
            Re: how to get statistics about memory usage ?

            In article <dmpq8o$aa1$1@m atell.enst-bretagne.fr>,
            Christophe Lohr <christophe.loh r@enst-bretagne.fr> wrote:[color=blue]
            >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?[/color]

            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.

            Comment

            • Keith Thompson

              #7
              Re: how to get statistics about memory usage ?

              gazelle@yin.int eraccess.com (Kenny McCormack) writes:[color=blue]
              > In article <lnsltbe4ht.fsf @nuthaus.mib.or g>,
              > Keith Thompson <kst-u@mib.org> wrote:[color=green]
              >>"David Resnick" <lndresnick@gma il.com> writes:
              >>[...][color=darkred]
              >>> This is all system specific, so OT in comp.lang.c. From what you are
              >>> saying,
              >>> I believe comp.unix.progr ammer 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>[/color]
              >>
              >><STILL_OT>
              >>/proc is Linux-specific, though some other Unix-like systems may
              >>provide something similar.
              >></STILL_OT>[/color]
              >
              > 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.[/color]

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

              --
              Keith Thompson (The_Other_Keit h) kst-u@mib.org <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.

              Comment

              • Flash Gordon

                #8
                Re: how to get statistics about memory usage ?

                Kenny McCormack wrote:[color=blue]
                > In article <lnsltbe4ht.fsf @nuthaus.mib.or g>,
                > Keith Thompson <kst-u@mib.org> wrote:[color=green]
                >> "David Resnick" <lndresnick@gma il.com> writes:
                >> [...][color=darkred]
                >>> This is all system specific, so OT in comp.lang.c. From what you are
                >>> saying,
                >>> I believe comp.unix.progr ammer 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>[/color]
                >> <STILL_OT>
                >> /proc is Linux-specific, though some other Unix-like systems may
                >> provide something similar.
                >> </STILL_OT>[/color]
                >
                > That should have been:
                >
                > <WRONG>
                > /proc is Linux-specific, though some other Unix-like systems may
                > provide something similar.
                > </WRONG>[/color]

                No, what Keith said is correct.
                [color=blue]
                > Solaris has /proc, as do (I believe) over Unix flavors.[/color]

                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.

                Comment

                • Joe Estock

                  #9
                  [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

                  Comment

                  • Mark B

                    #10
                    Re: how to get statistics about memory usage ?


                    "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
                    news:dkm663xln4 .ln2@news.flash-gordon.me.uk...[color=blue]
                    > Kenny McCormack wrote:[color=green]
                    >> In article <lnsltbe4ht.fsf @nuthaus.mib.or g>,
                    >> Keith Thompson <kst-u@mib.org> wrote:[color=darkred]
                    >>> "David Resnick" <lndresnick@gma il.com> writes:
                    >>> [...]
                    >>>> This is all system specific, so OT in comp.lang.c. From what you are
                    >>>> saying,
                    >>>> I believe comp.unix.progr ammer 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>[/color]
                    >>
                    >> That should have been:
                    >>
                    >> <WRONG>
                    >> /proc is Linux-specific, though some other Unix-like systems may
                    >> provide something similar.
                    >> </WRONG>[/color]
                    >
                    > No, what Keith said is correct.[/color]

                    Actually, what Keith said is most definately NOT correct.
                    [color=blue][color=green]
                    >> Solaris has /proc, as do (I believe) over Unix flavors.[/color]
                    >
                    > Are you claiming that these Unix flavours are not like Unix?[/color]

                    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.



                    Comment

                    • Jordan Abel

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

                      On 2005-12-02, Joe Estock <jestock@NOSPAM nutextonline.co m> wrote:[color=blue]
                      > Kenny McCormack wrote:
                      > [usual crap]
                      >
                      > You're still alive Kenny? I thought someone would have killfiled you by now.[/color]

                      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]

                      Comment

                      • Keith Thompson

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

                        "Mark B" <sober@localbar .com> writes:[color=blue]
                        > "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
                        > news:dkm663xln4 .ln2@news.flash-gordon.me.uk...[color=green]
                        >> Kenny McCormack wrote:[color=darkred]
                        >>> In article <lnsltbe4ht.fsf @nuthaus.mib.or g>,
                        >>> Keith Thompson <kst-u@mib.org> wrote:
                        >>>> "David Resnick" <lndresnick@gma il.com> writes:
                        >>>> [...]
                        >>>>> This is all system specific, so OT in comp.lang.c. From what you are
                        >>>>> saying,
                        >>>>> I believe comp.unix.progr ammer 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>[/color]
                        >>
                        >> No, what Keith said is correct.[/color]
                        >
                        > Actually, what Keith said is most definately NOT correct.
                        >[color=green][color=darkred]
                        >>> Solaris has /proc, as do (I believe) over Unix flavors.[/color]
                        >>
                        >> Are you claiming that these Unix flavours are not like Unix?[/color]
                        >
                        > 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.[/color]

                        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.prog rammer) 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.solar is, 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_Keit h) kst-u@mib.org <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.

                        Comment

                        • John Devereux

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

                          Joe Estock <jestock@NOSPAM nutextonline.co m> writes:
                          [color=blue]
                          > Kenny McCormack wrote:
                          > [usual crap]
                          >
                          > You're still alive Kenny? I thought someone would have killfiled you by now.[/color]

                          Oh no! They killed Kenny!

                          --

                          John Devereux

                          Comment

                          • Kenny McCormack

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

                            In article <vY2kf.595437$_ o.124251@attbi_ s71>,
                            Joe Estock <jestock@NOSPAM nutextonline.co m> wrote:[color=blue]
                            >Kenny McCormack wrote:
                            >[usual crap]
                            >
                            >You're still alive Kenny? I thought someone would have killfiled you by now.
                            >
                            >Joe[/color]

                            Like a bad penny...

                            Comment

                            • Mark McIntyre

                              #15
                              Re: how to get statistics about memory usage ?

                              On Fri, 02 Dec 2005 20:17:37 +0000, in comp.lang.c , Flash Gordon
                              <spam@flash-gordon.me.uk> wrote:
                              [color=blue][color=green]
                              >> Solaris has /proc, as do (I believe) over Unix flavors.[/color][/color]

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

                              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 =----

                              Comment

                              Working...