[Baypiggies] [Fwd: [PyOP] find memory leaks in running program]

Bill Janssen janssen at parc.com
Wed Dec 8 03:03:01 CET 2010


marco> ------------------------------------------------------------------------------------------
marco> questions
marco> ------------------------------------------------------------------------------------------
marco> 1. What are the best tools to analyze pythons memory stack,
marco> while it is running?  2. Is there a possibility to analyze the
marco> memory stack of a program with external programs? (without to
marco> change the source code - I am only interested in the object
marco> size) 3. Can I sort of "break" into the memory to see what
marco> objects consume how much memory?

Tough without adding some sort of trace.

What I use is Guppy, or actually Heapy.  I added a thread to my Python
program which runs something like this:

      while True:
          heap = hpy().heap()
          outputfile.write("-=--=--=--=--=- %s\n" % time.time())
          heap.dump(outputfile)
          time.sleep(5 * 60)

Then you've got a logfile that shows you the state of the heap as your
program progresses.  You've still got to write a program to parse the
logfile, but at least you have data.

Might be able to start a thread like this using gdb to attach to a
remote process and start the new thread, too.

http://guppy-pe.sourceforge.net/#Guppy

See also <http://mg.pov.lt/blog/hunting-python-memleaks>.

Bill


More information about the Baypiggies mailing list