How to measure memory footprint of Python objects?

Discussion in 'Python' started by Neagu, Adrian, Sep 20, 2006.

  1. Hello everybody,

    I try to solve the following problem: I have a python program that takes a
    lot of memory (>hundred Mb). I made an improvement (I hope) and I want to
    measure the gain (if possible on several platforms). I would like to be able
    to print the max memory taken during the run upon exiting my Python program
    (like I already do for the time taken to run).

    I can see the total process size of the Python process (Task manager on MS
    Win or Unix "ps" command) but that is not precise enough for me and also not
    convenient. I don't care about the python interpreter overhead, I'm
    interested only in the total size of Python objects allocated by my program.
    Is there a Python way to get that (meaning without resorting to
    non-portable, less precise OS features)?

    I would like to get that size at different given moments in time to make up
    a timeline of memory consumption. But, if that is too tricky, I would be
    happy to just get the maximum.

    Any suggestion welcome,
    Adrian.
    Neagu, Adrian, Sep 20, 2006
    #1
    1. Advertising

  2. Neagu, Adrian

    Paul Rubin Guest

    "Neagu, Adrian" <> writes:
    > I would like to get that size at different given moments in time to make up
    > a timeline of memory consumption. But, if that is too tricky, I would be
    > happy to just get the maximum.
    >
    > Any suggestion welcome,


    See the docs for the gc module.
    Paul Rubin, Sep 20, 2006
    #2
    1. Advertising

  3. Neagu, Adrian

    AdrianNg3 Guest

    Paul Rubin wrote:
    > See the docs for the gc module.


    This is the first place I've checked. I see no useful info there about
    the actual size of the objects (bytes occupied in memeory).

    The closest thing to what I need is get_objects( ). Then I have to go
    over the list
    and do something with the objects. Wouldn't that be too slow?

    Thanks anyway,
    Adrian.
    AdrianNg3, Sep 20, 2006
    #3
  4. Neagu, Adrian wrote:
    > I try to solve the following problem: I have a python program that takes a
    > lot of memory (>hundred Mb). I made an improvement (I hope) and I want to
    > measure the gain (if possible on several platforms). I would like to be able
    > to print the max memory taken during the run upon exiting my Python program
    > (like I already do for the time taken to run).


    You could try PySizer: http://pysizer.8325.org/

    --
    Heikki Toivonen
    Heikki Toivonen, Sep 21, 2006
    #4
    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. Beatrice Rutger

    JMS memory footprint size

    Beatrice Rutger, Jun 5, 2005, in forum: Java
    Replies:
    0
    Views:
    357
    Beatrice Rutger
    Jun 5, 2005
  2. gbrun
    Replies:
    1
    Views:
    446
    Andrey Kuznetsov
    Feb 19, 2006
  3. Adam Warner

    Memory footprint of a subclass

    Adam Warner, Feb 27, 2006, in forum: Java
    Replies:
    3
    Views:
    632
    Adam Warner
    Feb 27, 2006
  4. Fredrik Lundh
    Replies:
    1
    Views:
    347
    AdrianNg3
    Sep 20, 2006
  5. nick
    Replies:
    58
    Views:
    1,916
    Bart van Ingen Schenau
    Mar 16, 2009
Loading...

Share This Page