Skip to content

Commit

Permalink
scripts: disable tcmalloc to support valgrind memcheck (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wu Tao authored Oct 16, 2018
1 parent 18688e8 commit 06b106e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 80 deletions.
25 changes: 18 additions & 7 deletions bin/dsn.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
include(${CMAKE_CURRENT_LIST_DIR}/compiler_info.cmake)


# Always generate the compilation database file (compile_commands.json) for use
# with various development tools, such as IWYU and Vim's YouCompleteMe plugin.
# See http://clang.llvm.org/docs/JSONCompilationDatabase.html
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)


# Set DSN_PROJECT_DIR to rdsn/
set(DSN_PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR})
get_filename_component(DSN_PROJECT_DIR ${DSN_PROJECT_DIR} DIRECTORY)
Expand All @@ -19,6 +17,18 @@ message(STATUS "DSN_THIRDPARTY_ROOT = ${DSN_THIRDPARTY_ROOT}")
set(DSN_ROOT ${DSN_PROJECT_DIR}/DSN_ROOT)
message(STATUS "DSN_ROOT = ${DSN_ROOT}")

option(BUILD_TEST "build unit test" ON)
message(STATUS "BUILD_TEST = ${BUILD_TEST}")

option(ENABLE_GCOV "Enable gcov (for code coverage analysis)" OFF)
message(STATUS "ENABLE_GCOV = ${ENABLE_GCOV}")

# Disable this option before running valgrind.
option(ENABLE_GPERF "Enable gperftools (for tcmalloc)" ON)
message(STATUS "ENABLE_GPERF = ${ENABLE_GPERF}")

# ================================================================== #


# Install this target into ${CMAKE_INSTALL_PREFIX}/lib
function(dsn_install_library)
Expand Down Expand Up @@ -139,11 +149,9 @@ function(dsn_add_project)
else()
set(TEMP_LIBS dsn_runtime)
endif()
set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${TEMP_LIBS} ${MY_BOOST_LIBS} -ltcmalloc ${DSN_SYSTEM_LIBS})
set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${TEMP_LIBS} ${MY_BOOST_LIBS} ${DSN_SYSTEM_LIBS})
endif()

list(APPEND MY_PROJ_LIBS thrift)

ms_add_project("${MY_PROJ_TYPE}" "${MY_PROJ_NAME}" "${MY_PROJ_SRC}" "${MY_PROJ_INC_PATH}" "${MY_PROJ_LIBS}" "${MY_PROJ_LIB_PATH}" "${MY_BINPLACES}")
endfunction(dsn_add_project)

Expand All @@ -169,8 +177,6 @@ function(dsn_add_object)
dsn_add_project()
endfunction(dsn_add_object)

option(BUILD_TEST "build unit test" ON)
option(ENABLE_GCOV "Enable gcov (for code coverage analysis)" OFF)
function(dsn_add_test)
if(${BUILD_TEST})
set(MY_EXECUTABLE_IS_TEST TRUE)
Expand Down Expand Up @@ -290,8 +296,13 @@ function(dsn_setup_system_libs)
endif()
set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} ${DSN_LIB_CRYPTO})

if(ENABLE_GPERF)
set(DSN_SYSTEM_LIBS ${DSN_SYSTEM_LIBS} tcmalloc)
endif()

set(DSN_SYSTEM_LIBS
${DSN_SYSTEM_LIBS}
thrift
${CMAKE_THREAD_LIBS_INIT} # the thread library found by FindThreads
CACHE STRING "rDSN system libs" FORCE
)
Expand Down
58 changes: 11 additions & 47 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,10 @@ function usage()
echo " start_zk start the local single zookeeper server"
echo " stop_zk stop the local single zookeeper server"
echo " clear_zk stop the local single zookeeper server and clear the data"
echo " format check the code format"
echo " publish publish the program"
echo " publish_docker"
echo " publish the program docker image"
echo " republish republish the program without changes to machinelist and config.ini files"
echo " republish_docker"
echo " republish the program docker image without changes to machinelist and config.ini files"
echo " deploy deploy the program to remote machine"
echo " start start program at remote machine"
echo " stop stop program at remote machine"
echo " clean clean deployed program at remote machine"
echo " k8s_deploy deploy onto kubernetes cluster"
echo " k8s_undeploy"
echo " undeploy from kubernetes cluster"
echo
echo "Command 'run.sh <command> -h' will print help for subcommands."
}
Expand All @@ -61,6 +51,8 @@ function usage_build()
echo " --enable_gcov generate gcov code coverage report, default no"
echo " -v|--verbose build in verbose mode, default no"
echo " --notest build without building unit tests, default no"
echo " --disable_gperf build without gperftools, this flag is mainly used"
echo " to enable valgrind memcheck, default no"
if [ "$ONLY_BUILD" == "NO" ]; then
echo " -m|--test_module specify modules to test, split by ',',"
echo " e.g., \"dsn.core.tests,dsn.tests\","
Expand Down Expand Up @@ -119,12 +111,19 @@ function run_build()
--enable_gcov)
ENABLE_GCOV=YES
BUILD_TYPE="debug"
shift
;;
-v|--verbose)
RUN_VERBOSE=YES
shift
;;
--notest)
NO_TEST=YES
shift
;;
--disable_gperf)
DISABLE_GPERF=YES
shift
;;
-m|--test_module)
if [ "$ONLY_BUILD" == "YES" ]; then
Expand Down Expand Up @@ -176,7 +175,8 @@ function run_build()
C_COMPILER="$C_COMPILER" CXX_COMPILER="$CXX_COMPILER" BUILD_TYPE="$BUILD_TYPE" \
ONLY_BUILD="$ONLY_BUILD" CLEAR="$CLEAR" JOB_NUM="$JOB_NUM" \
BOOST_DIR="$BOOST_DIR" ENABLE_GCOV="$ENABLE_GCOV" \
RUN_VERBOSE="$RUN_VERBOSE" TEST_MODULE="$TEST_MODULE" NO_TEST="$NO_TEST" $scripts_dir/build.sh
RUN_VERBOSE="$RUN_VERBOSE" TEST_MODULE="$TEST_MODULE" NO_TEST="$NO_TEST" \
DISABLE_GPERF="$DISABLE_GPERF" $scripts_dir/build.sh
}

#####################
Expand Down Expand Up @@ -321,35 +321,6 @@ function run_clear_zk()
DOWNLOADED_DIR="$DOWNLOADED_DIR" $scripts_dir/clear_zk.sh
}

#####################
## format
#####################
function usage_format()
{
echo "Options for subcommand 'format':"
echo " -h|--help print the help info"
}
function run_format()
{
while [[ $# > 0 ]]; do
key="$1"
case $key in
-h|--help)
usage_format
exit 0
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage_format
exit 1
;;
esac
shift
done
$scripts_dir/format.sh
}

####################################################################

if [ $# -eq 0 ]; then
Expand Down Expand Up @@ -380,15 +351,8 @@ case $cmd in
clear_zk)
shift
run_clear_zk $* ;;
format)
shift
run_format $* ;;
publish|publish_docker|republish|republish_docker)
$scripts_dir/publish.sh $* ;;
deploy|start|stop|clean)
$scripts_dir/deploy.sh $* ;;
k8s_deploy|k8s_undeploy)
$scripts_dir/k8s_deploy.sh $* ;;
*)
echo "ERROR: unknown command $cmd"
echo
Expand Down
9 changes: 9 additions & 0 deletions scripts/linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ else
echo "NO_TEST=NO"
fi

# valgrind can not work together with gpertools
# you may want to use this option when you want to run valgrind
if [ "$DISABLE_GPERF" == "YES" ]
echo "DISABLE_GPERF=YES"
CMAKE_OPTIONS="$CMAKE_OPTIONS -DENABLE_GPERF=Off"
then
echo "DISABLE_GPERF=NO"
fi

# You can specify customized boost by defining BOOST_DIR.
# Install boost like this:
# wget http://downloads.sourceforge.net/project/boost/boost/1.54.0/boost_1_54_0.zip?r=&ts=1442891144&use_mirror=jaist
Expand Down
26 changes: 0 additions & 26 deletions scripts/linux/format.sh

This file was deleted.

0 comments on commit 06b106e

Please sign in to comment.