]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: cleanup Findgperftools.cmake
authorKefu Chai <kchai@redhat.com>
Wed, 10 Aug 2016 16:12:05 +0000 (00:12 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 11 Aug 2016 06:06:39 +0000 (14:06 +0800)
* 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>
CMakeLists.txt
cmake/modules/Findgperftools.cmake
cmake/modules/Findtcmalloc.cmake [deleted file]
configure.ac
src/CMakeLists.txt
src/include/config-h.in.cmake
src/perfglue/cpu_profiler.cc
src/perfglue/heap_profiler.cc

index 7edf4566bdd40065118cab08cefa8b882f0714c8..0cd73bfab6bad1fc8b4f7ecb46768b626ab5d0e9 100644 (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)
index f1bf24a09b58b88753a8a7c15df831a56669419f..c4db922f4a0c02ffae6384756e1b73b1c14c701c 100644 (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)
 
diff --git a/cmake/modules/Findtcmalloc.cmake b/cmake/modules/Findtcmalloc.cmake
deleted file mode 100644 (file)
index 9b4cf1a..0000000
+++ /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)
index eba694b50970672356f8ada5e51dfcbb80ac536e..be2397b80e009d6644760f5144f23ba79b9176d2 100644 (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
index ffa417651d7b193640f30b02f054f6b8b648ac5e..fe1f5d832c23e3a28f69625ef96ac915a3da8547 100644 (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")
index 1d6bc706f68e70f42bd959144663b4ac0a0889ca..1123f5812d6fbbfd825cc57eb0294cf909dbadae 100644 (file)
 /* 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
 
index d2a69842090381d1cd2b9d0c593eb9f6644405b0..beec88533d0e869c68df53dee4577d026b60712a 100644 (file)
 
 #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"
index 685b4be5738098cea5675d5638e8d8a57e3b37e8..5a329e2ceb3d4610ba1e1de22a8b6e783121dc65 100644 (file)
 // 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"