Development Team/Memory/Leak testing

These are instructions on how to test for memory leaks in Sugar.

Install guppy
If you don't already have guppy on the XO (or other computer running sugar) you want to test, you'll have to download and install it. In Terminal, as root:

wget http://dev.laptop.org/~tomeu/guppy-0.1.9-1.i386.rpm rpm -i guppy-0.1.9-1.i386.rpm

Edit /usr/bin/sugar-shell with

(or whatever your favorite text editor is) and add a line that reads

Then restart Sugar (ctrl-alt-erase).

Starting a heapy session
ssh into the XO (or othe rcomputer running sugar) from another computer. We'll call this the Monitor Computer, and it should be separate from the XOs or cumputers you are testing. When we observe Sugar, it is best not use it for anything else than to execute the test case. From your Monitor computer, in the shell you're ssh'd into your XO with:

su - olpc python -c "from guppy import hpy;hpy.monitor" sc 1 int

Running a test
From your monitor computer:

Then, on your XO (or computer with sugar), do whatever action you're testing memory leaks for. (For instance, start and then close an Activity.)

Go back to your monitor computer and type:

Reading the results
You'll see a table that looks like this:

hp.heap prints a summary of the contents of the python heap, which is where python places objects we ask it to create. The most interesting part is this line:

This would mean that, since the last time we called hp.setref, 219 new objects have been placed on the heap and they take up 18212 bytes in total. This doesn't necessarily mean we are leaking all these 219 objects, though - but if you repeat this procedure several times...

and you see the amount of bytes growing steadily, we may have a bug. Look at anything that is over 10kb or so.

Repeated leak testing
A more definite test for leaks is the following:

...and then look for new objects in quantities that are multiple of 9. Those will probably be leaks.

Without collaboration
If you run a test multiple times and get results with a lot of variance, it may be due to collaboration activity (especially if you're in a radio-noisy environment). You can solve this by disabling radio (in the Sugar Control Panel) and using an usb-to-ethernet dongle to give the XO or computer a wired connection to ssh into.