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 <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2016-08-11 00:12:05 +08:00
parent f440aec1ba
commit 6c12edbf9d
8 changed files with 26 additions and 94 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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")

View File

@ -105,15 +105,6 @@
/* Defined if LevelDB supports bloom filters */
#cmakedefine HAVE_LEVELDB_FILTER_POLICY
/* Define to 1 if you have the <gperftools/heap-profiler.h> header file. */
#cmakedefine HAVE_GPERFTOOLS_HEAP_PROFILER_H 1
/* Define to 1 if you have the <gperftools/malloc_extension.h> header file. */
#cmakedefine HAVE_GPERFTOOLS_MALLOC_EXTENSION_H 1
/* Define to 1 if you have the <gperftools/profiler.h> header file. */
#cmakedefine HAVE_GPERFTOOLS_PROFILER_H 1
/* Define if you have tcmalloc */
#cmakedefine HAVE_LIBTCMALLOC

View File

@ -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 <gperftools/profiler.h>
#else
#include <google/profiler.h>
#endif
#include <gperftools/profiler.h>
#include "common/LogClient.h"
#include "perfglue/cpu_profiler.h"

View File

@ -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 <gperftools/heap-profiler.h>
#else
#include <google/heap-profiler.h>
#endif
#ifdef HAVE_GPERFTOOLS_MALLOC_EXTENSION_H
#include <gperftools/malloc_extension.h>
#else
#include <google/malloc_extension.h>
#endif
#include <gperftools/heap-profiler.h>
#include <gperftools/malloc_extension.h>
#include "heap_profiler.h"
#include "common/environment.h"