[Python-Dev] tracemallocqt: GUI to analyze tracemalloc snapshots (original) (raw)

Victor Stinner victor.stinner at gmail.com
Fri Mar 14 00:54:38 CET 2014


Hi,

To prepare my conference on tracemalloc for Pycon Montréal next month, I wrote a GUI to analyze tracemalloc snapshots: "tracemallocqt". https://bitbucket.org/haypo/tracemallocqt

It looks like that:

http://www.haypocalc.com/tmp/tracemallocqt_python34.png

I'm looking for testers and feedback on the GUI. You may be curious to see which parts of Python is allocating the most memory, or maybe test your favorite application to check if it leaks memory or how its memory footprint can be reduced.

To run tracemallocqt, you have to install PySide and get tracemalloc snapshots. It looks like most Linux distributions provide PySide packages.

To take snapshots, see tracemalloc documentation: http://docs.python.org/dev/library/tracemalloc.html

In short, use Python 3.4 with "-X tracemalloc=25" command line option and then call:

import pickle, tracemalloc snap = tracemalloc.take_snapshot() with open("dump.pickle", "wb") as fp: pickle.dump(snap, fp, 2) snap = None

It's more fun with at least 2 snapshots to compare them ;-)

I force pickle version 2 because tracemallocqt currently only works on Python 2. (Mostly because I don't see how to get PySide for Python 3 on Fedora 20.)

Not all applications work on Python 3.4 right now, you can use the pytracemalloc project which is tracemalloc for Python 2.5-3.3. Sorry, you have to patch Python and recompile it. Here are instructions to install a patched Python 2.7 with tracemalloc: http://pytracemalloc.readthedocs.org/#manual-installation

If you don't want to take snapshot, you can compare these two files:

http://www.haypocalc.com/tmp/python34_start.pickle http://www.haypocalc.com/tmp/python34_after_import.pickle

The source browser will not find Python source code, because the snapshots contain absolute paths.

Victor



More information about the Python-Dev mailing list