Goto Chapter: Top 1 2 Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

1 Tutorial
 1.1 Line By Line Profiling
 1.2 FAQ / Problems
 1.3 Function-Based Profiling

1 Tutorial

1.1 Line By Line Profiling

The purpose of this section is to show how to use GAP's line-by-line profiler / code coverage. For this, you need GAP 4.8 or newer.

Do you just care which lines of code are executed? Then you should switch to the coverage guide (these two guides are very similar!)

We will start with a quick guide to profiling, with some brief comments. We will explain later how to do these things in greater depth!

Let's start with some code we want to profile. Here I am going to profile the function f given below, and use a group from the AtlasRep package.

a := AtlasGroup("U6(2)", NrMovedPoints, 12474);
b := a^(1,2,3);
f := function() Intersection(a,b); end;

Firstly, we will record a profile of a function f:

# Code between ProfileLineByLine and UnprofileLineByLine is recorded
# to a file output.gz
ProfileLineByLine("output.gz"); f(); UnprofileLineByLine();

You should write this all on a single line in GAP, as profiling records the real time spent executing code, so time spent typing commands will be counted.

This creates a file called output.gz, which stores the result of running f. Now we want to turn that into a nice output. This requires loading the profiling package, like this:

OutputAnnotatedCodeCoverageFiles("output.gz", "outdir");

If loading the profiling package produces errors, make sure you have compiled both the profiling and IO packages.

OutputAnnotatedCodeCoverageFiles (2.3-1) reads the previously created output.gz and produces HTML output into the directory outdir.

You must view the result of your profiling in a web-browser outside of GAP. Open index.html from the outdir directory in the web browser of your choice to see what happened.

At the very top is a link to a flame graph. These give a quick overview of this functions took the most time. Functions are stacked, so lower functions call higher functions.

From this graph we can see that f called Intersection (Reference: Intersection), which called a function without a name at line 2942 in This function spent most of its time in PartitionBacktrack, and a little time in Stabilizer.

Whenever you generate a profile which contains timing information, a flame graph link will be show on the first page of your generated profile!

1.2 FAQ / Problems

1.3 Function-Based Profiling

Sometimes you will have code that just runs too long to easily profile line by line. You can profile this in GAP older function-based profiler. You can read more about this profiler in GAP's documentation, but here is a quick example to get you going!

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 Ind

generated by GAPDoc2HTML