Skip to content

prasunanand/gperftools_d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gperftools_d

D bindings for gperftools(Google Performance Tools)

Dub version Dub downloads

Installation

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

Performance Profiling

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

Example output:

Profile.pdf

LICENSE

This software is distributed under the BSD 3-Clause License.

Copyright © 2017, Prasun Anand

Packages

No packages published

Languages