Exploring the Call Graph

Contents

Internal Reports

The above example demonstrates that while the call graph contains some useful information, it does not afford a particularly usable interface. The Magma profiler contains some profile report generators which can be used to study the call graph in a more intuitive way.

The reports are all tabular, and have a similar set of columns:

(i)
Index: The numeric identifier for the function in the vertex list of the call graph.

(ii)
Name: The name of the function. The function name will be followed by an asterisk if a recursive call was made through it.

(iii)
Time: The time spent in the function; depending on the report, the meaning might vary slightly.

(iv)
Count: The number of times the function was called; depending on the report, the meaning might vary slightly.

ProfilePrintByTotalCount(G): GrphDir ->
    Percentage: BoolElt                 Default: false
    Max: RngIntElt                      Default: All
Print the list of functions in the call graph, sorted in descending order by the total number of times they were called. The Time and Count fields of the report give the total time and total number of times the function was called. If Percentage is true, then the Time and Count fields represent their values as percentages of the total value. If Max is set, then the report only displays the first Max entries.
ProfilePrintByTotalTime(G): GrphDir ->
    Percentage: BoolElt                 Default: false
    Max: RngIntElt                      Default: All
Print the list of functions in the call graph, sorted in descending order by the total time spent in them. Apart from the sort order, this function's behaviour is identical to that of ProfilePrintByTotalCount.
ProfilePrintChildrenByCount(G, n): GrphDir, GrphVert ->
ProfilePrintChildrenByCount(G, n): GrphDir, RngIntElt ->
    Percentage: BoolElt                 Default: false
    Max: RngIntElt                      Default: All
Given a vertex n in the call graph G, print the list of functions called by the function n, sorted in descending order by the number of times they were called by n. The Time and Count fields of the report give the time spent during calls by the function n and the number of times the function was called by the function n. If Percentage is true, then the Time and Count fields represent their values as percentages of the total value. If Max is set, then the report only displays the first Max entries.
ProfilePrintChildrenByTime(G, n): GrphDir, GrphVert ->
ProfilePrintChildrenByTime(G, n): GrphDir, RngIntElt ->
    Percentage: BoolElt                 Default: false
    Max: RngIntElt                      Default: All
Given a vertex n in the call graph G, print the list of functions in the called by the function n, sorted in descending order by the time spent during calls by the function n. Apart from the sort order, this function's behaviour is identical to that of ProfilePrintChildrenByCount.

Example Prof_profile-reports (H7E2)

Continuing with the previous example, we examine the call graph using profile reports.
> ProfilePrintByTotalTime(G);
Index Name                                                     Time    Count
1     <main>                                                   10.940  1
2     fibonacci                                                10.940  392835
3     eq(<RngIntElt> x, <RngIntElt> y) -> BoolElt              1.210   710646
4     -(<RngIntElt> x, <RngIntElt> y) -> RngIntElt             0.630   392834
5     +(<RngIntElt> x, <RngIntElt> y) -> RngIntElt             0.250   196417
6     Fibonacci(<RngIntElt> n) -> RngIntElt                    0.000   1
7     SetProfile(<BoolElt> v)                                  0.000   1
> ProfilePrintChildrenByTime(G, 2);
Function: fibonacci
Function Time: 10.940
Function Count: 392835
Index Name                                                     Time    Count
2     fibonacci (*)                                            182.430 392834
3     eq(<RngIntElt> x, <RngIntElt> y) -> BoolElt              1.210   710645
4     -(<RngIntElt> x, <RngIntElt> y) -> RngIntElt             0.630   392834
5     +(<RngIntElt> x, <RngIntElt> y) -> RngIntElt             0.250   196417
* A recursive call is made through this child

HTML Reports

While the internal reports are useful for casual inspection of a profile run, for detailed examination a text-based interface has serious limitations. Magma's profiler also supports the generation of HTML reports of the profile run. The HTML report can be loaded up in any web browser. If Javascript is enabled, then the tables in the report can be dynamically sorted by any field, by clicking on the column heading you wish to perform a sort with. Clicking the column heading multiple times will alternate between ascending and descending sorts.

ProfileHTMLOutput(G, prefix): GrphDir, MonStgElt ->
Given a call graph G, an HTML report is generated using the file prefix prefix. The index file of the report will be "prefix.html", and exactly n additional files will be generated with the given filename prefix, where n is the number of functions in the call graph.
V2.28, 13 July 2023