forked from ofiwg/libfabric
-
Notifications
You must be signed in to change notification settings - Fork 9
Building and profiling with gperftools
Evan Harvey edited this page Mar 17, 2017
·
11 revisions
- Change to the directory where you want to build gperftools.
- Download and run the build script found here: https://gist.github.com/e-harvey/ac98dea070fec4a73ef9c48434e23c9c#file-install_gperftools-sh.
We need to build libfabric and the application with the gcc flag -fno-omit-frame-pointer
. See https://github.com/gperftools/gperftools/blob/master/INSTALL for more information.
- Building libfabric
./autogen.sh && ./configure CFLAGS="-fno-omit-frame-pointer" --prefix="$PWD/libfabric-test" && make clean && make -j install
- Use the
--with-profiler
option during the cray-tests configure step./autogen.sh && ./configure --prefix=$PWD/../cray-tests-build --with-libfabric=$PWD/../libfabric-test --with-pmi=/opt/cray/pmi/default --with-profiler=/path/to/gperftools-build && make -j install
./configure CFLAGS=-fno-omit-frame-pointer CPPFLAGS=-I"$PWD/gperftools-build/include/" LDFLAGS=-L"$PWD/lib/" LIBS=-lprofiler
- We need to manually compile a separate source file with a main function since pprof uses the binary to generate the profiling output. Using gnitest as the binary does not work. Here is an example of how the source code should look https://github.com/ofi-cray/cray-tests/blob/master/contrib/buddy_test.c. Note that you need to include
<gperftools/profiler.h>
. - Once you have your source code and your calls to
ProfilerStart("name.prof") and ProfilerStop()
where you want them and have built libfabric in$PWD/libfabric-build
compile it like this on tiger:gcc -fno-omit-frame-pointer -Wall `pkg-config cray-ugni --cflags --libs` `pkg-config cray-gni-headers --cflags --libs` `pkg-config cray-udreg --cflags --libs` -I $PWD/gperftools-build/include/ -I $PWD/libfabric-cray/include/ -I $PWD/prov/gni/include/ -L$PWD/libfabric-build/lib/ -L$PWD/gperftools-build/lib/ -I $PWD/libfabric-cray -lfabric -lprofiler buddy_test.c -o buddy_test $PWD/libfabric-build/lib/libfabric.a
- To profile the entire application:
export CPUPROFILE=ProfileName.prof
-
export CPUPROFILE_FREQUENCY=1000000
(this can be increased to have the profiler peek at the top of the call stack more frequently) - Run it manually or with a job launcher
pprof --text a.out buddy.test
- Don't forget to include gperftools/gperftools.h.
- Wrap the section of code you're interested in in ProfilerStart("ProfileName.prof") and ProfilerStop().
- Remember that if the job runs multiple ranks/threads/messageSizes and the ProfileName.prof is named the same for each rank/thread/messageSize the last instance to run will stomp on all the other profiles.
- The cpu profiler should work with multiple threads, according to the gperf documentation. However, sometimes the profiles show calls to pthread routines even if the
ProfileStart
andProfileStop
calls are wrapped around code that doesn't call into pthread. - There are many more output types and additional options for using the profiler that can be found here: http://htmlpreview.github.com/?https://github.com/gperftools/gperftools/blob/master/docs/cpuprofile.html.