diff --git a/CMakeLists.txt b/CMakeLists.txt index 02568ba10..21be37be1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,11 @@ if( UNIX ) find_package(Readline) find_package(ZLIB) find_package(BZip2) + + if ( WITH_PERFTOOLS ) + find_package(Gperftools) + endif() + endif() if(NOT WITHOUT_GIT) diff --git a/conf/config.cmake.dist b/conf/config.cmake.dist index f51b4d883..a2d5db1ca 100644 --- a/conf/config.cmake.dist +++ b/conf/config.cmake.dist @@ -5,5 +5,6 @@ option(USE_SCRIPTPCH "Use precompiled headers when compiling scripts" option(USE_COREPCH "Use precompiled headers when compiling servers" 1) option(WITH_WARNINGS "Show all warnings during compile" 0) option(WITH_COREDEBUG "Include additional debug-code in core" 0) +option(WITH_PERFTOOLS "Enable compilation with gperftools libraries included" 0) option(WITH_MESHEXTRACTOR "Build meshextractor (alpha)" 0) option(WITHOUT_GIT "Disable the GIT testing routines" 0) diff --git a/modules/worldengine/nucleus/src/cmake/macros/FindGperftools.cmake b/modules/worldengine/nucleus/src/cmake/macros/FindGperftools.cmake new file mode 100644 index 000000000..f35104d2f --- /dev/null +++ b/modules/worldengine/nucleus/src/cmake/macros/FindGperftools.cmake @@ -0,0 +1,51 @@ +# Tries to find Gperftools. +# +# Usage of this module as follows: +# +# find_package(Gperftools) +# +# Variables used by this module, they can change the default behaviour and need +# to be set before calling find_package: +# +# Gperftools_ROOT_DIR Set this variable to the root installation of +# Gperftools if the module has problems finding +# the proper installation path. +# +# Variables defined by this module: +# +# GPERFTOOLS_FOUND System has Gperftools libs/headers +# GPERFTOOLS_LIBRARIES The Gperftools libraries (tcmalloc & profiler) +# GPERFTOOLS_INCLUDE_DIR The location of Gperftools headers + +find_library(GPERFTOOLS_TCMALLOC + NAMES tcmalloc + HINTS ${Gperftools_ROOT_DIR}/lib) + +find_library(GPERFTOOLS_PROFILER + NAMES profiler + HINTS ${Gperftools_ROOT_DIR}/lib) + +find_library(GPERFTOOLS_TCMALLOC_AND_PROFILER + NAMES tcmalloc_and_profiler + HINTS ${Gperftools_ROOT_DIR}/lib) + +find_path(GPERFTOOLS_INCLUDE_DIR + NAMES gperftools/heap-profiler.h + HINTS ${Gperftools_ROOT_DIR}/include) + +set(GPERFTOOLS_LIBRARIES ${GPERFTOOLS_TCMALLOC_AND_PROFILER}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + Gperftools + DEFAULT_MSG + GPERFTOOLS_LIBRARIES + GPERFTOOLS_INCLUDE_DIR) + +mark_as_advanced( + Gperftools_ROOT_DIR + GPERFTOOLS_TCMALLOC + GPERFTOOLS_PROFILER + GPERFTOOLS_TCMALLOC_AND_PROFILER + GPERFTOOLS_LIBRARIES + GPERFTOOLS_INCLUDE_DIR) \ No newline at end of file diff --git a/src/cmake/showoptions.cmake b/src/cmake/showoptions.cmake index 0b935bd6c..28b70b457 100644 --- a/src/cmake/showoptions.cmake +++ b/src/cmake/showoptions.cmake @@ -65,6 +65,15 @@ else() message("* Use coreside debug : No (default)") endif() +if ( UNIX ) + if( WITH_PERFTOOLS ) + message("* Use unix gperftools : Yes") + add_definitions(-DPERF_TOOLS) + else() + message("* Use unix gperftools : No (default)") + endif() +endif( UNIX ) + if( WIN32 ) if( USE_MYSQL_SOURCES ) message("* Use MySQL sourcetree : Yes (default)") diff --git a/src/worldserver/CMakeLists.txt b/src/worldserver/CMakeLists.txt index 040ebdfd7..4dfe57833 100644 --- a/src/worldserver/CMakeLists.txt +++ b/src/worldserver/CMakeLists.txt @@ -174,6 +174,7 @@ target_link_libraries(worldserver g3dlib gsoap Detour + ${GPERFTOOLS_LIBRARIES} ${JEMALLOC_LIBRARY} ${READLINE_LIBRARY} ${TERMCAP_LIBRARY}