Quantcast
Channel: Planet Sage
Viewing all articles
Browse latest Browse all 414

Titus Nicolae: Profiling script

$
0
0

To find bottlenecks in Pynac I have created a profiling script. I will use it on some representative programs for Pynac from the Sage wiki page symbench.
I am running the profiling script as a Sage program. This way Sage isn’t called multiple times and the startup initialization overhead is avoided. Doing this while not using separate processes led to Sage programs sharing their variables/functions. To avoid this issue each program needs to be encapsulated in a function. If each program is in a separate file you can execute it with execfile(<sageprogram.py>,{}), with an empty dict for the global variables parameter.
For profiling I need Python files of the sage programs. To generate these I use sage -preparse *.sage
The profiling script uses Callgrind to get an accurate result, although it has a significant overhead. The script profiles multiple files by running each of them in a separate process.Callgrind creates a separate output file for each process when using --trace-children option.
The Sage initialization is not profiled because the Callgrind instrumentation is off when the script starts. This is done with the option --instr-atstart=no. Starting and stopping the instrumentation during the profiling avoids recording calls not related to the profiled file, and also runs faster.
I will use KCachegrind to interpret the output from Callgrind.


Viewing all articles
Browse latest Browse all 414

Trending Articles