Debugging Gramps

From Gramps
Revision as of 14:01, 5 March 2009 by Bmcage (talk | contribs)
Jump to: navigation, search

This page gives an overview on how to debug GRAMPS.

Hard crash

When a hard crash occurs, you typically have no idea where the crash occurs. It is important to know the line where the crash occurs. So if you are able to reproduce the crash, restart GRAMPS with the command:

python -m trace -t src/

Add debug statements

GRAMPS is run with the optimize flag.

python -O

This gives you the option of adding debug statements. You can use the __debug__ variable or the assert statement for this. This allows us to add code to GRAMPS that will be printed out when GRAMPS runs without the optimize flag:


More info: [1]

Use the log infrastructure

GRAMPS has built in the python log infratructure. GRAMPS runs with logging level logging.DEBUG to stderrh.

More info: Logging system

Short: in your code add data to the logger with: log.warning(), log.error(), Start Gramps with the --debug flag: python --debug="name_of_the_logger"

This is useful when working in different parts, adding info output, and selecting on the commandline with --debug the logger you want to see output with.

Use profiling

GRAMPS has a convenience hook to allow you to do profiling. Profiling gives an overview how many times methods are called in a code fragment and how long each one took. It helps to find perfermance bottlenecks.

An example usage:

Add at the top of the file you want to use profiling:

from Utils import profile

Then, suppose you want to profile a save function on one of the editors. The save is called due to a connect done in the method _connect_signals. So, change the connect to save to a new method testsave you make:

self.define_ok_button("ok"), self.testsave)

Now add the testsave function as follows, where you use the profile convenience function:

   def testsave(self, *obj):
       profile(, *obj)

Then run gramps, everytime you save, the profiler kicks in and prints to command line a report with the time for each function.

So in short: replace the call to a function/method to calling profile with as first parameter the function/method, and other parameters the parameters of the function/method.

That's it

Use the winpdb python debugger

Note: there are some issues with the winpdb debugger. For a workaround see bug ticket: 2564

Winpdb (Ubuntu: sudo apt-get install winpdb) is a graphical interface for the python debugger. Start it with:

winpdb src/
Winpdb with GRAMPS loaded
Now, in File menu, select 'Open Source', and open the source file you want to debug. Now all debug options are possible. Eg, go to a line in the file with the cursor, and click the run to line button. The debugger will run to that point, and left show you all defined local variables with their value, as well as the stack frame.

Try it!