Skip to content

Commit 0eadfaf

Browse files
committed
Merge pull request #78 from torbjoernk/feature/profiler-support
Sweet!
2 parents 6199696 + fecf574 commit 0eadfaf

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/doc/build
33
/build*
44
/dist
5+
/coverage
6+
*.info
57

68
# Created by http://www.gitignore.io
79

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ option(pfasst_DISABLE_LIBCXX "Disable use of LLVM's libc++ when compiling with C
1313
option(pfasst_BUILD_EXAMPLES "Build example programs." ON )
1414
option(pfasst_BUILD_TESTS "Build test suite for PFASST." ON )
1515
option(pfasst_WITH_MPI "Build with MPI enabled." OFF)
16+
option(pfasst_WITH_GCC_PROF "Enable excessive debugging & profiling output with GCC." OFF)
1617

1718
# Set output directories
1819
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${pfasst_SOURCE_DIR}/dist/bin")
@@ -32,6 +33,9 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
3233
else()
3334
message(FATAL_ERROR "No advanced standard C++ support of your GCC (-std=c++11 not defined).")
3435
endif()
36+
if(pfasst_WITH_GCC_PROF)
37+
add_to_string_list("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS "-ggdb3 -pg")
38+
endif(pfasst_WITH_GCC_PROF)
3539
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
3640
check_cxx_compiler_flag(-std=c++11 HAVE_STD11)
3741
if(HAVE_STD11)
@@ -101,6 +105,7 @@ if(pfasst_BUILD_TESTS)
101105
endif()
102106
message(STATUS "********************************************************************************")
103107

108+
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER}")
104109
message(STATUS "C++ Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
105110
message(STATUS "C++ Compiler Names: ${CMAKE_CXX_COMPILER_NAMES}")
106111
message(STATUS "C++ Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")

generate_coverage.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/sh
2+
basepath=`pwd`
3+
4+
function print_help {
5+
echo "#######################################################################"
6+
echo "### Generation of Test Coverage Report ###"
7+
echo "# #"
8+
echo "# This only works for builds made with GCC and the following CMake #"
9+
echo "# variables: #"
10+
echo "# -Dpfasst_WITH_GCC_PROF=ON -Dpfasst_BUILD_TESTS=ON #"
11+
echo "# #"
12+
echo "# First (and only) parameter must be the name of the build directory #"
13+
echo "# #"
14+
echo "# Example: #"
15+
echo "# ./generate_coverage.sh build_gcc #"
16+
echo "# #"
17+
echo "#######################################################################"
18+
return 0
19+
}
20+
21+
22+
if [[ $# -ne 1 ]]
23+
then
24+
print_help
25+
echo "ERROR: Please name the build directory as the first parameter."
26+
exit -1
27+
fi
28+
29+
builddir=${1}
30+
cd ${builddir}
31+
32+
rm -rf ${basepath}/coverage
33+
mkdir -p ${basepath}/coverage
34+
35+
for testdir in `find ${basepath}/${builddir} -type d | grep -o 'tests/.*/.*\dir'`
36+
do
37+
testname=`expr "$testdir" : '.*\(test_[a-zA-Z\-_]*\)\.dir'`
38+
echo "Gathering Coverage for ${testname}"
39+
cd $testdir
40+
lcov --zerocounters --directory .
41+
cd ${basepath}/${builddir}
42+
ctest -R $testname
43+
cd $testdir
44+
lcov --directory . --capture --output-file ${testname}.info.tmp
45+
lcov --extract ${testname}.info.tmp "*${basepath}/include/**/*" --output-file ${testname}.info
46+
rm ${testname}.info.tmp
47+
cd ${basepath}/${builddir}
48+
lcov --add-tracefile ${testdir}/${testname}.info --output-file all_tests.info
49+
done
50+
51+
cd ${basepath}
52+
genhtml --output-directory ./coverage \
53+
--demangle-cpp --num-spaces 2 --sort \
54+
--title "PFASST++ Test Coverage" --prefix ${basepath}/include \
55+
--function-coverage --branch-coverage --legend ${basepath}/${builddir}/all_tests.info

tests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ foreach(test ${TESTS})
1919
set_target_properties(${test}
2020
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests
2121
)
22+
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
23+
set_target_properties(${test}
24+
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
25+
LINK_FLAGS "-fprofile-arcs"
26+
)
27+
endif()
2228
add_test(NAME ${test}
2329
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/${test} --gtest_output=xml:${test}_out.xml
2430
)

tests/examples/advection_diffusion/CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ foreach(test ${TESTS})
3030
set_target_properties(${test}
3131
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/examples/advection_diffusion
3232
)
33+
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
34+
set_target_properties(${test}
35+
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
36+
LINK_FLAGS "-fprofile-arcs"
37+
)
38+
endif()
3339
add_test(NAME ${test}
3440
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/examples/advection_diffusion/${test} --gtest_output=xml:${test}_out.xml
3541
)
@@ -44,8 +50,15 @@ if(${pfasst_WITH_MPI})
4450
if(NOT FFTW_FOUND)
4551
add_dependencies(${test} googlemock fftw3)
4652
endif()
47-
if(MPI_COMPILE_FLAGS)
48-
set_target_properties(${test} PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
53+
if(MPI_COMPILE_FLAGS)
54+
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
55+
set_target_properties(${test}
56+
PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS} -ftest-coverage -fprofile-arcs"
57+
LINK_FLAGS "-fprofile-arcs"
58+
)
59+
else()
60+
set_target_properties(${test} PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
61+
endif()
4962
endif()
5063
if(MPI_LINK_FLAGS)
5164
set_target_properties(${test} PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")

tests/examples/scalar/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ foreach(test ${TESTS})
2020
set_target_properties(${test}
2121
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/examples/scalar
2222
)
23+
if(pfasst_WITH_GCC_PROF AND ${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
24+
set_target_properties(${test}
25+
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs"
26+
LINK_FLAGS "-fprofile-arcs"
27+
)
28+
endif()
2329
add_test(NAME ${test}
2430
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/examples/scalar/${test} --gtest_output=xml:${test}_out.xml
2531
)

0 commit comments

Comments
 (0)