Skip to content

Commit

Permalink
Merge pull request #81 from mantidproject/feature/10271_tcmalloc_ldpr…
Browse files Browse the repository at this point in the history
…eload

Use tcmalloc via ld_preload
  • Loading branch information
stuartcampbell committed Dec 10, 2014
2 parents 0c12a08 + 8af22ff commit b04d843
Show file tree
Hide file tree
Showing 30 changed files with 539 additions and 523 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/Build/CMake/FindTcmalloc.cmake
Expand Up @@ -6,14 +6,14 @@
# TCMALLOC_LIBRARIES libraries to link against
# TCMALLOC_FOUND If false, do not try to use TCMALLOC

find_path ( TCMALLOC_INCLUDE_DIR tcmalloc.h
find_path ( TCMALLOC_INCLUDE_DIR tcmalloc.h
PATHS /usr/include/gperftools
)

find_library ( TCMALLOC_LIB NAMES tcmalloc tcmalloc_minimal )
find_library ( TCMALLOC_LIB NAMES tcmalloc_minimal tcmalloc )
set ( TCMALLOC_LIBRARIES ${TCMALLOC_LIB} )

# handle the QUIETLY and REQUIRED arguments and set TCMALLOC_FOUND to TRUE if
# handle the QUIETLY and REQUIRED arguments and set TCMALLOC_FOUND to TRUE if
# all listed variables are TRUE
include ( FindPackageHandleStandardArgs )
find_package_handle_standard_args( Tcmalloc DEFAULT_MSG TCMALLOC_LIBRARIES TCMALLOC_INCLUDE_DIR )
Expand Down
145 changes: 145 additions & 0 deletions Code/Mantid/Build/CMake/LinuxPackageScripts.cmake
@@ -0,0 +1,145 @@
###########################################################################
# Define scripts for the Linux packages
#
# It provides:
# - launch_mantidplot.sh
#
###########################################################################

###########################################################################
# Set installation variables
###########################################################################
set ( BIN_DIR bin )
set ( ETC_DIR etc )
set ( LIB_DIR lib )
set ( PLUGINS_DIR plugins )
set ( PVPLUGINS_DIR pvplugins )
set ( PVPLUGINS_SUBDIR pvplugins ) # Need to tidy these things up!

if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set ( CMAKE_INSTALL_PREFIX /opt/Mantid CACHE PATH "Install path" FORCE )
endif()

set ( CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${LIB_DIR};${CMAKE_INSTALL_PREFIX}/${PLUGINS_DIR};${CMAKE_INSTALL_PREFIX}/${PVPLUGINS_DIR} )

###########################################################################
# LD_PRELOAD libraries
###########################################################################
set ( EXTRA_LDPRELOAD_LIBS "${TCMALLOC_LIBRARIES}" )

###########################################################################
# Environment scripts (profile.d)
###########################################################################
# default shell (bash-like)
file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/mantid.sh
"#!/bin/sh\n"
"MANTIDPATH=${CMAKE_INSTALL_PREFIX}/${BIN_DIR}\n"
"PV_PLUGIN_PATH=${CMAKE_INSTALL_PREFIX}/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}\n"
"PATH=$PATH:$MANTIDPATH\n"
"PYTHONPATH=$MANTIDPATH:$PYTHONPATH\n"

"export MANTIDPATH PV_PLUGIN_PATH PATH PYTHONPATH\n"
)

# c-shell
file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/mantid.csh
"#!/bin/csh\n"
"setenv MANTIDPATH \"${CMAKE_INSTALL_PREFIX}/${BIN_DIR}\"\n"
"setenv PV_PLUGIN_PATH \"${CMAKE_INSTALL_PREFIX}/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}\"\n"
"setenv PATH \"\${PATH}:\${MANTIDPATH}\"\n"

"if ($?PYTHONPATH) then\n"
" setenv PYTHONPATH \"\${MANTIDPATH}:\${PYTHONPATH}\"\n"
"else\n"
" setenv PYTHONPATH \"\${MANTIDPATH}\"\n"
"endif\n"
)

install ( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/mantid.sh
${CMAKE_CURRENT_BINARY_DIR}/mantid.csh
DESTINATION ${ETC_DIR}
)

############################################################################
# Setup file variables for pre/post installation
# These are very different depending on the distribution so are contained
# in the Packaging/*/scripts directory as CMake templates
############################################################################
if ( NOT MPI_BUILD )
set ( ENVVARS_ON_INSTALL ON CACHE BOOL
"Whether to include the scripts in /etc/profile.d to set the MANTIDPATH variable and add it to PATH. Turning this off allows installing locally without being root." )
endif()
# for shell maintainer scripts as ENVVARS_ON_INSTALL could have ON, OFF, True, False etc
if ( ENVVARS_ON_INSTALL )
set ( ENVVARS_ON_INSTALL_INT 1 )
else ()
set ( ENVVARS_ON_INSTALL_INT 0 )
endif()

# Common filenames to hold maintainer scripts
set ( PRE_INSTALL_FILE ${CMAKE_CURRENT_BINARY_DIR}/preinst )
set ( POST_INSTALL_FILE ${CMAKE_CURRENT_BINARY_DIR}/postinst )
set ( PRE_UNINSTALL_FILE ${CMAKE_CURRENT_BINARY_DIR}/prerm )
set ( POST_UNINSTALL_FILE ${CMAKE_CURRENT_BINARY_DIR}/postrm )

if ( "${UNIX_DIST}" MATCHES "RedHatEnterprise" OR "${UNIX_DIST}" MATCHES "^Fedora" ) # RHEL/Fedora
if ( "${UNIX_CODENAME}" MATCHES "Santiago" ) # el6
set ( WRAPPER_COMMAND "scl enable mantidlibs" )
set ( EXTRA_LDPATH "/usr/lib64/paraview" )
else()
set ( WRAPPER_COMMAND "eval" )
endif()

if ( NOT MPI_BUILD )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/rpm/scripts/rpm_pre_install.sh.in
${PRE_INSTALL_FILE} @ONLY )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/rpm/scripts/rpm_post_install.sh.in
${POST_INSTALL_FILE} @ONLY )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/rpm/scripts/rpm_pre_uninstall.sh.in
${PRE_UNINSTALL_FILE} @ONLY )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/rpm/scripts/rpm_post_install.sh.in
${POST_UNINSTALL_FILE} @ONLY )
# CPack variables
set ( CPACK_RPM_PRE_INSTALL_SCRIPT_FILE ${PRE_INSTALL_FILE} )
set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${POST_INSTALL_FILE} )
set ( CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${PRE_UNINSTALL_FILE} )
set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${POST_UNINSTALL_FILE} )
endif()
elseif ( "${UNIX_DIST}" MATCHES "Ubuntu" )
set ( WRAPPER_COMMAND "eval" )

if ( NOT MPI_BUILD )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/deb/scripts/deb_pre_inst.in
${PRE_INSTALL_FILE} @ONLY )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/deb/scripts/deb_post_inst.in
${POST_INSTALL_FILE} @ONLY )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/deb/scripts/deb_pre_rm.in
${PRE_UNINSTALL_FILE} @ONLY )
# No postrm script as dpkg removes empty directories if everything else is tidied away.

# CPack variables
set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
"${PRE_INSTALL_FILE};${POST_INSTALL_FILE};${PRE_UNINSTALL_FILE}" )
endif()
endif()

############################################################################
# MantidPlot launcher script
############################################################################
# Local dev version
set ( MANTIDPLOT_EXEC MantidPlot )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/launch_mantidplot.sh.in
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/launch_mantidplot.sh @ONLY )
# Needs to be executable
execute_process ( COMMAND "chmod" "+x" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/launch_mantidplot.sh"
OUTPUT_QUIET ERROR_QUIET )
# Package version
set ( MANTIDPLOT_EXEC MantidPlot_exe )
configure_file ( ${CMAKE_MODULE_PATH}/Packaging/launch_mantidplot.sh.in
${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh.install @ONLY )
install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh.install
DESTINATION ${BIN_DIR} RENAME launch_mantidplot.sh
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
WORLD_EXECUTE WORLD_READ
)
180 changes: 13 additions & 167 deletions Code/Mantid/Build/CMake/LinuxSetup.cmake
@@ -1,3 +1,8 @@
###########################################################################
# Who are we
###########################################################################
include ( DetermineLinuxDistro )

###########################################################################
# Use the system-installed version of Python.
###########################################################################
Expand All @@ -8,181 +13,22 @@ if ( PYTHON_DEBUG_LIBRARIES )
endif ()

###########################################################################
# tcmalloc stuff. Only used on linux for now.
# If required, find tcmalloc
###########################################################################

# Look for tcmalloc. Make it optional, for now at least, but on by default
set ( USE_TCMALLOC ON CACHE BOOL "Flag for replacing regular malloc with tcmalloc" )
set ( USE_TCMALLOC ON CACHE BOOL "If true, use LD_PRELOAD=libtcmalloc.so in startup scripts" )
# If not wanted, just carry on without it
if ( USE_TCMALLOC )
find_package ( Tcmalloc )
if ( TCMALLOC_FOUND )
set ( TCMALLOC_LIBRARY ${TCMALLOC_LIBRARIES} )
# Make a C++ define to use as flags in, e.g. MemoryManager.cpp
add_definitions ( -DUSE_TCMALLOC )
else ( TCMALLOC_FOUND )
# If not found, print a message telling the user to either get it or disable its use in the cache
message ( SEND_ERROR "TCMalloc not found: either install the google-perftools suite on your system or set the USE_TCMALLOC CMake cache variable to OFF" )
endif ( TCMALLOC_FOUND )
# if it can't be found still carry on as the build will work. The package
# depenendencies will install it for the end users
else ( USE_TCMALLOC )
message ( STATUS "Not using TCMalloc" )
endif ( USE_TCMALLOC )
message ( STATUS "TCMalloc will not be included in startup scripts" )
endif ()

###########################################################################
# Set installation variables
# Set up package scripts for this distro
###########################################################################
set ( BIN_DIR bin )
set ( ETC_DIR etc )
set ( LIB_DIR lib )
set ( PLUGINS_DIR plugins )
set ( PVPLUGINS_DIR pvplugins )
set ( PVPLUGINS_SUBDIR pvplugins ) # Need to tidy these things up!

include ( DetermineLinuxDistro )

if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set ( CMAKE_INSTALL_PREFIX /opt/Mantid CACHE PATH "Install path" FORCE )
endif()

set ( CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${LIB_DIR};${CMAKE_INSTALL_PREFIX}/${PLUGINS_DIR};${CMAKE_INSTALL_PREFIX}/${PVPLUGINS_DIR} )

file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/mantid.sh "#!/bin/sh\n"
"MANTIDPATH=${CMAKE_INSTALL_PREFIX}/${BIN_DIR}\n"
"PV_PLUGIN_PATH=${CMAKE_INSTALL_PREFIX}/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}\n"
# "scriptpath=\"$(cd \"\${0%/*}\" 2> /dev/null;echo \"$PWD\"/\"\${0##*/}\")\"\n"
# "scriptpath=`readlink -f $scriptpath`\n"
# "scriptpath=`dirname $scriptpath`\n"
# "echo \"script $scriptpath\"\n"
# "MANTIDPATH=$scriptpath/${BIN_DIR}\n"
# "echo $MANTIDPATH\n"
# "PV_PLUGIN_PATH=$scriptpath/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}\n"
"PATH=$PATH:$MANTIDPATH\n"
"PYTHONPATH=$MANTIDPATH:$PYTHONPATH\n"
"LD_PRELOAD=\n"
"export MANTIDPATH PV_PLUGIN_PATH PATH PYTHONPATH LD_PRELOAD\n"
)

file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/mantid.csh "#!/bin/csh\n"
"setenv MANTIDPATH \"${CMAKE_INSTALL_PREFIX}/${BIN_DIR}\"\n"
"setenv PV_PLUGIN_PATH \"${CMAKE_INSTALL_PREFIX}/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}\"\n"
"setenv PATH \"\${PATH}:\${MANTIDPATH}\"\n"
"setenv LD_PRELOAD \" \"\n"
"if ($?PYTHONPATH) then\n"
" setenv PYTHONPATH \"\${MANTIDPATH}:\${PYTHONPATH}\"\n"
"else\n"
" setenv PYTHONPATH \"\${MANTIDPATH}\"\n"
"endif\n"
)


file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh "#!/bin/sh\n"
"if [ ! -e $RPM_INSTALL_PREFIX0/${BIN_DIR}/mantidplot ]; then\n"
" ln -s $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot $RPM_INSTALL_PREFIX0/${BIN_DIR}/mantidplot\n"
"fi\n"
)
if ( ENVVARS_ON_INSTALL )
file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh "\n"
"ln -s $RPM_INSTALL_PREFIX0/${ETC_DIR}/mantid.sh /etc/profile.d/mantid.sh\n"
"ln -s $RPM_INSTALL_PREFIX0/${ETC_DIR}/mantid.csh /etc/profile.d/mantid.csh\n"
)
endif()



# RHEL6 specific stuff (as we need to use software collections)
if ( "${UNIX_DIST}" MATCHES "RedHatEnterprise" )
file ( APPEND ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh "\n"
"if [ -f $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot ]; then\n"
" mv $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot_exe\n"
" ln -s $RPM_INSTALL_PREFIX0/${BIN_DIR}/launch_mantidplot.sh $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot\n"
"fi\n"
)
if ( "${UNIX_CODENAME}" MATCHES "Santiago" ) # el6
file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh "#!/bin/sh\n"
"scl enable mantidlibs \"${CMAKE_INSTALL_PREFIX}/${BIN_DIR}/MantidPlot_exe $*\" \n"
)
else ()
file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh "#!/bin/sh\n"
"LD_LIBRARY_PATH=/usr/lib64/paraview:${LD_LIBRARY_PATH} ${CMAKE_INSTALL_PREFIX}/${BIN_DIR}/MantidPlot_exe $* \n"
)
endif()

install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh
DESTINATION ${BIN_DIR}
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
WORLD_EXECUTE WORLD_READ
)

endif()

file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/rpm_pre_uninstall.sh "#!/bin/sh\n"
"if [ ! -f $RPM_INSTALL_PREFIX0/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}/libMantidParaViewSplatterPlotSMPlugin.so ];then\n"
" rm -f $RPM_INSTALL_PREFIX0/${BIN_DIR}/mantidplot\n"
"fi\n"
"if [ -h /etc/profile.d/mantid.sh ]; then\n"
" rm /etc/profile.d/mantid.sh\n"
"fi\n"
"if [ -h /etc/profile.d/mantid.csh ]; then\n"
" rm /etc/profile.d/mantid.csh\n"
"fi\n"
"if [ -f $RPM_INSTALL_PREFIX0/${BIN_DIR}MantidPlot_exe ]; then\n"
" rm $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot_exe\n"
"fi\n"

)

file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/rpm_remove_all_links.sh "#!/bin/sh\n"
"if [ ! -f $RPM_INSTALL_PREFIX0/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}/libMantidParaViewSplatterPlotSMPlugin.so ];then\n"
" rm -f $RPM_INSTALL_PREFIX0/${BIN_DIR}/mantidplot\n"
"fi\n"
"if [ -h /etc/profile.d/mantid.sh ]; then\n"
" rm /etc/profile.d/mantid.sh\n"
"fi\n"
"if [ -h /etc/profile.d/mantid.csh ]; then\n"
" rm /etc/profile.d/mantid.csh\n"
"fi\n"
)

file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/rpm_remove_links.sh "#!/bin/sh\n"
"if [ ! -f $RPM_INSTALL_PREFIX0/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}/libMantidParaViewSplatterPlotSMPlugin.so ];then\n"
" rm -f $RPM_INSTALL_PREFIX0/${BIN_DIR}/mantidplot\n"
"fi\n"
)

file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/rpm_remove_empty_install.sh "#!/bin/sh\n"
"# If the install prefix contains mantid then prune empty directories.\n"
"# Begin extra cautious here just in case some has set the something like Prefix=/usr\n"
"if echo \"$RPM_INSTALL_PREFIX0\" | grep -qi mantid; then\n"
" find $RPM_INSTALL_PREFIX0 -mindepth 1 -type d -empty -delete\n"
" rmdir --ignore-fail-on-non-empty -p $RPM_INSTALL_PREFIX0\n"
"else\n"
" echo Install prefix does not contain the word mantid. Empty directories NOT removed.\n"
" exit 1\n"
"fi\n"
)

install ( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/mantid.sh ${CMAKE_CURRENT_BINARY_DIR}/mantid.csh
DESTINATION ${ETC_DIR}
)

# unset all install/uninstall scripts
unset ( CPACK_RPM_PRE_INSTALL_SCRIPT_FILE )
unset ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE )
unset ( CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE )
unset ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE )

# set install/uninstall scripts as desired
if ( NOT MPI_BUILD )
set ( ENVVARS_ON_INSTALL ON CACHE BOOL "Whether to include the scripts in /etc/profile.d to set the MANTIDPATH variable and add it to PATH. Turning this off allows installing locally without being root." )
if ( ENVVARS_ON_INSTALL )
set ( CPACK_RPM_PRE_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/rpm_remove_all_links.sh )
set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh )
set ( CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/rpm_pre_uninstall.sh )
set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/rpm_remove_empty_install.sh )
else ( ENVVARS_ON_INSTALL )
set ( CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh )
set ( CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/rpm_remove_links.sh )
set ( CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/rpm_remove_empty_install.sh )
endif ()
endif ( NOT MPI_BUILD )
include ( LinuxPackageScripts )

0 comments on commit b04d843

Please sign in to comment.