Skip to content

Instantly share code, notes, and snippets.

@JasonQSY
Last active September 24, 2017 23:47
Show Gist options
  • Save JasonQSY/91292308d3f0b6ccf28d280995252d10 to your computer and use it in GitHub Desktop.
Save JasonQSY/91292308d3f0b6ccf28d280995252d10 to your computer and use it in GitHub Desktop.

Set up gperftools

Installation

OS X

Make sure you have Xcode command line tools (e.g. clang++), brew and go.

# optional
brew install llvm

# pprof is its dependency
brew install gperftools
go get github.com/google/pprof

Linux

# compile gperftools from source code
git clone https://github.com/gperftools/gperftools.git
cd gperftools
./autogen.sh
./configure
make && make check
make install

# install pprof
go get github.com/google/pprof

Time

# compile 
clang++ -std=c++17 -Og -g3 -Wl,-no_pie -lprofiler puzzle.cpp -o puzzle # OS X
g++ -std=c++17 -Og -g3 -lprofiler puzzle.cpp -o puzzle # linux

# run
env CPUPROFILE=puzzle.prof ./puzzle -qo list < huge2.txt > output.txt

# report
pprof --list=main puzzle.prof

Memory

# compile
clang++ -std=c++17 -Og -g3 -Wl,-no_pie -ltcmalloc puzzle.cpp -o puzzle # OS X
g++ -std=c++17 -Og -g3 -ltcmalloc puzzle.cpp -o puzzle # linux

# run
env HEAPPROFILE=puzzle.prof ./puzzle -qo list < huge2.txt > output.txt

# report (specify the largest heap prof file)
pprof --list=main puzzle.prof.0003.heap

Tips

  • You may need check the GOPATH and find the pprof installed by go get. Use pprof installed by go.
  • If you do not have root access, you need specify prefix and library path for profiler and tcmalloc.

Contributors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment