Skip to content

Commit

Permalink
cmake: cleanup Findgperftools.cmake
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
tchaikov committed Aug 11, 2016
1 parent f440aec commit 6c12edb
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 94 deletions.
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 12 additions & 19 deletions cmake/modules/Findgperftools.cmake
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
28 changes: 0 additions & 28 deletions cmake/modules/Findtcmalloc.cmake

This file was deleted.

3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 0 additions & 9 deletions src/include/config-h.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 1 addition & 8 deletions src/perfglue/cpu_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 2 additions & 11 deletions src/perfglue/heap_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6c12edb

Please sign in to comment.