mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 02:25:53 +00:00
Add jemalloc support to cmake build (RIPD-1472):
Enable jemalloc under option. Create additional option that sets flags appropriate for use with linux perf. Tested with jemalloc on linux and macos.
This commit is contained in:
@@ -156,11 +156,17 @@ macro(setup_build_cache)
|
|||||||
set(assert false CACHE BOOL "Enables asserts, even in release builds")
|
set(assert false CACHE BOOL "Enables asserts, even in release builds")
|
||||||
set(static false CACHE BOOL
|
set(static false CACHE BOOL
|
||||||
"On linux, link protobuf, openssl, libc++, and boost statically")
|
"On linux, link protobuf, openssl, libc++, and boost statically")
|
||||||
|
set(jemalloc false CACHE BOOL "Enables jemalloc for heap profiling")
|
||||||
|
set(perf false CACHE BOOL "Enables flags that assist with perf recording")
|
||||||
|
|
||||||
if (static AND (WIN32 OR APPLE))
|
if (static AND (WIN32 OR APPLE))
|
||||||
message(FATAL_ERROR "Static linking is only supported on linux.")
|
message(FATAL_ERROR "Static linking is only supported on linux.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (perf AND (WIN32 OR APPLE))
|
||||||
|
message(FATAL_ERROR "perf flags are only supported on linux.")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles" AND NOT CMAKE_BUILD_TYPE)
|
if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles" AND NOT CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
endif()
|
endif()
|
||||||
@@ -507,6 +513,10 @@ macro(setup_build_boilerplate)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (perf)
|
||||||
|
add_compile_options(-fno-omit-frame-pointer)
|
||||||
|
endif()
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
add_definitions(
|
add_definitions(
|
||||||
@@ -525,8 +535,18 @@ macro(setup_build_boilerplate)
|
|||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version
|
COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version
|
||||||
ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
|
ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
|
||||||
if ("${LD_VERSION}" MATCHES "GNU gold")
|
# NOTE: THE gold linker inserts -rpath as DT_RUNPATH by default
|
||||||
append_flags(CMAKE_EXE_LINKER_FLAGS -fuse-ld=gold)
|
# intead of DT_RPATH, so you might have slightly unexpected
|
||||||
|
# runtime ld behavior if you were expecting DT_RPATH.
|
||||||
|
# Specify --disable-new-dtags to gold if you do not want
|
||||||
|
# the default DT_RUNPATH behavior. This rpath treatment as well
|
||||||
|
# as static/dynamic selection means that gold does not currently
|
||||||
|
# have ideal default behavior when we are using jemalloc. Thus
|
||||||
|
# for simplicity we don't use it when jemalloc is requested.
|
||||||
|
# An alternative to disabling would be to figure out all the settings
|
||||||
|
# required to make gold play nicely with jemalloc.
|
||||||
|
if (("${LD_VERSION}" MATCHES "GNU gold") AND (NOT jemalloc))
|
||||||
|
append_flags(CMAKE_EXE_LINKER_FLAGS -fuse-ld=gold)
|
||||||
endif ()
|
endif ()
|
||||||
unset(LD_VERSION)
|
unset(LD_VERSION)
|
||||||
endif()
|
endif()
|
||||||
@@ -555,6 +575,15 @@ macro(setup_build_boilerplate)
|
|||||||
STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_C_FLAGS_RELEASECLASSIC "${CMAKE_C_FLAGS_RELEASECLASSIC}")
|
STRING(REGEX REPLACE "[-/]DNDEBUG" "" CMAKE_C_FLAGS_RELEASECLASSIC "${CMAKE_C_FLAGS_RELEASECLASSIC}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (jemalloc)
|
||||||
|
find_package(jemalloc REQUIRED)
|
||||||
|
add_definitions(-DPROFILE_JEMALLOC)
|
||||||
|
include_directories(SYSTEM ${JEMALLOC_INCLUDE_DIRS})
|
||||||
|
link_libraries(${JEMALLOC_LIBRARIES})
|
||||||
|
get_filename_component(JEMALLOC_LIB_PATH ${JEMALLOC_LIBRARIES} DIRECTORY)
|
||||||
|
set(CMAKE_BUILD_RPATH ${CMAKE_BUILD_RPATH} ${JEMALLOC_LIB_PATH})
|
||||||
|
endif()
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||||
append_flags(CMAKE_CXX_FLAGS -frtti -std=c++14 -Wno-invalid-offsetof
|
append_flags(CMAKE_CXX_FLAGS -frtti -std=c++14 -Wno-invalid-offsetof
|
||||||
|
|||||||
47
Builds/CMake/Findjemalloc.cmake
Normal file
47
Builds/CMake/Findjemalloc.cmake
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# - Try to find jemalloc
|
||||||
|
# Once done this will define
|
||||||
|
# JEMALLOC_FOUND - System has jemalloc
|
||||||
|
# JEMALLOC_INCLUDE_DIRS - The jemalloc include directories
|
||||||
|
# JEMALLOC_LIBRARIES - The libraries needed to use jemalloc
|
||||||
|
|
||||||
|
if(NOT USE_BUNDLED_JEMALLOC)
|
||||||
|
find_package(PkgConfig)
|
||||||
|
if (PKG_CONFIG_FOUND)
|
||||||
|
pkg_check_modules(PC_JEMALLOC QUIET jemalloc)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(PC_JEMALLOC_INCLUDEDIR)
|
||||||
|
set(PC_JEMALLOC_INCLUDE_DIRS)
|
||||||
|
set(PC_JEMALLOC_LIBDIR)
|
||||||
|
set(PC_JEMALLOC_LIBRARY_DIRS)
|
||||||
|
set(LIMIT_SEARCH NO_DEFAULT_PATH)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(JEMALLOC_DEFINITIONS ${PC_JEMALLOC_CFLAGS_OTHER})
|
||||||
|
|
||||||
|
find_path(JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h
|
||||||
|
PATHS ${PC_JEMALLOC_INCLUDEDIR} ${PC_JEMALLOC_INCLUDE_DIRS}
|
||||||
|
${LIMIT_SEARCH})
|
||||||
|
|
||||||
|
# If we're asked to use static linkage, add libjemalloc.a as a preferred library name.
|
||||||
|
if(JEMALLOC_USE_STATIC)
|
||||||
|
list(APPEND JEMALLOC_NAMES
|
||||||
|
"${CMAKE_STATIC_LIBRARY_PREFIX}jemalloc${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
list(APPEND JEMALLOC_NAMES jemalloc)
|
||||||
|
|
||||||
|
find_library(JEMALLOC_LIBRARY NAMES ${JEMALLOC_NAMES}
|
||||||
|
HINTS ${PC_JEMALLOC_LIBDIR} ${PC_JEMALLOC_LIBRARY_DIRS}
|
||||||
|
${LIMIT_SEARCH})
|
||||||
|
|
||||||
|
set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY})
|
||||||
|
set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR})
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
# handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE
|
||||||
|
# if all listed variables are TRUE
|
||||||
|
find_package_handle_standard_args(JeMalloc DEFAULT_MSG
|
||||||
|
JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR)
|
||||||
|
|
||||||
|
mark_as_advanced(JEMALLOC_INCLUDE_DIR JEMALLOC_LIBRARY)
|
||||||
@@ -15,11 +15,9 @@
|
|||||||
# * ninja builds
|
# * ninja builds
|
||||||
# * check openssl version on linux
|
# * check openssl version on linux
|
||||||
# * static builds (swd TBD: needs to be tested by building & deploying on different systems)
|
# * static builds (swd TBD: needs to be tested by building & deploying on different systems)
|
||||||
#
|
# * jemalloc enabled builds (linux and macos only)
|
||||||
# TBD:
|
# * perf builds (linux only) - which just sets recommended compiler flags
|
||||||
# * jemalloc support
|
# for running perf on the executable
|
||||||
# * count
|
|
||||||
# * Windows protobuf compiler puts generated file in src directory instead of build directory.
|
|
||||||
#
|
#
|
||||||
# Notes:
|
# Notes:
|
||||||
# * Use the -G"Visual Studio 14 2015 Win64" generator on Windows. Without this
|
# * Use the -G"Visual Studio 14 2015 Win64" generator on Windows. Without this
|
||||||
|
|||||||
Reference in New Issue
Block a user