How to measure memory footprint of Python objects?

N

Neagu, Adrian

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.
 
P

Paul Rubin

Neagu said:
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.
 
A

AdrianNg3

Paul said:
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.
 
H

Heikki Toivonen

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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top