D bindings for gperftools(Google Performance Tools)
Install google-perftools and graphviz
sudo apt-get install google-perftools libgoogle-perftools-dev graphviz
Install go and then install google-pprof.
go get github.com/google/pprof
Add gperftools_d
in dub.json
as a dependency.
"dependencies": {
"gperftools_d": "~>0.1.0"
}
Place the code you want to profile within ProfilerStart()
and ProfilerStop()
.
Example: In the examples/source/app.d
file:
import std.stdio;
import gperftools_d.profiler;
int fib(int x) {
if(x == 0){
return 0;
}
else if(x == 1){
return 1;
}
else{
return (fib(x-1) + fib(x-2));
}
}
void main() {
ProfilerStart(); // Profiling Starts
foreach (i; 0 .. 30) {
writeln(fib(i));
}
ProfilerStop(); // Profiling Stops
}
To profile:
dub --compiler=ldc2
CPUPROFILE=/tmp/prof.out <path/to/binary> [binary args]
pprof <path/to/binary> /tmp/prof.out # -pg-like text output
pprof --gv <path/to/binary> /tmp/prof.out # really cool graphical output
pprof --pdf <path/to/binary> /tmp/prof.out > profile.pdf # dump graphical output in profile.pdf
This software is distributed under the BSD 3-Clause License.
Copyright © 2017, Prasun Anand