Guppy-PE: A Python Programming Environment

# Guppy-PE

  # A Python Programming Environment

Guppy | A fish swimming in Python
Heapy | Heap Analysis Toolset
GSL | Guppy Specification Language
Documentation
Download
Credits
Contact

This is the home page for Guppy-PE , a programming environment providing object and heap memory sizing, profiling and analysis. It includes a prototypical specification language that can be used to formally specify aspects of Python programs and generate tests and documentation from a common source.

## Guppy

Guppy is an umbrella package combining Heapy and GSL with support utilities such as the Glue module that keeps things together.

The name guppy was chosen because I found it in a backward-dictionary as a word ending with py and I thought it was cute enough and that it would not so likely conflict with some other package name. It was to be a general name since all kinds of packages should fit under this top level name.

The name guppy-pe is because there was another project named guppy in Sourceforge when I was about to register guppy. The other guppy was not in Python, so I added -pe which means Programming Environment. The Python package is just guppy.

## Heapy

The aim of Heapy is to support debugging and optimization regarding memory related issues in Python programs.

Such issues can make a program use too much memory, making it slow by itself as well as slowing down an entire server, or it may fail to run at all in a limited memory device such as a mobile phone.

The primary motivation for Heapy is that there has been a lack of support for the programmer to get information about the memory usage in Python programs. Heapy is an attempt to improve this situation. A project with a similar intent is PySizer.

The problem situation has a number of aspects, which I think can be characterised, for example, as follows.

- What data about memory and objects to get from the system.
- How to get that data technically.
- How portable to be across platforms and versions.
- How to process data to compress it and find structure in it.
- How to present the resulting information to the user.
- How to make a coherent, useful & usable system of it all that doesn't interfer too much with the target system it is analysing.

As Heapy has evolved, with considerations like this in mind, it currently provides the following features.

### Data gathering

- Finds reachable and/or unreachable objects in the object heap, and collects them into special C-implemented 'nodesets'. Can get data about the objects such as their sizes and how they refer to each other.
- Uses a C library that can get data about non-standard types from extension modules, given a function table.
- Optionally uses multiple Python interpreters in the same process, so one can monitor the other transparently.

### Data processing

- Algebraic set operations, for example the set difference can be used to extract the objects allocated after a reference point in time.
- Various classifications of object sets, and different classifiers can be combined.
- Shortest paths to a set of objects from other objects, which can be used to find out why the objects are retained in memory.
- Calculation of the 'dominated' set from a set of root objects which yields the set of objects that would be deallocated if the root objects were deallocated.

### Presentation

- Tables where each row represents a classification of data.
- Lists of shortest paths where the edges show the relationships found between the underlying C objects.
- Reference pattern, presenting a spanning tree of the graph with sets of objects treated as a unit.
- Limits the number of rows when presentation objects are shown, without depending on an external pager.
- An interactive graphical browser program can show a time sequence of classified heap data sets as a graph together with a table detailing the data at a specific time or the difference between two points in time.

### Portability aspects

- Can be used with an unmodified C Python, back to version 2.3 AFAIK. Does not depend on any external unix-specific or other utilities.
- Requires Tk if the graphical browser is to be used.
- Can not be used with Jython or other non-C Python versions.

### System aspects

- A general 'glue' model provides a session context that imports modules and creates objects automatically when accessed. The glue model is not Heapy specific but is used throughout Guppy and could be used by other packages as well.
- The glue model makes it practical to have everything in Guppy being dynamically allocated in a session context, so there is no need for any global module-level variables. The modules themself are stored as usual in sys.modules but they are not modified.
- To be true there is one exception I come to think of but it is really exceptional.

Heapy has been used during development of itself and of the other parts of Guppy. It has been used to tell how much memory the parts of compound objects use, to see what could be worthwhile to optimize. It was used to find a memory leak in the Heapy profile browser, and to find out the cause, which as far as I can tell was due to a bug in a library routine which I have reported.

## GSL

The Guppy Specification Language is an evolving specification language. I started experimenting with this language because I felt the need to have a way to specify documentation and tests from the same source. GSL can describe aspects of a system, especially its API, in a way that can be automatically converted to tests as well as to documents. The documents generated have a formal structure for describing the formal aspects of the specification, complemented with descriptive text from the same source documents. A language that is similar in intent is the Assertion Definition Language .

Specifications written in GSL can be used for:

- Generating documentation

  Documents are generated from a combination of formally described aspects and descriptive text. The formal aspects include specifications of attributes and methods and their parameters and return values. The descriptive text is written together with the formal specifications. It can include HTML tags and attributes, specified in the GSL dotted tree format. Output modules can convert from the GSL form to formats such as HTML or Latex.

- Generating tests

  The tests generated can check the formal aspects of the specification against an implementation. It can test whether objects have the promised attributes, and then if the kind of attribute is specified it is tested again and so on. Methods are checked to see if they can be called with the forms of parameters specified. The return value can then be checked up to some limit of recursion.

- Resolving compatibility issues

  A specification can be compared to a previous specification, to tell according to formalized rules whether or not the new one is backwards compatible with the old one, and if not, in what way they differ. For example, according to such rules, an attribute or parameter type can be added to a specification, but it can not be removed. The idea is that all tests possibly generated from the old specification should still succeed with objects conforming to the new specification. -- A program could likely compare specifications for compatibility automatically, but this is not yet implemented.

GSL has been used to generate the documentation for this Guppy distribution. Some part of the specification has been checked against the implementation using the generated tests, which did reveal some discrepancies that were subsequently corrected.

The documents generated by GSL use a formal syntax to describe parameter modes. This document contains examples of such parameter descriptions and explains what they mean.

## Documentation

Some documentation is included with the source code distribution and can also be browsed here via the following links.

Getting started with Heapy | An example of how to get started with Heapy
Document example | Explains the meaning of some aspects of the documents.
Guppy | Specification of`guppy` , the top level module.
Profile Browser | How to use the graphical heap profile browser.
Screenshot | Example showing the graphical heap profile browser in action.
GSL | The Guppy Specification Language.
heapyc | Specification of the heapyc extension module. Note that this is an internal interface and may be subject to change.
sets | Specification of the interface to the setsc extension module which contains bitsets and nodesets.

The following documentation is not included with the source code.

heapy-thesis.pdf | The master's thesis, "Heapy: A Memory Profiler and Debugger for Python", which presents background, design, implementation, rationale and some use cases for Heapy (version 0.1).
Metadata and Abstract | Published at Linköping University Electronic Press.
heapy-presentation.pdf | Slides from the presentation.

### External resources

Thanks to all that have written about Heapy on various blogs. I think the following links may be especially useful to get started. More tips are very welcome!

- How to use guppy/heapy for tracking down memory usage (pkgcore - Trac)
- Debugging Django memory leak with TrackRefs and Guppy (Redi for Life)

## Download

The latest version is in the svn trunk directory.

In Version 0.1.9 I have introduced interactive help and compatibility for MS compilers (see ANNOUNCE and ChangeLog).

As of 2009-06-23, I have tested the latest revision successfully on an AMD64 in 64 bits mode with Ubuntu 7.10 with Python 2.3, 2.4, 2.5 and 2.6, and in 32 bits mode with Ubuntu 9.04 with Python 2.4, 2.5 and 2.6 .

To check out the latest (HEAD) revision, you can do:

    svn co https://guppy-pe.svn.sourceforge.net/svnroot/guppy-pe/trunk/guppy guppy

To check out the latest release as of this writing (2009-06-23, guppy-0.1.9), you can do:

    svn co -r79 https://guppy-pe.svn.sourceforge.net/svnroot/guppy-pe/trunk/guppy guppy

### Source code releases in tarball format

guppy-0.1.9 | Updated 2009-06-23. Added interactive help and improved MS compatibility.
guppy-0.1.8 | Updated 2008-04-08. Works with 64 bits and Python 2.6 .
guppy-0.1.6.tar.gz | Updated 2006-10-16. Doesn't work with 64 bits. -- Quick bug fix version, correcting the name of the Root object in the hpy instance. This is a kind of bug the automatic test generation should have catched, since it was specified with another name in the documentation, but I yet need some time to get that to work... so I am just uploading this quick fix now.
guppy-0.1.5.tar.gz | Updated 2006-10-12. Fixed bugs wrt remote monitoring and HTML rendering. New features include the shorthand sp for shpaths and representing the source of the shortest paths in terms of a Root object in the hpy instance. See changelog.
guppy-0.1.4.tar.gz | Updated 2006-10-11. Most changes are to make it work with Python 2.5; other changes include improved error reporting in Glue.py and some test improvements.
guppy-0.1.3.tar.gz | Updated 2006-03-02. Updates to Monitor so multiple lines work. It also got a command to interrupt the remote process. Cleanups and bugfixes especially todo with Python2.4 (used to crash with array objects). A bunch of other fixes, see changelog.
guppy-0.1.2.tar.gz | Pointer comparison bugs and test portability problems were fixed. See the included changelog.
guppy-0.1.1.tar.gz | The C source code for the extension modules was changed to be ANSI compatible and I also changed some help text that had become outdated.
guppy-0.1.tar.gz | Original version. Extension modules could not be compiled using strict ANSI C compilers.

## Credits

- Claudio Grondi has tested in Microsoft XP and reported the problems that occurred. The ANSI-compatibility problems I think have been fixed but there also seemed to be problems with the .NET C compiler which I haven't had a chance to sort out yet.
- Patrik Andersson has helped me installing Ubuntu Linux on my new computer and to make it dual-boot with Microsoft XP. (But we don't have any C compiler for Windows XP (yet).)
- Chad Austin has supplied a patch for compiling on Windows w/ Visual Studio 2003 and Python 2.5. I think this may fix similar problems with other MS compilers, Cygwin & Mingw as well.
- Yaroslav Halchenko is packaging and uploading Guppy into the Debian distribution.

## Contact

The author, Sverker Nilsson, may be contacted at:
I have registered a mailing list for discussions, questions, announcements etc. The list information, subscription form and archives are available at:
  http://lists.sourceforge.net/mailman/listinfo/guppy-pe-list
Please report bugs preferably via the SourceForge bug tracking system:
  http://sourceforge.net/tracker/?group_id=105577&atid=641821
The Sourceforge project summary page is:
  http://sourceforge.net/projects/guppy-pe

Generated by GSL-HTML 0.1.5 on Sat Jul 4 13:25:11 2009