This is a DMD compilation time profiler. It allows profiling and visualizing which parts of the D code take up most of the time compiling.
Click image above for working tooltips and hyperlinks.
Example taken from here.
-
Build a debug DMD, e.g. using
make -f posix.mak BUILD=debug
in dmd/src. -
Run the debug DMD you built under GDB, and pass the program to compile and profile:
$ gdb --args .../dmd/generated/linux/debug/64/dmd -o- your_program.d
If you use a build tool like rdmd or Dub, you need to first find the dmd invocation it uses, then use that. Try enabling verbose output.
-
Load the
dmdprof.py
GDB script from this repository:(gdb) source path/to/dmdprof.py
-
Run the profiler:
(gdb) python DMDProfiler().profile()
You can optionally specify a sampling interval:
(gdb) python DMDProfiler(0.001).profile()
The sampling interval specifies the duration (in seconds) between samples taken. The default is 0.01, and the lowest possible value is 0, meaning to take samples as quickly as possible.
Note that currently GDB leaks about 15-30 MB of memory per sample (!), so watch your memory usage to avoid crashing your machine.
The profiler will save the results to a
profile.json
file. -
Use gprof2dot to generate a GraphViz .dot file, pipe it through the
linkify
program in this repository, and pipe the result intodot
:./gprof2dot.py -f json path/to/profile.json --root=-2:-2 -n 2 -e 0 | rdmd path/to/linkify.d | dot -Tsvg > profile.svg
Adjust gprof2dot
-n
parameter to taste.To generate correct, permanent links in the output file, you can specify Phobos and Druntime versions as Git commit SHA1s or tag names using the
--phobos
and--druntime
arguments tolinkify
.