From 3e974e6b9af1bbca0d40c653fabdade1a6666bb7 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Wed, 26 Jun 2019 12:26:13 +0200 Subject: [PATCH 01/18] Adding possibility to plug flamegraphes in rootbench --- CMakeLists.txt | 6 +++--- cmake/modules/AddRootBench.cmake | 11 +++++++---- cmake/modules/RootBenchOptions.cmake | 3 ++- rootbench-scripts/flamegraph.sh | 0 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100755 rootbench-scripts/flamegraph.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d82b032f..bbc416f91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,9 @@ set(CMAKE_MODULE_PATH #Define ROOTbench source tree set(ROOTBENCH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +#---Include rootbench options +include(RootBenchOptions) + include(AddRootBench) # You need first to tell CMake where to find the ROOT installation. This can either be the @@ -56,9 +59,6 @@ include(PytestBenchmark) include_directories(${ROOT_INCLUDE_DIRS}) add_definitions(${ROOT_CXX_FLAGS}) -#---Include rootbench options -include(RootBenchOptions) - #---Enable test coverage ----------------------------------------------------------------------- if(coverage) set(GCC_COVERAGE_COMPILE_FLAGS "-g -fprofile-arcs -ftest-coverage") diff --git a/cmake/modules/AddRootBench.cmake b/cmake/modules/AddRootBench.cmake index 2b0f6144d..2d80dea19 100644 --- a/cmake/modules/AddRootBench.cmake +++ b/cmake/modules/AddRootBench.cmake @@ -45,10 +45,13 @@ function(RB_ADD_GBENCHMARK benchmark) # to implement because some ROOT components create more than one library. target_link_libraries(${benchmark} ${ARG_LIBRARIES} gbenchmark RBSupport rt) #ROOT_PATH_TO_STRING(mangled_name ${benchmark} PATH_SEPARATOR_REPLACEMENT "-") - #ROOT_ADD_TEST(gbench${mangled_name} - # COMMAND ${benchmark} - # WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} - # LABELS "benchmark") + if(ARG_POSTCMD) + set(postcmd POSTCMD ${ARG_POSTCMD}) + endif() + if(flamegraph) + set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh") + add_dependencies(${benchmark} flamegraph-download) + endif() if(${ARG_LABEL} STREQUAL "long") set(${TIMEOUT_VALUE} 1200) elseif($ARG_LABEL STREQUAL "short") diff --git a/cmake/modules/RootBenchOptions.cmake b/cmake/modules/RootBenchOptions.cmake index 9829657d7..b98acb1a9 100644 --- a/cmake/modules/RootBenchOptions.cmake +++ b/cmake/modules/RootBenchOptions.cmake @@ -4,4 +4,5 @@ # # TBD: to introduce special function for options (similar to root.git) #---------------------------------------------------------------------------- option(coverage OFF) -option(rootbench-datafiles OFF) \ No newline at end of file +option(rootbench-datafiles OFF) +option(flamegraph "FlameGraph generation option" OFF) diff --git a/rootbench-scripts/flamegraph.sh b/rootbench-scripts/flamegraph.sh new file mode 100755 index 000000000..e69de29bb From 05addd42c2cc8d36455d9c273293a61704d12b6d Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Wed, 26 Jun 2019 12:58:33 +0200 Subject: [PATCH 02/18] Add FlameGraph sources in rootbench project --- CMakeLists.txt | 5 +++++ cmake/modules/FlameGraph.cmake | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 cmake/modules/FlameGraph.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index bbc416f91..f05e02239 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,11 @@ endif() include(GoogleBenchmark) include(PytestBenchmark) +if(flamegraph) + include(FlameGraph) + add_custom_target(flamegraph-download DEPENDS FlameGraph) +endif() + #---Add ROOT include direcories and used compilation flags include_directories(${ROOT_INCLUDE_DIRS}) add_definitions(${ROOT_CXX_FLAGS}) diff --git a/cmake/modules/FlameGraph.cmake b/cmake/modules/FlameGraph.cmake new file mode 100644 index 000000000..fdec6afff --- /dev/null +++ b/cmake/modules/FlameGraph.cmake @@ -0,0 +1,11 @@ +include(ExternalProject) + +ExternalProject_Add(FlameGraph + GIT_REPOSITORY "https://github.com/brendangregg/FlameGraph.git" + UPDATE_COMMAND "" + PATCH_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + EXCLUDE_FROM_ALL 1 +) From ea7e65321245072c780ad26b23718b8cddb43202 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Wed, 26 Jun 2019 13:11:00 +0200 Subject: [PATCH 03/18] Adding /usr/bin/time and perf as dependencies to rootbench --- CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f05e02239..086bc3094 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ) -#Define ROOTbench source tree +#---Define ROOTbench source tree set(ROOTBENCH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) #---Include rootbench options @@ -21,6 +21,12 @@ include(RootBenchOptions) include(AddRootBench) +#---ROOTbench dependencies +find_program(TIME_EXECUTABLE time) +if(NOT TIME_EXECUTABLE) + message(WARNING "/usr/bin/time is requirement for rootbench.git") +endif() + # You need first to tell CMake where to find the ROOT installation. This can either be the # final ROOT installation or a local build directory. In both cases it is using # the $ROOTSYS environment variable to locate it. @@ -56,6 +62,12 @@ include(GoogleBenchmark) include(PytestBenchmark) if(flamegraph) + # Check if perf is available in OS: + find_program(PERF_EXECUTABLE perf) + if(NOT PERF_EXECUTABLE) + message(WARNING "Perf is not available in your system, please install it.") + set(flamegraph OFF CACHE BOOL "") + endif() include(FlameGraph) add_custom_target(flamegraph-download DEPENDS FlameGraph) endif() From 9212764b86b673ba9d57f65c216651173a724dc4 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Tue, 2 Jul 2019 16:33:12 +0300 Subject: [PATCH 04/18] Update CMakeLists.txt with better message for flamegraph option Co-Authored-By: Vassil Vassilev --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 086bc3094..ad7501d68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ if(flamegraph) # Check if perf is available in OS: find_program(PERF_EXECUTABLE perf) if(NOT PERF_EXECUTABLE) - message(WARNING "Perf is not available in your system, please install it.") + message(WARNING "Perf is not available in your system, please install it. Turning off the flamegraph option.") set(flamegraph OFF CACHE BOOL "") endif() include(FlameGraph) From 0e2f18813a7455b6a261769c2b835233fecb2b54 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Tue, 2 Jul 2019 15:39:41 +0200 Subject: [PATCH 05/18] Update logic for flamegraph option --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad7501d68..99970f852 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,11 +65,12 @@ if(flamegraph) # Check if perf is available in OS: find_program(PERF_EXECUTABLE perf) if(NOT PERF_EXECUTABLE) - message(WARNING "Perf is not available in your system, please install it. Turning off the flamegraph option.") + message(WARNING "Perf is not available in your system, please install it.") set(flamegraph OFF CACHE BOOL "") + else() + include(FlameGraph) + add_custom_target(flamegraph-download DEPENDS FlameGraph) endif() - include(FlameGraph) - add_custom_target(flamegraph-download DEPENDS FlameGraph) endif() #---Add ROOT include direcories and used compilation flags From b1d8175e922401bd1726222659340db5e8d965fa Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Tue, 2 Jul 2019 15:48:32 +0200 Subject: [PATCH 06/18] Add tests for time -v --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99970f852..7769f1609 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,12 @@ include(AddRootBench) #---ROOTbench dependencies find_program(TIME_EXECUTABLE time) +# Testing valid output of /usr/bin/time -v +exec_program(${TIME_EXECUTABLE} ARGS -v ${CMAKE_COMMAND} -E environment OUTPUT_VARIABLE TIME_OUTPUT RETURN_VALUE TIME_EXECUTABLE_VALID) if(NOT TIME_EXECUTABLE) - message(WARNING "/usr/bin/time is requirement for rootbench.git") + if(NOT TIME_EXECUTABLE_VALID) + message(FATAL_ERROR "/usr/bin/time is a requirement for rootbench.git") + endif() endif() # You need first to tell CMake where to find the ROOT installation. This can either be the From 891dbc6fce990bf2961fff5ad75f5209cfd9df7a Mon Sep 17 00:00:00 2001 From: HLilit Date: Wed, 3 Jul 2019 14:46:31 +0200 Subject: [PATCH 07/18] Flamegraph bash script It could be invocated from Cmake or as a standalone. --- rootbench-scripts/flamegraph.sh | 183 ++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/rootbench-scripts/flamegraph.sh b/rootbench-scripts/flamegraph.sh index e69de29bb..5137ce698 100755 --- a/rootbench-scripts/flamegraph.sh +++ b/rootbench-scripts/flamegraph.sh @@ -0,0 +1,183 @@ +#!/bin/bash + + +BENCHMARKPATTERN="*benchmark*" +ROOTBENCHBUILDDIR=$1 #/home/lharutyu/ROOT/rootbench-build2 # Enter path to rootbench-build folder +shift +FLAMEGRAPHBASEDIR=$ROOTBENCHBUILDDIR/FlameGraph + +MKDIR=/bin/mkdir +BASENAME=/usr/bin/basename +DIRNAME=/usr/bin/dirname +FIND=/usr/bin/find +SED=/bin/sed +PERF=/usr/bin/perf +STACKCOLLASE=stackcollapse-perf.pl +FLAMEGRAPG=flamegraph.pl + + +usage() +{ + echo + echo "--------------------------FlameGraph Generator---------------------------" + echo + echo "Usage: $0 [OPTION]..." + echo "This script generates FlameGraphs for benchmarks !!!" + echo " Enter path/to/rootbench/build/dir" + echo "OPTIONS" + echo " -b, --benchmarkfile path Location of ROOT benchmark file" + echo " -a, --all Create all benchmarks." + echo " -h, --help Display this help and exit" +} + +usage_short() +{ + echo "FlameGraph Generator" + echo "Usage: $0 [path/to/rootbench/build/dir] [-b |--benchmarkfile filepath] [-a | --all] [-h | --help]" +} + +get_bm_fn() +{ + if [ ! -f $1 ] ; then + echo "Can't find the executable" + exit 1 + else + bm_fn_full=$1 + bm_fn=`$BASENAME $bm_fn_full` + fi +} + +get_bm_fn_interactive() +{ + read -p "Enter benchmark filename: " bm_fn_full + if [ -z $bm_fn_full ] ; then + echo "You did not enter any filename. Exiting..." + exit 1 + fi + get_bm_fn $bm_fn_full +} + + + +perf_record() +{ + $PERF record -F 50 --call-graph dwarf $1 --benchmark_filter=$2 +} + +perf_script() +{ + $PERF script | stackcollapse-perf.pl | flamegraph.pl > $1.svg +} + +perf_rec_scr() +{ + perf_record $1 $2 + perf_script $3 + # $PERF record --call-graph dwarf $1 | $PERF script | $STACKCOLLASE | $FLAMEGRAPG > $2 +} + + +get_bm_files() +{ + bm_file_list=`$FIND $ROOTBENCHBUILDDIR/root -iname "$BENCHMARKPATTERN" |grep -v "CMakeFiles"` + +} + +run_all_bm() +{ + get_bm_files + for bm_fn_full in $bm_file_list + do + bm_fn=`$BASENAME $bm_fn_full` + bm_dn=`$DIRNAME $bm_fn_full` + bm_path=`echo "$bm_dn" | $SED -n "s|^$ROOTBENCHBUILDDIR/||p"` + bm_list_exec=`./$bm_path/$bm_fn --benchmark_list_tests` + outputdir_full=${FLAMEGRAPHBASEDIR}/$bm_path/$bm_fn + $MKDIR -p $outputdir_full + if [ $? -ne 0 ]; then + echo "Can't create directory $1. Exiting..." + exit 1 + fi + for benchmark in $bm_list_exec + do + perf_rec_scr $bm_fn_full $benchmark ${outputdir_full}/${benchmark}_FlameGraph + done + done +} + + +run_spec_bm() +{ +spec_bm_list_exec=`$ROOTBENCHBUILDDIR/$bm_fn_full --benchmark_list_tests` +spec_outputdir_full=$ROOTBENCHBUILDDIR/$bm_fn +$MKDIR $spec_outputdir_full + if [ $? -ne 0 ]; then + echo "Can't create directory $1. Exiting..." + exit 1 + fi + for benchmark in $spec_bm_list_exec + do + perf_rec_scr $ROOTBENCHBUILDDIR/$bm_fn_full $benchmark ${spec_outputdir_full}/${benchmark}_FlameGraph + done +} + + +##### Main ##### + + +if [ \( "$ROOTBENCHBUILDDIR" = "-h" \) -o \( "$ROOTBENCHBUILDDIR" = "--help" \) ] ; then + usage + exit 1 +fi + +if [ ! -d $ROOTBENCHBUILDDIR ] ; then + echo "Can't find the build directory. Exiting..." + exit 1 +fi + +[ $# -eq 0 ] && usage_short + +while [ $# -gt 0 ]; do + case "$1" in + -b | --benchmarkfile ) + shift + get_bm_fn $1 + ;; + -a | --all ) + all=y + ;; + -h | --help ) + usage + exit + ;; + * ) + usage + exit 1 + ;; + esac + shift +done + +if [ "$all" = "y" ] ; then + run_all_bm +fi + +### If no "-b" option, we go with interactive mode. ### +# if [ -z $bm_fn_full ] ; then +# get_bm_fn_interactive +# fi + +if [ ! -z $bm_fn_full ] ; then + run_spec_bm +fi + +exit $? + + + + + + + + + From 5c5d2bfb46ccb25961a410777042b520ca365bff Mon Sep 17 00:00:00 2001 From: HLilit Date: Thu, 4 Jul 2019 17:04:55 +0200 Subject: [PATCH 08/18] Generation of flamegraphs for rootbenchmarks (script) --- cmake/modules/AddRootBench.cmake | 2 +- rootbench-scripts/flamegraph.sh | 143 +++++++++++++------------------ 2 files changed, 59 insertions(+), 86 deletions(-) diff --git a/cmake/modules/AddRootBench.cmake b/cmake/modules/AddRootBench.cmake index 2d80dea19..06537f841 100644 --- a/cmake/modules/AddRootBench.cmake +++ b/cmake/modules/AddRootBench.cmake @@ -49,7 +49,7 @@ function(RB_ADD_GBENCHMARK benchmark) set(postcmd POSTCMD ${ARG_POSTCMD}) endif() if(flamegraph) - set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh") + set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark}") add_dependencies(${benchmark} flamegraph-download) endif() if(${ARG_LABEL} STREQUAL "long") diff --git a/rootbench-scripts/flamegraph.sh b/rootbench-scripts/flamegraph.sh index 5137ce698..c7d53407a 100755 --- a/rootbench-scripts/flamegraph.sh +++ b/rootbench-scripts/flamegraph.sh @@ -1,20 +1,14 @@ #!/bin/bash - BENCHMARKPATTERN="*benchmark*" -ROOTBENCHBUILDDIR=$1 #/home/lharutyu/ROOT/rootbench-build2 # Enter path to rootbench-build folder -shift -FLAMEGRAPHBASEDIR=$ROOTBENCHBUILDDIR/FlameGraph - MKDIR=/bin/mkdir BASENAME=/usr/bin/basename DIRNAME=/usr/bin/dirname FIND=/usr/bin/find SED=/bin/sed PERF=/usr/bin/perf -STACKCOLLASE=stackcollapse-perf.pl -FLAMEGRAPG=flamegraph.pl - +STACKCOLLASE=stackcollapse-perf.pl +FLAMEGRAPG=flamegraph.pl usage() { @@ -23,23 +17,24 @@ usage() echo echo "Usage: $0 [OPTION]..." echo "This script generates FlameGraphs for benchmarks !!!" - echo " Enter path/to/rootbench/build/dir" echo "OPTIONS" echo " -b, --benchmarkfile path Location of ROOT benchmark file" echo " -a, --all Create all benchmarks." + echo " -d, --builddir path Create all benchmarks." echo " -h, --help Display this help and exit" } usage_short() { - echo "FlameGraph Generator" - echo "Usage: $0 [path/to/rootbench/build/dir] [-b |--benchmarkfile filepath] [-a | --all] [-h | --help]" +# echo "FlameGraph Generator" + echo "Usage: $0 -d | --builddir path [-b | --benchmarkfile filepath] [-a | --all] [-h | --help]" + exit 1 } get_bm_fn() { if [ ! -f $1 ] ; then - echo "Can't find the executable" + echo "Can't find the benchmark file" exit 1 else bm_fn_full=$1 @@ -47,6 +42,17 @@ get_bm_fn() fi } +get_build_dir() +{ + if [ ! -d $1 ] ; then + echo "Can't find the build directory. Exiting..." + exit 1 + else + build_dir=$1 + flamegraph_base_dir=$build_dir/FlameGraph + fi +} + get_bm_fn_interactive() { read -p "Enter benchmark filename: " bm_fn_full @@ -57,84 +63,53 @@ get_bm_fn_interactive() get_bm_fn $bm_fn_full } - - perf_record() { - $PERF record -F 50 --call-graph dwarf $1 --benchmark_filter=$2 + $PERF record -F 50 --call-graph dwarf $1 --benchmark_filter=${2}$ } perf_script() { - $PERF script | stackcollapse-perf.pl | flamegraph.pl > $1.svg + $PERF script | stackcollapse-perf.pl | flamegraph.pl --title $1 > $2.svg } -perf_rec_scr() +perf_rec_scr() { - perf_record $1 $2 - perf_script $3 - # $PERF record --call-graph dwarf $1 | $PERF script | $STACKCOLLASE | $FLAMEGRAPG > $2 + perf_record $1 $2 + perf_script $2 $3 + # $PERF record --call-graph dwarf $1 | $PERF script | $STACKCOLLASE | $FLAMEGRAPG > $2 } - get_bm_files() { - bm_file_list=`$FIND $ROOTBENCHBUILDDIR/root -iname "$BENCHMARKPATTERN" |grep -v "CMakeFiles"` - + bm_file_list=`$FIND $build_dir/root -iname "$BENCHMARKPATTERN" |grep -v "CMakeFiles"` } -run_all_bm() +run_bm() { - get_bm_files - for bm_fn_full in $bm_file_list + for bm_fn_full in $bm_file_list + do + bm_fn=`$BASENAME $bm_fn_full` + bm_dn=`$DIRNAME $bm_fn_full` + bm_path=`echo "$bm_dn" | $SED -n "s|^$build_dir/||p"` + bm_sub_list=`$bm_fn_full --benchmark_list_tests` + outputdir_full=${flamegraph_base_dir}/$bm_path/$bm_fn + $MKDIR -p $outputdir_full + if [ $? -ne 0 ]; then + echo "Can't create directory $1. Exiting..." + exit 1 + fi + for bm in $bm_sub_list do - bm_fn=`$BASENAME $bm_fn_full` - bm_dn=`$DIRNAME $bm_fn_full` - bm_path=`echo "$bm_dn" | $SED -n "s|^$ROOTBENCHBUILDDIR/||p"` - bm_list_exec=`./$bm_path/$bm_fn --benchmark_list_tests` - outputdir_full=${FLAMEGRAPHBASEDIR}/$bm_path/$bm_fn - $MKDIR -p $outputdir_full - if [ $? -ne 0 ]; then - echo "Can't create directory $1. Exiting..." - exit 1 - fi - for benchmark in $bm_list_exec - do - perf_rec_scr $bm_fn_full $benchmark ${outputdir_full}/${benchmark}_FlameGraph - done + bm_modified_fn=`echo "$bm" | $SED "s|[/:]|-|g"` #replacing all "/" and ":" with "-" + perf_rec_scr $bm_fn_full $bm ${outputdir_full}/${bm_modified_fn}_FlameGraph done + done } -run_spec_bm() -{ -spec_bm_list_exec=`$ROOTBENCHBUILDDIR/$bm_fn_full --benchmark_list_tests` -spec_outputdir_full=$ROOTBENCHBUILDDIR/$bm_fn -$MKDIR $spec_outputdir_full - if [ $? -ne 0 ]; then - echo "Can't create directory $1. Exiting..." - exit 1 - fi - for benchmark in $spec_bm_list_exec - do - perf_rec_scr $ROOTBENCHBUILDDIR/$bm_fn_full $benchmark ${spec_outputdir_full}/${benchmark}_FlameGraph - done -} - - ##### Main ##### - -if [ \( "$ROOTBENCHBUILDDIR" = "-h" \) -o \( "$ROOTBENCHBUILDDIR" = "--help" \) ] ; then - usage - exit 1 -fi - -if [ ! -d $ROOTBENCHBUILDDIR ] ; then - echo "Can't find the build directory. Exiting..." - exit 1 -fi - [ $# -eq 0 ] && usage_short while [ $# -gt 0 ]; do @@ -143,6 +118,11 @@ while [ $# -gt 0 ]; do shift get_bm_fn $1 ;; + -d | --builddir ) + shift + get_build_dir $1 + ;; + -a | --all ) all=y ;; @@ -158,26 +138,19 @@ while [ $# -gt 0 ]; do shift done -if [ "$all" = "y" ] ; then - run_all_bm +if [ -z $build_dir ] ; then + echo "************* Rootbench Build dir is mandatory *****************" + usage_short fi -### If no "-b" option, we go with interactive mode. ### -# if [ -z $bm_fn_full ] ; then -# get_bm_fn_interactive -# fi - -if [ ! -z $bm_fn_full ] ; then - run_spec_bm +if [ "$all" = "y" ] ; then + get_bm_files + run_bm +else + if [ ! -z $bm_fn_full ] ; then + bm_file_list=$bm_fn_full + run_bm + fi fi exit $? - - - - - - - - - From 28b161692b2b53b004a9adf95cd4df44747650fe Mon Sep 17 00:00:00 2001 From: HLilit Date: Tue, 9 Jul 2019 13:28:06 +0200 Subject: [PATCH 09/18] Fix Roofit banner appearance in gbenchmarks --- root/roofit/roofit/.rootrc | 1 + root/roofit/roofit/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 root/roofit/roofit/.rootrc diff --git a/root/roofit/roofit/.rootrc b/root/roofit/roofit/.rootrc new file mode 100644 index 000000000..2ebeffdf9 --- /dev/null +++ b/root/roofit/roofit/.rootrc @@ -0,0 +1 @@ +RooFit.Banner: no diff --git a/root/roofit/roofit/CMakeLists.txt b/root/roofit/roofit/CMakeLists.txt index a78169b98..c95b117cf 100644 --- a/root/roofit/roofit/CMakeLists.txt +++ b/root/roofit/roofit/CMakeLists.txt @@ -1,3 +1,4 @@ +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/.rootrc ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) RB_ADD_GBENCHMARK(RoofitBinnedBenchmark RooFitBinnedBenchmarks.cxx LABEL long @@ -7,3 +8,4 @@ RB_ADD_GBENCHMARK(RoofitUnBinnedBenchmark RooFitUnBinnedBenchmarks.cxx LABEL long LIBRARIES Core Hist MathCore RIO RooFit RooStats RooFitCore HistFactory) + From 7f7f5db3be97e55bc9a51cbe358a034cd22801ac Mon Sep 17 00:00:00 2001 From: HLilit Date: Tue, 9 Jul 2019 13:30:53 +0200 Subject: [PATCH 10/18] Adjust invocation of flamegraphs --- cmake/modules/AddRootBench.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/AddRootBench.cmake b/cmake/modules/AddRootBench.cmake index 06537f841..848d653c7 100644 --- a/cmake/modules/AddRootBench.cmake +++ b/cmake/modules/AddRootBench.cmake @@ -49,7 +49,7 @@ function(RB_ADD_GBENCHMARK benchmark) set(postcmd POSTCMD ${ARG_POSTCMD}) endif() if(flamegraph) - set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark}") + set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark}") add_dependencies(${benchmark} flamegraph-download) endif() if(${ARG_LABEL} STREQUAL "long") From 365f59442d2d1bdf2b69ff838d5d94baa76442fb Mon Sep 17 00:00:00 2001 From: HLilit Date: Fri, 19 Jul 2019 15:53:47 +0200 Subject: [PATCH 11/18] Separate flamegraphs into memory and CPU generation options --- cmake/modules/AddRootBench.cmake | 8 +- cmake/modules/RootBenchOptions.cmake | 3 +- rootbench-scripts/flamegraph.sh | 266 +++++++++++++++------------ 3 files changed, 155 insertions(+), 122 deletions(-) diff --git a/cmake/modules/AddRootBench.cmake b/cmake/modules/AddRootBench.cmake index 848d653c7..98a89600f 100644 --- a/cmake/modules/AddRootBench.cmake +++ b/cmake/modules/AddRootBench.cmake @@ -48,8 +48,12 @@ function(RB_ADD_GBENCHMARK benchmark) if(ARG_POSTCMD) set(postcmd POSTCMD ${ARG_POSTCMD}) endif() - if(flamegraph) - set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark}") + if(flamegraphCPU) + set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -c") + add_dependencies(${benchmark} flamegraph-download) + endif() + if(flamegraphMem) + set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -m") add_dependencies(${benchmark} flamegraph-download) endif() if(${ARG_LABEL} STREQUAL "long") diff --git a/cmake/modules/RootBenchOptions.cmake b/cmake/modules/RootBenchOptions.cmake index b98acb1a9..8c9de1081 100644 --- a/cmake/modules/RootBenchOptions.cmake +++ b/cmake/modules/RootBenchOptions.cmake @@ -5,4 +5,5 @@ #---------------------------------------------------------------------------- option(coverage OFF) option(rootbench-datafiles OFF) -option(flamegraph "FlameGraph generation option" OFF) +option(flamegraphCPU "CPU FlameGraph generation option" OFF) +option(flamegraphMem "Memory FlameGraph generation option" OFF) diff --git a/rootbench-scripts/flamegraph.sh b/rootbench-scripts/flamegraph.sh index c7d53407a..5c4df81b8 100755 --- a/rootbench-scripts/flamegraph.sh +++ b/rootbench-scripts/flamegraph.sh @@ -1,156 +1,184 @@ #!/bin/bash BENCHMARKPATTERN="*benchmark*" -MKDIR=/bin/mkdir -BASENAME=/usr/bin/basename -DIRNAME=/usr/bin/dirname -FIND=/usr/bin/find -SED=/bin/sed -PERF=/usr/bin/perf -STACKCOLLASE=stackcollapse-perf.pl -FLAMEGRAPG=flamegraph.pl - -usage() -{ - echo - echo "--------------------------FlameGraph Generator---------------------------" - echo - echo "Usage: $0 [OPTION]..." - echo "This script generates FlameGraphs for benchmarks !!!" - echo "OPTIONS" - echo " -b, --benchmarkfile path Location of ROOT benchmark file" - echo " -a, --all Create all benchmarks." - echo " -d, --builddir path Create all benchmarks." - echo " -h, --help Display this help and exit" +MKDIR=$(which mkdir) +BASENAME=$(which basename) +DIRNAME=$(which dirname) +FIND=$(which find) +SED=$(which sed) +PERF=$(which perf) +STACKCOLLAPSE=stackcollapse-perf.pl +FLAMEGRAPH=flamegraph.pl + +usage() { + echo + echo "--------------------------FlameGraph Generator---------------------------" + echo + echo "Usage: $0 [OPTION]..." + echo "This script generates FlameGraphs for benchmarks !!!" + echo "OPTIONS" + echo " -d, --builddir path Create all benchmarks." + echo " -b, --benchmarkfile path Location of ROOT benchmark file" + echo " -a, --all Create all benchmarks." + echo " -c, --cpu Generate CPU FlameGraphs" + echo " -m, --memory Generate Memory FlameGraphs" + echo " -h, --help Display this help and exit" } -usage_short() -{ -# echo "FlameGraph Generator" - echo "Usage: $0 -d | --builddir path [-b | --benchmarkfile filepath] [-a | --all] [-h | --help]" - exit 1 +usage_short() { + echo "Usage: $0 -d | --builddir path [-b | --benchmarkfile filepath] [-a | --all] [-c | --cpu] [-m | --memory] [-h | --help]" + exit 1 } -get_bm_fn() -{ - if [ ! -f $1 ] ; then - echo "Can't find the benchmark file" - exit 1 - else - bm_fn_full=$1 - bm_fn=`$BASENAME $bm_fn_full` - fi +get_bm_fn() { + if [ ! -f $1 ]; then + echo "Can't find the benchmark file" + exit 1 + else + bm_fn_full=$1 + bm_fn=$($BASENAME $bm_fn_full) + fi } -get_build_dir() -{ - if [ ! -d $1 ] ; then - echo "Can't find the build directory. Exiting..." - exit 1 - else - build_dir=$1 - flamegraph_base_dir=$build_dir/FlameGraph - fi +get_build_dir() { + if [ ! -d $1 ]; then + echo "Can't find the build directory. Exiting..." + exit 1 + else + build_dir=$1 + flamegraph_base_dir=$build_dir/FlameGraph + fi } -get_bm_fn_interactive() -{ - read -p "Enter benchmark filename: " bm_fn_full - if [ -z $bm_fn_full ] ; then - echo "You did not enter any filename. Exiting..." - exit 1 - fi - get_bm_fn $bm_fn_full +get_bm_fn_interactive() { + read -p "Enter benchmark filename: " bm_fn_full + if [ -z $bm_fn_full ]; then + echo "You did not enter any filename. Exiting..." + exit 1 + fi + get_bm_fn $bm_fn_full } -perf_record() -{ - $PERF record -F 50 --call-graph dwarf $1 --benchmark_filter=${2}$ +perf_record_cpu() { + $PERF record -F 50 --call-graph dwarf $1 --benchmark_filter=${2}$ } -perf_script() -{ - $PERF script | stackcollapse-perf.pl | flamegraph.pl --title $1 > $2.svg +perf_script_cpu() { + $PERF script | stackcollapse-perf.pl | flamegraph.pl --title $1 >$2.svg } -perf_rec_scr() -{ - perf_record $1 $2 - perf_script $2 $3 - # $PERF record --call-graph dwarf $1 | $PERF script | $STACKCOLLASE | $FLAMEGRAPG > $2 +perf_record_mem() { + $PERF record -F 50 -e page-faults --call-graph dwarf $1 --benchmark_filter=${2}$ } -get_bm_files() -{ - bm_file_list=`$FIND $build_dir/root -iname "$BENCHMARKPATTERN" |grep -v "CMakeFiles"` +perf_script_mem() { + $PERF script | stackcollapse-perf.pl | flamegraph.pl --color=mem --title=$1 --countname="pages" >$2.svg } -run_bm() -{ - for bm_fn_full in $bm_file_list - do - bm_fn=`$BASENAME $bm_fn_full` - bm_dn=`$DIRNAME $bm_fn_full` - bm_path=`echo "$bm_dn" | $SED -n "s|^$build_dir/||p"` - bm_sub_list=`$bm_fn_full --benchmark_list_tests` - outputdir_full=${flamegraph_base_dir}/$bm_path/$bm_fn - $MKDIR -p $outputdir_full - if [ $? -ne 0 ]; then - echo "Can't create directory $1. Exiting..." - exit 1 - fi - for bm in $bm_sub_list - do - bm_modified_fn=`echo "$bm" | $SED "s|[/:]|-|g"` #replacing all "/" and ":" with "-" - perf_rec_scr $bm_fn_full $bm ${outputdir_full}/${bm_modified_fn}_FlameGraph - done - done +perf_rec_scr_cpu() { + perf_record_cpu $1 $2 + perf_script_cpu $2 $3 +} + +perf_rec_scr_mem() { + perf_record_mem $1 $2 + perf_script_mem $2 $3 } +get_bm_files() { + bm_file_list=$($FIND $build_dir/root -iname "$BENCHMARKPATTERN" | grep -v "CMakeFiles\|pyroot\|interpreter\|.csv") +} + +run_bm() { + for bm_fn_full in $bm_file_list; do + bm_fn=$($BASENAME $bm_fn_full) + bm_dn=$($DIRNAME $bm_fn_full) + bm_path=$(echo "$bm_dn" | $SED -n "s|^$build_dir/||p") + bm_sub_list=$($bm_fn_full --benchmark_list_tests) + flamegraph_base_dir_mem=${flamegraph_base_dir}/FlameGraph_Memory + flamegraph_base_dir_cpu=${flamegraph_base_dir}/FlameGraph_CPU + outputdir_full_mem=${flamegraph_base_dir_mem}/$bm_path/$bm_fn + outputdir_full_cpu=${flamegraph_base_dir_cpu}/$bm_path/$bm_fn + if [ "$memory" = "y" ]; then + $MKDIR -p $outputdir_full_mem + if [ $? -ne 0 ]; then + echo "Can't create directory $1. Exiting..." + exit 1 + fi + fi + if [ "$cpu" = "y" ]; then + $MKDIR -p $outputdir_full_cpu + if [ $? -ne 0 ]; then + echo "Can't create directory $1. Exiting..." + exit 1 + fi + fi + for bm in $bm_sub_list; do + bm_modified_fn=$(echo "$bm" | $SED "s|[/:]|-|g") #replacing all "/" and ":" with "-" + if [ "$cpu"="y" ]; then + perf_rec_scr_cpu $bm_fn_full $bm ${outputdir_full_cpu}/${bm_modified_fn}_FlameGraph + fi + if [ "$memory"="y" ]; then + perf_rec_scr_mem $bm_fn_full $bm ${outputdir_full_mem}/${bm_modified_fn}_FlameGraph + fi + done + done +} ##### Main ##### [ $# -eq 0 ] && usage_short while [ $# -gt 0 ]; do - case "$1" in - -b | --benchmarkfile ) - shift - get_bm_fn $1 - ;; - -d | --builddir ) - shift - get_build_dir $1 - ;; - - -a | --all ) - all=y - ;; - -h | --help ) - usage - exit - ;; - * ) - usage - exit 1 - ;; - esac - shift + case "$1" in + -b | --benchmarkfile) + shift + get_bm_fn $1 + ;; + -d | --builddir) + shift + get_build_dir $1 + ;; + + -a | --all) + all=y + ;; + -c | --cpu) + cpu=y + ;; + -m | --memory) + memory=y + ;; + -h | --help) + usage + exit + ;; + *) + usage + exit 1 + ;; + esac + shift done -if [ -z $build_dir ] ; then - echo "************* Rootbench Build dir is mandatory *****************" - usage_short +if [ -z $build_dir ]; then + echo "************* Rootbench Build dir is mandatory *****************" + usage_short fi -if [ "$all" = "y" ] ; then - get_bm_files - run_bm -else - if [ ! -z $bm_fn_full ] ; then - bm_file_list=$bm_fn_full +if [ -z $cpu -a -z $memory ]; then + echo "************* Please specify the type of the FlameGraphs *****************" + usage_short +fi + +if [ "$all" = "y" ]; then + get_bm_files run_bm - fi +else + if [ ! -z $bm_fn_full ]; then + bm_file_list=$bm_fn_full + run_bm + fi fi exit $? From 4c40941ca07b4018d9d9985c76f1ba2b9fb4539e Mon Sep 17 00:00:00 2001 From: HLilit Date: Fri, 19 Jul 2019 15:56:00 +0200 Subject: [PATCH 12/18] Change location of .rootrc file, removing Roofit banner --- CMakeLists.txt | 3 ++- root/roofit/roofit/CMakeLists.txt | 1 - {root/roofit/roofit => rootbench-scripts}/.rootrc | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {root/roofit/roofit => rootbench-scripts}/.rootrc (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7769f1609..4890f7387 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ endif() include(GoogleBenchmark) include(PytestBenchmark) -if(flamegraph) +if(flamegraphCPU OR flamegraphMem) # Check if perf is available in OS: find_program(PERF_EXECUTABLE perf) if(NOT PERF_EXECUTABLE) @@ -109,3 +109,4 @@ add_subdirectory(tools) #---Add the now all the benchmark sub-directories on this repository add_subdirectory(root) +configure_file(${PROJECT_SOURCE_DIR}/rootbench-scripts/.rootrc ${PROJECT_BINARY_DIR} COPYONLY) diff --git a/root/roofit/roofit/CMakeLists.txt b/root/roofit/roofit/CMakeLists.txt index c95b117cf..ae4bbe53e 100644 --- a/root/roofit/roofit/CMakeLists.txt +++ b/root/roofit/roofit/CMakeLists.txt @@ -1,4 +1,3 @@ -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/.rootrc ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) RB_ADD_GBENCHMARK(RoofitBinnedBenchmark RooFitBinnedBenchmarks.cxx LABEL long diff --git a/root/roofit/roofit/.rootrc b/rootbench-scripts/.rootrc similarity index 100% rename from root/roofit/roofit/.rootrc rename to rootbench-scripts/.rootrc From 17cc65311b7ac02d78708431b628eb80ad36e443 Mon Sep 17 00:00:00 2001 From: HLilit Date: Fri, 19 Jul 2019 15:59:57 +0200 Subject: [PATCH 13/18] Add patch truncated names for templates for flamegraphs --- cmake/modules/FlameGraph.cmake | 4 +++- rootbench-scripts/stackcollapse-perf.patch | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 rootbench-scripts/stackcollapse-perf.patch diff --git a/cmake/modules/FlameGraph.cmake b/cmake/modules/FlameGraph.cmake index fdec6afff..78830a3da 100644 --- a/cmake/modules/FlameGraph.cmake +++ b/cmake/modules/FlameGraph.cmake @@ -3,9 +3,11 @@ include(ExternalProject) ExternalProject_Add(FlameGraph GIT_REPOSITORY "https://github.com/brendangregg/FlameGraph.git" UPDATE_COMMAND "" - PATCH_COMMAND "" + PATCH_COMMAND patch < ${CMAKE_SOURCE_DIR}/rootbench-scripts/stackcollapse-perf.patch CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" EXCLUDE_FROM_ALL 1 ) + + diff --git a/rootbench-scripts/stackcollapse-perf.patch b/rootbench-scripts/stackcollapse-perf.patch new file mode 100644 index 000000000..9df694582 --- /dev/null +++ b/rootbench-scripts/stackcollapse-perf.patch @@ -0,0 +1,13 @@ +diff --git a/stackcollapse-perf.pl b/stackcollapse-perf.pl +index e91f7de..fe88660 100755 +--- a/stackcollapse-perf.pl ++++ b/stackcollapse-perf.pl +@@ -80,7 +80,7 @@ my $include_pid = 0; # include process ID with process name + my $include_tid = 0; # include process & thread ID with process name + my $include_addrs = 0; # include raw address where a symbol can't be found + my $tidy_java = 1; # condense Java signatures +-my $tidy_generic = 1; # clean up function names a little ++my $tidy_generic = 0; # clean up function names a little + my $target_pname; # target process name from perf invocation + my $event_filter = ""; # event type filter, defaults to first encountered event + my $event_defaulted = 0; # whether we defaulted to an event (none provided) From dd35cfdd1e3edbcbe81a22a01f88cedbe197df14 Mon Sep 17 00:00:00 2001 From: Lilit Date: Thu, 25 Jul 2019 15:58:28 +0400 Subject: [PATCH 14/18] Add files via upload --- rootbench-scripts/README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 rootbench-scripts/README.md diff --git a/rootbench-scripts/README.md b/rootbench-scripts/README.md new file mode 100644 index 000000000..d947966cb --- /dev/null +++ b/rootbench-scripts/README.md @@ -0,0 +1,35 @@ +## About + +flamegraph.sh is a script that generates Flame Graphs for each benchmark in `rootbench.git`. More information on Flame Graphs can be found [here](http://www.brendangregg.com/flamegraphs.html). + +## Options + +See the USAGE message (--help) for options. + +To generate only CPU or only memory Flame Graphs, use `-c` or `-m` respectively. To generate both CPU and memory Flame Graphs for all benchmarks at once run the following command: +```bash +flamegraph.sh -d path/to/rootbench/build/dir -a -c -m +``` + +To generate Flame Graphs for specific benchmark just run the following command with `-c` or `-m` options or both: + ```bash +flamegraph.sh -d path/to/rootbench/build/dir -b path/to/benchmark +``` + +## Configuration + +If `perf` cannot find symbols in the program try to execute the following commands +```bash +echo 0 > /proc/sys/kernel/kptr_restrict +echo 1 > /proc/sys/kernel/sched_schedstats +``` + +To generate Flame Graphs for each benchmark add `-Dflamegraph=ON` option to your cmake configuration. + +```bash +cmake ../rootbench -Dflamegraph=ON +make -j4 +ctest -V -R rootbench-CLASSNAMEBenchmarks +``` +You can also run the script for Flame Graph generation from your rootbench directory. +The Flame Graphs will be stored in the local rootbench build directory under FlameGraph folder. From 09a58ea2e2990cea0b968ce9c2a8767eae9cb0ac Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Fri, 25 Sep 2020 15:03:11 +0200 Subject: [PATCH 15/18] Move flamegraph scripts to tools directory --- {rootbench-scripts => tools}/.rootrc | 0 {rootbench-scripts => tools}/README.md | 0 {rootbench-scripts => tools}/flamegraph.sh | 0 {rootbench-scripts => tools}/stackcollapse-perf.patch | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {rootbench-scripts => tools}/.rootrc (100%) rename {rootbench-scripts => tools}/README.md (100%) rename {rootbench-scripts => tools}/flamegraph.sh (100%) rename {rootbench-scripts => tools}/stackcollapse-perf.patch (100%) diff --git a/rootbench-scripts/.rootrc b/tools/.rootrc similarity index 100% rename from rootbench-scripts/.rootrc rename to tools/.rootrc diff --git a/rootbench-scripts/README.md b/tools/README.md similarity index 100% rename from rootbench-scripts/README.md rename to tools/README.md diff --git a/rootbench-scripts/flamegraph.sh b/tools/flamegraph.sh similarity index 100% rename from rootbench-scripts/flamegraph.sh rename to tools/flamegraph.sh diff --git a/rootbench-scripts/stackcollapse-perf.patch b/tools/stackcollapse-perf.patch similarity index 100% rename from rootbench-scripts/stackcollapse-perf.patch rename to tools/stackcollapse-perf.patch From f782c94502fa6b7280e6870139c51eef9f4ad746 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Fri, 25 Sep 2020 15:32:26 +0200 Subject: [PATCH 16/18] Move to use generation of flamegraphs as a CLEANUP_FIXTURE --- cmake/modules/AddRootBench.cmake | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cmake/modules/AddRootBench.cmake b/cmake/modules/AddRootBench.cmake index 98a89600f..cacce2c51 100644 --- a/cmake/modules/AddRootBench.cmake +++ b/cmake/modules/AddRootBench.cmake @@ -29,6 +29,29 @@ function(RB_ADD_SETUP_FIXTURE benchmark) endfunction(RB_ADD_SETUP_FIXTURE) +#---------------------------------------------------------------------------- +# function RB_ADD_FLAMEGRAPHCPU_FIXTURE() +#---------------------------------------------------------------------------- +function(RB_ADD_FLAMEGRAPHCPU_FIXTURE benchmark) + cmake_parse_arguments(ARG "" "" "" ${ARGN}) + add_test(NAME rootbench-fixture-flamegraphcpu-${benchmark} + COMMAND ${PROJECT_BINARY_DIR}/tools/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -c) + set_tests_properties(rootbench-fixture-flamegraphcpu-${benchmark} PROPERTIES FIXTURES_CLEANUP flamegraphcpu-${benchmark}) +endfunction(RB_ADD_FLAMEGRAPHCPU_FIXTURE) + + +#---------------------------------------------------------------------------- +# function RB_ADD_FLAMEGRAPHMEM_FIXTURE() +#---------------------------------------------------------------------------- +function(RB_ADD_FLAMEGRAPHMEM_FIXTURE benchmark) + cmake_parse_arguments(ARG "" "" "" ${ARGN}) + add_test(NAME rootbench-fixture-flamegraphmem-${benchmark} + COMMAND ${PROJECT_BINARY_DIR}/tools/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -m) + set_tests_properties(rootbench-fixture-flamegraphmem-${benchmark} PROPERTIES FIXTURES_CLEANUP flamegraphmem-${benchmark}) +endfunction(RB_ADD_FLAMEGRAPHMEM_FIXTURE) + + + #---------------------------------------------------------------------------- # function RB_ADD_GBENCHMARK( source1 source2... LIBRARIES libs) #---------------------------------------------------------------------------- @@ -74,13 +97,21 @@ function(RB_ADD_GBENCHMARK benchmark) RB_ADD_SETUP_FIXTURE(${benchmark} SETUP ${ARG_SETUP}) endif() + # Flamegraphs (both mem and cpu) + if(flamegraphCPU) + RB_ADD_FLAMEGRAPHCPU_FIXTURE(${benchmark}) + endif() + if(flamegraphMem) + RB_ADD_FLAMEGRAPHMEM_FIXTURE(${benchmark}) + endif() + # Add benchmark as a CTest add_test(NAME rootbench-${benchmark} COMMAND ${benchmark} --benchmark_out_format=csv --benchmark_out=rootbench-gbenchmark-${benchmark}.csv --benchmark_color=false) set_tests_properties(rootbench-${benchmark} PROPERTIES ENVIRONMENT LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR}:$ENV{LD_LIBRARY_PATH} TIMEOUT "${TIMEOUT_VALUE}" LABELS "${ARG_LABEL}" RUN_SERIAL TRUE - FIXTURES_REQUIRED "setup-${benchmark};download-${benchmark}-datafiles") + FIXTURES_REQUIRED "setup-${benchmark};download-${benchmark}-datafiles;flamegraphcpu-${benchmark};flamegraphmem-${benchmark}") endfunction(RB_ADD_GBENCHMARK) From 63aca79dfa3512db5814b1161dcf41386522ecd9 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Fri, 25 Sep 2020 17:25:27 +0200 Subject: [PATCH 17/18] Update CMake files according recent changes --- CMakeLists.txt | 9 ++++---- cmake/modules/AddRootBench.cmake | 34 +++++++++------------------- cmake/modules/FlameGraph.cmake | 4 +--- cmake/modules/RootBenchOptions.cmake | 3 +-- tools/CMakeLists.txt | 1 + 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4890f7387..0b51dd094 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,16 +65,15 @@ endif() include(GoogleBenchmark) include(PytestBenchmark) -if(flamegraphCPU OR flamegraphMem) +if(flamegraph) # Check if perf is available in OS: find_program(PERF_EXECUTABLE perf) if(NOT PERF_EXECUTABLE) message(WARNING "Perf is not available in your system, please install it.") set(flamegraph OFF CACHE BOOL "") - else() - include(FlameGraph) - add_custom_target(flamegraph-download DEPENDS FlameGraph) endif() + include(FlameGraph) + message(STATUS "INFO: CPU & Mem FlameGraph generation option is enabled.") endif() #---Add ROOT include direcories and used compilation flags @@ -109,4 +108,4 @@ add_subdirectory(tools) #---Add the now all the benchmark sub-directories on this repository add_subdirectory(root) -configure_file(${PROJECT_SOURCE_DIR}/rootbench-scripts/.rootrc ${PROJECT_BINARY_DIR} COPYONLY) +configure_file(${PROJECT_SOURCE_DIR}/tools/.rootrc ${PROJECT_BINARY_DIR} COPYONLY) diff --git a/cmake/modules/AddRootBench.cmake b/cmake/modules/AddRootBench.cmake index cacce2c51..80bc420cc 100644 --- a/cmake/modules/AddRootBench.cmake +++ b/cmake/modules/AddRootBench.cmake @@ -32,24 +32,14 @@ endfunction(RB_ADD_SETUP_FIXTURE) #---------------------------------------------------------------------------- # function RB_ADD_FLAMEGRAPHCPU_FIXTURE() #---------------------------------------------------------------------------- -function(RB_ADD_FLAMEGRAPHCPU_FIXTURE benchmark) +function(RB_ADD_FLAMEGRAPH_FIXTURE benchmark) cmake_parse_arguments(ARG "" "" "" ${ARGN}) - add_test(NAME rootbench-fixture-flamegraphcpu-${benchmark} - COMMAND ${PROJECT_BINARY_DIR}/tools/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -c) - set_tests_properties(rootbench-fixture-flamegraphcpu-${benchmark} PROPERTIES FIXTURES_CLEANUP flamegraphcpu-${benchmark}) -endfunction(RB_ADD_FLAMEGRAPHCPU_FIXTURE) - - -#---------------------------------------------------------------------------- -# function RB_ADD_FLAMEGRAPHMEM_FIXTURE() -#---------------------------------------------------------------------------- -function(RB_ADD_FLAMEGRAPHMEM_FIXTURE benchmark) - cmake_parse_arguments(ARG "" "" "" ${ARGN}) - add_test(NAME rootbench-fixture-flamegraphmem-${benchmark} - COMMAND ${PROJECT_BINARY_DIR}/tools/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -m) - set_tests_properties(rootbench-fixture-flamegraphmem-${benchmark} PROPERTIES FIXTURES_CLEANUP flamegraphmem-${benchmark}) -endfunction(RB_ADD_FLAMEGRAPHMEM_FIXTURE) - + add_test(NAME rootbench-fixture-flamegraph-${benchmark} + COMMAND ${PROJECT_BINARY_DIR}/tools/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -c -m) + set_tests_properties(rootbench-fixture-flamegraph-${benchmark} PROPERTIES + ENVIRONMENT PATH=${PROJECT_BINARY_DIR}/FlameGraph-prefix/src/FlameGraph/:$ENV{PATH} + FIXTURES_CLEANUP rootbench-${benchmark}) +endfunction(RB_ADD_FLAMEGRAPH_FIXTURE) #---------------------------------------------------------------------------- @@ -98,11 +88,9 @@ function(RB_ADD_GBENCHMARK benchmark) endif() # Flamegraphs (both mem and cpu) - if(flamegraphCPU) - RB_ADD_FLAMEGRAPHCPU_FIXTURE(${benchmark}) - endif() - if(flamegraphMem) - RB_ADD_FLAMEGRAPHMEM_FIXTURE(${benchmark}) + if(flamegraph) + RB_ADD_FLAMEGRAPH_FIXTURE(${benchmark}) + add_dependencies(${benchmark} FlameGraph) endif() # Add benchmark as a CTest @@ -111,7 +99,7 @@ function(RB_ADD_GBENCHMARK benchmark) set_tests_properties(rootbench-${benchmark} PROPERTIES ENVIRONMENT LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR}:$ENV{LD_LIBRARY_PATH} TIMEOUT "${TIMEOUT_VALUE}" LABELS "${ARG_LABEL}" RUN_SERIAL TRUE - FIXTURES_REQUIRED "setup-${benchmark};download-${benchmark}-datafiles;flamegraphcpu-${benchmark};flamegraphmem-${benchmark}") + FIXTURES_REQUIRED "setup-${benchmark};download-${benchmark}-datafiles") endfunction(RB_ADD_GBENCHMARK) diff --git a/cmake/modules/FlameGraph.cmake b/cmake/modules/FlameGraph.cmake index 78830a3da..b7e38330d 100644 --- a/cmake/modules/FlameGraph.cmake +++ b/cmake/modules/FlameGraph.cmake @@ -3,11 +3,9 @@ include(ExternalProject) ExternalProject_Add(FlameGraph GIT_REPOSITORY "https://github.com/brendangregg/FlameGraph.git" UPDATE_COMMAND "" - PATCH_COMMAND patch < ${CMAKE_SOURCE_DIR}/rootbench-scripts/stackcollapse-perf.patch + #PATCH_COMMAND patch < ${CMAKE_SOURCE_DIR}/tools/stackcollapse-perf.patch CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" EXCLUDE_FROM_ALL 1 ) - - diff --git a/cmake/modules/RootBenchOptions.cmake b/cmake/modules/RootBenchOptions.cmake index 8c9de1081..5311178eb 100644 --- a/cmake/modules/RootBenchOptions.cmake +++ b/cmake/modules/RootBenchOptions.cmake @@ -5,5 +5,4 @@ #---------------------------------------------------------------------------- option(coverage OFF) option(rootbench-datafiles OFF) -option(flamegraphCPU "CPU FlameGraph generation option" OFF) -option(flamegraphMem "Memory FlameGraph generation option" OFF) +option(flamegraph "CPU & Mem FlameGraph generation option" OFF) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e18fc0eb6..a06535c02 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1 +1,2 @@ configure_file(download_files.sh . COPYONLY) +configure_file(flamegraph.sh . COPYONLY) From 2507946cddacf473cb3fffdbbd141b2376d496a7 Mon Sep 17 00:00:00 2001 From: Oksana Shadura Date: Thu, 3 Dec 2020 19:48:19 +0100 Subject: [PATCH 18/18] Simplify Cmake option, -Dflamegraph enables both flamegraphs: mem and cpu + better dependencies management --- CMakeLists.txt | 7 ++++--- cmake/modules/AddRootBench.cmake | 12 ++++-------- cmake/modules/FlameGraph.cmake | 3 +++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b51dd094..a3d75a928 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,14 +66,15 @@ include(GoogleBenchmark) include(PytestBenchmark) if(flamegraph) - # Check if perf is available in OS: + # Check if perf is available in OS find_program(PERF_EXECUTABLE perf) if(NOT PERF_EXECUTABLE) message(WARNING "Perf is not available in your system, please install it.") set(flamegraph OFF CACHE BOOL "") + else() + include(FlameGraph) + message(STATUS "INFO: CPU & Mem FlameGraph generation option is enabled.") endif() - include(FlameGraph) - message(STATUS "INFO: CPU & Mem FlameGraph generation option is enabled.") endif() #---Add ROOT include direcories and used compilation flags diff --git a/cmake/modules/AddRootBench.cmake b/cmake/modules/AddRootBench.cmake index 80bc420cc..7f25c24ba 100644 --- a/cmake/modules/AddRootBench.cmake +++ b/cmake/modules/AddRootBench.cmake @@ -61,13 +61,9 @@ function(RB_ADD_GBENCHMARK benchmark) if(ARG_POSTCMD) set(postcmd POSTCMD ${ARG_POSTCMD}) endif() - if(flamegraphCPU) - set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -c") - add_dependencies(${benchmark} flamegraph-download) - endif() - if(flamegraphMem) - set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -m") - add_dependencies(${benchmark} flamegraph-download) + if(flamegraph) + set(postcmd ${postcmd} "${PROJECT_SOURCE_DIR}/rootbench-scripts/flamegraph.sh -d ${PROJECT_BINARY_DIR} -b ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} -c -m") + add_dependencies(${benchmark} FlameGraph) endif() if(${ARG_LABEL} STREQUAL "long") set(${TIMEOUT_VALUE} 1200) @@ -90,7 +86,7 @@ function(RB_ADD_GBENCHMARK benchmark) # Flamegraphs (both mem and cpu) if(flamegraph) RB_ADD_FLAMEGRAPH_FIXTURE(${benchmark}) - add_dependencies(${benchmark} FlameGraph) + add_dependencies(${benchmark} flamegraph) endif() # Add benchmark as a CTest diff --git a/cmake/modules/FlameGraph.cmake b/cmake/modules/FlameGraph.cmake index b7e38330d..5b3f50428 100644 --- a/cmake/modules/FlameGraph.cmake +++ b/cmake/modules/FlameGraph.cmake @@ -9,3 +9,6 @@ ExternalProject_Add(FlameGraph INSTALL_COMMAND "" EXCLUDE_FROM_ALL 1 ) + +# Register flamegraph +add_custom_target(flamegraph DEPENDS FlameGraph)