Usage
Once everything is set up
By default, scalac-profiling
generates the graph representation of the
implicit searches happening during compilation, and optionally of the macro
expansions separately by enabling proper compiler plugin option
(check the available compiler plugin options).
To be more precise, the compiler plugin does not generate the graphs for you; instead,
it persists the graph data in a format that allows you to generate the graphs yourself
without touching or transforming the data. That graph data is present under the
profiledb META-INF directory, located in the classes directory. For example,
a flamegraph data file will be located at
/target/scala-2.13/classes/META-INF/profiledb/graphs/implicit-searches-X.flamegraph
.
The resulting graphs are obtained by using the FlameGraph tool. They are intuitive to inspect and browse, and stand out because:
- They allow you to selectively choose what things to profile. Click on every stack to zoom in, and reset by clicking "Reset zoom" on the bottom left.
- They allow you to search via regexes and those matching stacks are highlighted. Check the search button on the top right.
Lastly, how to generate a flamegraph?
In order to generate flamegraphs, clone the scalac-profiling
GitHub repository. The repository contains the FlameGraph
git submodule consisting
of the tools to generate the SVG files that you will later use. Once the prepared
data is generated by the compiler plugin (.flamegraph
file):
cd
into theexternal/Flamegraph
directory;- Execute the
git submodule update --init
; - And run the following command in the
FlameGraph
project's root directory:
./flamegraph.pl \
--hash --countname="μs" \
--color=scala-compilation \
$PATH_TO_FLAMEGRAPH_DATA > implicit-searches-graph.svg
The resulting graph will look like this one we generated for the Scala Steward project:
Reading the graphs
A graph is a set of nodes and edges. A node represents an implicit search for a given type. Every node specifies how many implicit searches have been triggered in total, and how long they took in total. An edge represents the dependency between an implicit search and another one.
It is important to note that every node in a program can be relied upon by other nodes and can serve as the starting point for an implicit search. Therefore, the number of times a node has been searched for may not always be equal to the total number of nodes that depend on it.