From 6c12edbf9d24db98795d07b49cbe32893d35798d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 11 Aug 2016 00:12:05 +0800 Subject: [PATCH] cmake: cleanup Findgperftools.cmake * remove Findtcmalloc.cmake, use Findgperftools.cmake instead. * tcmalloc is packaged in gperftools-dev, so we can check them in a single place. * fix the check of heap-profiler.h, we should enable the check as long as tcmalloc is enabled or profiler is enabled. * only check gperftools headers in "include/gperftools", and do not "include/google" anymore. as we only support the distros which shipping recent gperftools-dev package with "include/gperftools". and "google/*.h" are deprecated. * set ALLOC_LIBS with GPERFTOOLS_TCMALLOC_LIBRARY, so we can link against tcmalloc with full path. Signed-off-by: Kefu Chai --- CMakeLists.txt | 16 +++++++-------- cmake/modules/Findgperftools.cmake | 31 ++++++++++++------------------ cmake/modules/Findtcmalloc.cmake | 28 --------------------------- configure.ac | 3 ++- src/CMakeLists.txt | 11 +---------- src/include/config-h.in.cmake | 9 --------- src/perfglue/cpu_profiler.cc | 9 +-------- src/perfglue/heap_profiler.cc | 13 ++----------- 8 files changed, 26 insertions(+), 94 deletions(-) delete mode 100644 cmake/modules/Findtcmalloc.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7edf4566bdd..0cd73bfab6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,27 +259,27 @@ find_package(snappy REQUIRED) #if allocator is set on command line make sure it matches below strings if(ALLOCATOR) if(${ALLOCATOR} STREQUAL "tcmalloc") - find_package(tcmalloc REQUIRED) - set(HAVE_LIBTCMALLOC ${Tcmalloc_FOUND}) + find_package(gperftools REQUIRED) + set(HAVE_LIBTCMALLOC ON) elseif(${ALLOCATOR} STREQUAL "jemalloc") find_package(JeMalloc REQUIRED) set(HAVE_LIBJEMALLOC ${JEMALLOC_FOUND}) endif() else(ALLOCATOR) - find_package(tcmalloc) - set(HAVE_LIBTCMALLOC ${Tcmalloc_FOUND}) - if(NOT ${Tcmalloc_FOUND}) + find_package(gperftools) + set(HAVE_LIBTCMALLOC ${GPERFTOOLS_FOUND}) + if(NOT GPERFTOOLS_FOUND) find_package(JeMalloc) set(HAVE_LIBJEMALLOC ${JEMALLOC_FOUND}) - endif(NOT ${Tcmalloc_FOUND}) - if(Tcmalloc_FOUND) + endif(NOT GPERFTOOLS_FOUND) + if(GPERFTOOLS_FOUND) set(ALLOCATOR tcmalloc) elseif(JEMALLOC_FOUND) set(ALLOCATOR jemalloc) else() message(WARNING "tcmalloc and jemalloc not found, falling back to libc") set(ALLOCATOR "libc") - endif(Tcmalloc_FOUND) + endif(GPERFTOOLS_FOUND) endif(ALLOCATOR) if(NOT FREEBSD) diff --git a/cmake/modules/Findgperftools.cmake b/cmake/modules/Findgperftools.cmake index f1bf24a09b5..c4db922f4a0 100644 --- a/cmake/modules/Findgperftools.cmake +++ b/cmake/modules/Findgperftools.cmake @@ -1,29 +1,22 @@ -# Try to find Profiler +# Try to find gperftools # Once done, this will define # # GPERFTOOLS_FOUND - system has Profiler # GPERFTOOLS_INCLUDE_DIR - the Profiler include directories -# GPERFTOOLS_LIBRARIES - link these to use Profiler +# Tcmalloc_INCLUDE_DIR - where to find Tcmalloc.h +# GPERFTOOLS_TCMALLOC_LIBRARY - link it to use tcmalloc +# GPERFTOOLS_TCMALLOC_MINIMAL_LIBRARY - link it to use tcmalloc_minimal +# GPERFTOOLS_PROFILER_LIBRARY - link it to use Profiler -if(GPERFTOOLS_INCLUDE_DIR AND GPERFTOOLS_LIBRARIES) - set(GPERFTOOLS_FIND_QUIETLY TRUE) -endif(GPERFTOOLS_INCLUDE_DIR AND GPERFTOOLS_LIBRARIES) +find_path(GPERFTOOLS_INCLUDE_DIR gperftools/profiler.h) +find_path(Tcmalloc_INCLUDE_DIR gperftools/tcmalloc.h) -# include dir -find_path(GPERFTOOLS_INCLUDE_DIR profiler.h NO_DEFAULT_PATH PATHS - /usr/include - /usr/include/gperftools - /usr/include/google - /opt/local/include - /usr/local/include -) +foreach(component tcmalloc tcmalloc_minimal profiler) + string(TOUPPER ${component} COMPONENT) + find_library(GPERFTOOLS_${COMPONENT}_LIBRARY ${component}) + list(APPEND GPERFTOOLS_LIBRARIES GPERFTOOLS_${COMPONENT}_LIBRARY) +endforeach() -# finally the library itself -find_library(LIBPROFILER NAMES profiler) -set(GPERFTOOLS_LIBRARIES ${LIBPROFILER}) - -# handle the QUIETLY and REQUIRED arguments and set GPERFTOOLS_FOUND to TRUE if -# all listed variables are TRUE include(FindPackageHandleStandardArgs) find_package_handle_standard_args(gperftools DEFAULT_MSG GPERFTOOLS_LIBRARIES GPERFTOOLS_INCLUDE_DIR) diff --git a/cmake/modules/Findtcmalloc.cmake b/cmake/modules/Findtcmalloc.cmake deleted file mode 100644 index 9b4cf1a8070..00000000000 --- a/cmake/modules/Findtcmalloc.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# - Find Tcmalloc -# Find the native Tcmalloc includes and library -# -# Tcmalloc_INCLUDE_DIR - where to find Tcmalloc.h, etc. -# Tcmalloc_LIBRARIES - List of libraries when using Tcmalloc. -# Tcmalloc_FOUND - True if Tcmalloc found. - -find_path(Tcmalloc_INCLUDE_DIR google/tcmalloc.h PATHS - /usr/include - /opt/local/include - /usr/local/include) - -find_library(Tcmalloc_LIBRARY - NAMES tcmalloc_minimal tcmalloc - PATHS /lib /usr/lib /usr/local/lib /opt/local/lib) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Tcmalloc - FOUND_VAR Tcmalloc_FOUND - REQUIRED_VARS Tcmalloc_INCLUDE_DIR Tcmalloc_LIBRARY) - -if(Tcmalloc_FOUND) - set(Tcmalloc_LIBRARIES ${Tcmalloc_LIBRARY}) -endif() - -mark_as_advanced( - Tcmalloc_LIBRARY - Tcmalloc_INCLUDE_DIR) diff --git a/configure.ac b/configure.ac index eba694b5097..be2397b80e0 100644 --- a/configure.ac +++ b/configure.ac @@ -637,7 +637,8 @@ AS_IF([test "$with_profiler" = yes -o \ [AC_LANG_PUSH([C++]) AC_CHECK_HEADERS([gperftools/heap-profiler.h \ gperftools/malloc_extension.h \ - gperftools/profiler.h]) + gperftools/profiler.h], [], + [AC_MSG_FAILURE([gperftools headers not found (use --without-profiler or disable tcmalloc)])]) AC_LANG_POP([C++])]) # error out if --with-jemalloc and ! --without-tcmalloc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ffa417651d7..fe1f5d832c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -229,15 +229,6 @@ if(WITH_PROFILER) list(APPEND EXTRALIBS profiler) endif(WITH_PROFILER) -if(WITH_PROFILER AND ALLOCATOR STREQUAL "tcmalloc") - find_file(HAVE_GPERFTOOLS_HEAP_PROFILER_H heap-profiler.h - PATHS ${GPERFTOOLS_INCLUDE_DIR}) - find_file(HAVE_GPERFTOOLS_MALLOC_EXTENSION_H malloc_extension.h - PATHS ${GPERFTOOLS_INCLUDE_DIR}) - find_file(HAVE_GPERFTOOLS_PROFILER_H profiler.h - PATHS ${GPERFTOOLS_INCLUDE_DIR}) -endif() - if(${ENABLE_COVERAGE}) find_program(HAVE_GCOV gcov) if(NOT HAVE_GCOV) @@ -291,7 +282,7 @@ endif(HAVE_XIO) # sort out which allocator to use if(ALLOCATOR STREQUAL "tcmalloc") - set(ALLOC_LIBS tcmalloc) + set(ALLOC_LIBS ${GPERFTOOLS_TCMALLOC_LIBRARY}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free") set(TCMALLOC_srcs perfglue/heap_profiler.cc) elseif(ALLOCATOR STREQUAL "jemalloc") diff --git a/src/include/config-h.in.cmake b/src/include/config-h.in.cmake index 1d6bc706f68..1123f5812d6 100644 --- a/src/include/config-h.in.cmake +++ b/src/include/config-h.in.cmake @@ -105,15 +105,6 @@ /* Defined if LevelDB supports bloom filters */ #cmakedefine HAVE_LEVELDB_FILTER_POLICY -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_GPERFTOOLS_HEAP_PROFILER_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_GPERFTOOLS_MALLOC_EXTENSION_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_GPERFTOOLS_PROFILER_H 1 - /* Define if you have tcmalloc */ #cmakedefine HAVE_LIBTCMALLOC diff --git a/src/perfglue/cpu_profiler.cc b/src/perfglue/cpu_profiler.cc index d2a69842090..beec88533d0 100644 --- a/src/perfglue/cpu_profiler.cc +++ b/src/perfglue/cpu_profiler.cc @@ -14,14 +14,7 @@ #include "acconfig.h" -// Use the newer gperftools header locations if available. -// If not, fall back to the old (gperftools < 2.0) locations. - -#ifdef HAVE_GPERFTOOLS_PROFILER_H - #include -#else - #include -#endif +#include #include "common/LogClient.h" #include "perfglue/cpu_profiler.h" diff --git a/src/perfglue/heap_profiler.cc b/src/perfglue/heap_profiler.cc index 685b4be5738..5a329e2ceb3 100644 --- a/src/perfglue/heap_profiler.cc +++ b/src/perfglue/heap_profiler.cc @@ -17,17 +17,8 @@ // Use the newer gperftools header locations if available. // If not, fall back to the old (gperftools < 2.0) locations. -#ifdef HAVE_GPERFTOOLS_HEAP_PROFILER_H - #include -#else - #include -#endif - -#ifdef HAVE_GPERFTOOLS_MALLOC_EXTENSION_H - #include -#else - #include -#endif +#include +#include #include "heap_profiler.h" #include "common/environment.h"