[gperftools] Update to 2.16, revise, test (#41904)

This commit is contained in:
Kai Pastor 2024-11-14 12:02:47 +01:00 committed by GitHub
parent 472f836ce0
commit 6378599835
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 239 additions and 334 deletions

View File

@ -1,211 +0,0 @@
cmake_minimum_required(VERSION 3.5)
project(gperftools LANGUAGES C CXX)
include(GNUInstallDirs)
option(GPERFTOOLS_BUILD_TOOLS "Build tools" ON)
if(WIN32) # TODO: MINGW, MSYS
option(GPERFTOOLS_WIN32_OVERRIDE "Override allocators" OFF)
endif()
set(deprecated_public_headers
src/google/heap-checker.h
src/google/heap-profiler.h
src/google/malloc_extension.h
src/google/malloc_extension_c.h
src/google/malloc_hook.h
src/google/malloc_hook_c.h
src/google/profiler.h
src/google/stacktrace.h
)
set(gperftools_public_headers
src/gperftools/heap-checker.h
src/gperftools/heap-profiler.h
src/gperftools/malloc_extension.h
src/gperftools/malloc_extension_c.h
src/gperftools/malloc_hook.h
src/gperftools/malloc_hook_c.h
src/gperftools/nallocx.h
src/gperftools/profiler.h
src/gperftools/stacktrace.h
)
if(WIN32) # TODO: MINGW, MSYS
list(APPEND deprecated_public_headers
src/windows/google/tcmalloc.h
)
list(APPEND gperftools_public_headers
src/windows/gperftools/tcmalloc.h
)
set(libtcmalloc_minimal_headers
src/addressmap-inl.h
src/base/arm_instruction_set_select.h
src/base/atomicops-internals-arm-generic.h
src/base/atomicops-internals-arm-v6plus.h
src/base/atomicops-internals-gcc.h
src/base/atomicops-internals-linuxppc.h
src/base/atomicops-internals-macosx.h
src/base/atomicops-internals-mips.h
src/base/atomicops-internals-windows.h
src/base/atomicops-internals-x86.h
src/base/atomicops.h
src/base/basictypes.h
src/base/commandlineflags.h
src/base/googleinit.h
src/base/logging.h
src/base/low_level_alloc.h
src/base/spinlock.h
src/base/spinlock_internal.h
src/base/spinlock_linux-inl.h
src/base/spinlock_posix-inl.h
src/base/spinlock_win32-inl.h
src/base/stl_allocator.h
src/base/sysinfo.h
src/base/thread_annotations.h
src/central_freelist.h
src/common.h
src/gperftools/heap-checker.h
src/gperftools/heap-profiler.h
src/gperftools/malloc_extension.h
src/gperftools/malloc_hook.h
src/gperftools/profiler.h
src/gperftools/stacktrace.h
src/heap-profile-table.h
src/internal_logging.h
src/malloc_hook-inl.h
src/memory_region_map.h
src/packed-cache-inl.h
src/pagemap.h
src/page_heap.h
src/page_heap_allocator.h
src/raw_printer.h
src/sampler.h
src/span.h
src/stacktrace_win32-inl.h
src/stack_trace_table.h
src/static_vars.h
src/symbolize.h
src/system-alloc.h
src/tcmalloc.h
src/thread_cache.h
src/windows/config.h
src/windows/mini_disassembler.h
src/windows/mini_disassembler_types.h
src/windows/port.h
src/windows/preamble_patcher.h
)
set(libtcmalloc_minimal_sources
src/base/dynamic_annotations.c
src/base/logging.cc
src/base/low_level_alloc.cc
src/base/spinlock.cc
src/base/spinlock_internal.cc
src/base/sysinfo.cc
src/central_freelist.cc
src/common.cc
src/fake_stacktrace_scope.cc
src/heap-profile-table.cc
src/internal_logging.cc
src/malloc_extension.cc
src/malloc_hook.cc
src/memory_region_map.cc
src/page_heap.cc
src/raw_printer.cc
src/sampler.cc
src/span.cc
src/stacktrace.cc
src/stack_trace_table.cc
src/static_vars.cc
src/symbolize.cc
src/thread_cache.cc
src/windows/ia32_modrm_map.cc
src/windows/ia32_opcode_map.cc
src/windows/mini_disassembler.cc
src/windows/port.cc
src/windows/preamble_patcher.cc
src/windows/preamble_patcher_with_stub.cc
src/windows/system-alloc.cc
)
if(GPERFTOOLS_WIN32_OVERRIDE)
list(APPEND libtcmalloc_minimal_sources src/windows/override_functions.cc)
else()
list(APPEND libtcmalloc_minimal_sources src/windows/patch_functions.cc)
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
source_group("Header Files" FILES ${libtcmalloc_minimal_headers})
source_group("Source Files" FILES ${libtcmalloc_minimal_sources})
if(GPERFTOOLS_WIN32_OVERRIDE)
add_library(libtcmalloc_minimal
STATIC
${libtcmalloc_minimal_headers}
${libtcmalloc_minimal_sources}
)
else()
add_library(libtcmalloc_minimal
${libtcmalloc_minimal_headers}
${libtcmalloc_minimal_sources}
)
endif()
target_compile_definitions(
libtcmalloc_minimal
PRIVATE
$<$<BOOL:${GPERFTOOLS_WIN32_OVERRIDE}>:
WIN32_OVERRIDE_ALLOCATORS
PERFTOOLS_DLL_DECL=
>
)
target_compile_options(
libtcmalloc_minimal
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:
/wd4141
/wd4251
>
)
target_include_directories(
libtcmalloc_minimal
PUBLIC
$<BUILD_INTERFACE:
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/src/windows
>
)
install(FILES ${deprecated_public_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/google
)
install(FILES ${gperftools_public_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gperftools
)
install(TARGETS libtcmalloc_minimal
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
if(GPERFTOOLS_BUILD_TOOLS)
add_executable(addr2line-pdb src/windows/addr2line-pdb.c)
target_link_libraries(addr2line-pdb PRIVATE DbgHelp)
add_executable(nm-pdb src/windows/nm-pdb.c)
target_link_libraries(nm-pdb PRIVATE DbgHelp)
install(TARGETS addr2line-pdb nm-pdb DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
else()
endif()

View File

@ -0,0 +1,4 @@
if(ANDROID)
include(CheckFunctionExists)
check_function_exists("glob" HAVE_GLOB_H)
endif()

View File

@ -0,0 +1,89 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e9647d5..092f40d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -424,7 +424,7 @@ if(MSVC)
endif()
add_library(common
- STATIC
+ OBJECT
src/base/logging.cc
src/base/generic_writer.cc
src/base/sysinfo.cc
@@ -497,7 +497,7 @@ endif()
if(WITH_STACK_TRACE)
### Making the library
- add_library(stacktrace STATIC
+ add_library(stacktrace OBJECT
src/stacktrace.cc
src/base/elf_mem_image.cc
src/base/vdso_support.cc)
@@ -926,4 +926,66 @@ if(MSVC)
add_subdirectory(src/windows)
endif()
+foreach(lib IN ITEMS
+ common stacktrace
+ tcmalloc_minimal tcmalloc tcmalloc_minimal_debug tcmalloc_debug
+ profiler
+)
+ if(TARGET "${lib}")
+ install(TARGETS "${lib}")
+ if(lib MATCHES "tcmalloc|profiler")
+ set(pc_file "${CMAKE_CURRENT_BINARY_DIR}/lib${lib}.pc")
+ set(pc_libs_private "${CMAKE_THREAD_LIBS_INIT}")
+ if("execinfo" IN_LIST unwind_libs AND lib MATCHES "tcmalloc")
+ string(APPEND pc_libs_private " -lexecinfo")
+ endif()
+ set(pc_requires_private "")
+ if(gperftools_enable_libunwind AND lib MATCHES "tcmalloc")
+ string(APPEND pc_requires_private " libunwind")
+ endif()
+ file(CONFIGURE OUTPUT "${pc_file}" CONTENT [[
+prefix=
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: @PROJECT_NAME@
+Version: @PROJECT_VERSION@
+Description: Performance tools for C++
+URL: https://github.com/gperftools/gperftools
+Cflags: -I${includedir}
+Libs: -L${libdir} -l@lib@
+Libs.private: @pc_libs_private@
+Requires.private: @pc_requires_private@
+]] @ONLY)
+ install(FILES "${pc_file}" DESTINATION "lib/pkgconfig")
+ endif()
+ endif()
+endforeach()
+
+foreach(exe IN ITEMS addr2line-pdb nm-pdb)
+ if(NOT TARGET "${exe}")
+ continue()
+ elseif(GPERFTOOLS_BUILD_TOOLS)
+ install(TARGETS "${exe}")
+ else()
+ set_target_properties("${exe}" PROPERTIES EXCLUDE_FROM_ALL 1)
+ endif()
+endforeach()
+
+install(
+ FILES
+ src/gperftools/heap-checker.h
+ src/gperftools/heap-profiler.h
+ src/gperftools/malloc_extension.h
+ src/gperftools/malloc_extension_c.h
+ src/gperftools/malloc_hook.h
+ src/gperftools/malloc_hook_c.h
+ src/gperftools/nallocx.h
+ src/gperftools/profiler.h
+ src/gperftools/stacktrace.h
+ "${CMAKE_CURRENT_BINARY_DIR}/gperftools/tcmalloc.h"
+ DESTINATION include/gperftools
+)
+
message(WARNING "note: gperftools' cmake support is incomplete and is best-effort only")

View File

@ -1,30 +1,24 @@
diff --git a/configure.ac b/configure.ac diff --git a/CMakeLists.txt b/CMakeLists.txt
index 65a4e24..fc0d7d6 100644 index 52629d3..a93c7e8 100644
--- a/configure.ac --- a/CMakeLists.txt
+++ b/configure.ac +++ b/CMakeLists.txt
@@ -278,9 +278,24 @@ AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes) @@ -241,13 +241,13 @@ if(NOT WIN32)
# We want to link in libunwind if it is enabled and exists. endif()
UNWIND_LIBS=
if test "$enable_libunwind" = yes; then
+ save_CFLAGS="$CFLAGS"
+ save_LIBS="$LIBS"
+ PKG_PROG_PKG_CONFIG
+ PKG_CHECK_MODULES([PC_UNWIND],[libunwind],[
+ CFLAGS="$PC_UNWIND_CFLAGS"
+ LIBS="$PC_UNWIND_LIBS"
+ ],[
+ PC_UNWIND_CFLAGS=""
+ LIBS="-lunwind"
+ ])
AC_CHECK_HEADERS([libunwind.h],
- [AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind)
+ [AC_SEARCH_LIBS(backtrace, [], [
+ save_CFLAGS="$CFLAGS $PC_UNWIND_CFLAGS"
+ UNWIND_LIBS="$LIBS"
+ ])
will_use_libunwind=yes])
+ CFLAGS="$save_CFLAGS"
+ LIBS="$save_LIBS"
fi
AC_SUBST(UNWIND_LIBS)
if(gperftools_enable_libunwind)
- check_include_file("libunwind.h" HAVE_LIBUNWIND_H)
+ find_package(PkgConfig REQUIRED)
+ pkg_check_modules(PC_LIBUNWIND libunwind REQUIRED)
+ find_file(HAVE_LIBUNWIND_H "libunwind.h" PATHS ${PC_LIBUNWIND_INCLUDE_DIRS} NO_DEFAULT_PATH REQUIRED)
if(HAVE_LIBUNWIND_H)
- find_library(libunwind_location NAMES unwind)
- if(libunwind_location)
- check_library_exists(
- unwind backtrace ${libunwind_location} have_libunwind)
- endif()
+ include_directories(${PC_LIBUNWIND_INCLUDE_DIRS})
+ set(libunwind_location "${PC_LIBUNWIND_LINK_LIBRARIES}" CACHE INTERNAL "")
+ set(have_libunwind 1)
if(have_libunwind)
set(unwind_libs ${libunwind_location})
set(will_use_libunwind ON)

View File

@ -1,89 +1,65 @@
vcpkg_from_github( vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH OUT_SOURCE_PATH SOURCE_PATH
REPO gperftools/gperftools REPO gperftools/gperftools
REF gperftools-2.10 REF gperftools-${VERSION}
SHA512 4400711723be9401f519d85b3b69c026e4715473cbed48ab0573df17abdf895fb971ee969875fe5127a2e8b9aba90d858285e50c8e012384c2c36d5a76b1f0c4 SHA512 a6eddee06cd6a9344c724522a5bb977082d6ee30eded1c6793d6bb508d4c8542a238dc0f62818c715f09312c858cc90cded0ee95ba2a3ea15fad8a0b78bcdaea
HEAD_REF master HEAD_REF master
PATCHES PATCHES
libunwind.diff libunwind.diff
install.diff
win32-override.diff
) )
file(REMOVE_RECURSE "${SOURCE_PATH}/vendor")
if(VCPKG_TARGET_IS_WINDOWS) if("override" IN_LIST FEATURES)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}") vcpkg_check_linkage(ONLY_STATIC_LIBRARY ONLY_STATIC_CRT)
if(override IN_LIST FEATURES)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
message(STATUS "${PORT}[override] only supports static library linkage. Building static library.")
vcpkg_check_linkage(ONLY_STATIC_LIBRARY ONLY_STATIC_CRT)
endif()
endif()
vcpkg_check_features(
OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
override GPERFTOOLS_WIN32_OVERRIDE
tools GPERFTOOLS_BUILD_TOOLS
)
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
DISABLE_PARALLEL_CONFIGURE
OPTIONS
${FEATURE_OPTIONS}
)
vcpkg_cmake_install()
vcpkg_copy_pdbs()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
file(GLOB gperf_public_headers "${CURRENT_PACKAGES_DIR}/include/gperftools/*.h")
foreach(gperf_header ${gperf_public_headers})
vcpkg_replace_string(${gperf_header} "__declspec(dllimport)" "")
endforeach()
endif()
if(tools IN_LIST FEATURES)
vcpkg_copy_tools(TOOL_NAMES addr2line-pdb nm-pdb AUTO_CLEAN)
endif()
else()
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set(BUILD_OPTS --enable-shared --disable-static)
else()
set(BUILD_OPTS --enable-static --disable-shared)
endif()
if(VCPKG_TARGET_IS_LINUX)
vcpkg_find_acquire_program(PKGCONFIG)
endif()
vcpkg_configure_make(
SOURCE_PATH ${SOURCE_PATH}
AUTOCONFIG
OPTIONS
${BUILD_OPTS}
)
vcpkg_install_make()
if(tools IN_LIST FEATURES)
vcpkg_copy_tools(TOOL_NAMES pprof pprof-symbolize AUTO_CLEAN)
endif()
file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/share"
)
# https://github.com/microsoft/vcpkg/pull/8750#issuecomment-625590773
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
endif()
vcpkg_fixup_pkgconfig()
endif() endif()
file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) vcpkg_check_features(
OUT_FEATURE_OPTIONS OPTIONS
FEATURES
libunwind gperftools_enable_libunwind
override GPERFTOOLS_WIN32_OVERRIDE
tools GPERFTOOLS_BUILD_TOOLS
)
if(gperftools_enable_libunwind)
vcpkg_find_acquire_program(PKGCONFIG)
list(APPEND OPTIONS "-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}")
endif()
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DBUILD_TESTING=OFF
"-DCMAKE_PROJECT_INCLUDE=${CURRENT_PORT_DIR}/cmake-project-include.cmake"
-Dgperftools_build_benchmark=OFF
${OPTIONS}
OPTIONS_DEBUG
-DGPERFTOOLS_BUILD_TOOLS=OFF
MAYBE_UNUSED_VARIABLES
GPERFTOOLS_BUILD_TOOLS
GPERFTOOLS_WIN32_OVERRIDE
)
vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_fixup_pkgconfig()
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(GLOB gperf_public_headers "${CURRENT_PACKAGES_DIR}/include/gperftools/*.h")
foreach(gperf_header IN LISTS gperf_public_headers)
vcpkg_replace_string("${gperf_header}" "__declspec(dllimport)" "")
endforeach()
endif()
if("tools" IN_LIST FEATURES)
if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)
vcpkg_copy_tools(TOOL_NAMES addr2line-pdb nm-pdb AUTO_CLEAN)
endif()
# Perl script
file(INSTALL "${SOURCE_PATH}/src/pprof" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}")
endif()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING")

View File

@ -1,29 +1,29 @@
{ {
"name": "gperftools", "name": "gperftools",
"version": "2.10", "version": "2.16",
"port-version": 2, "description": "A high-performance multi-threaded malloc() implementation, plus some performance analysis tools.",
"description": "A set of tools for performance profiling and memory checking",
"homepage": "https://github.com/gperftools/gperftools", "homepage": "https://github.com/gperftools/gperftools",
"supports": "!(arm & windows) & !uwp & !android", "license": "BSD-3-Clause",
"supports": "((x86 | x64) & windows & !uwp) | !windows | mingw",
"dependencies": [ "dependencies": [
{
"name": "libunwind",
"platform": "linux"
},
{ {
"name": "vcpkg-cmake", "name": "vcpkg-cmake",
"host": true, "host": true
"platform": "windows"
} }
], ],
"features": { "features": {
"libunwind": {
"description": "Support libunwind for stack traces",
"dependencies": [
"libunwind"
]
},
"override": { "override": {
"description": "Override allocators", "description": "Override Windows allocators",
"supports": "windows & staticcrt" "supports": "windows & staticcrt"
}, },
"tools": { "tools": {
"description": "Build gperftools CLI tools", "description": "Install tools"
"supports": "windows"
} }
} }
} }

View File

@ -0,0 +1,16 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2897655..7e93511 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -460,6 +460,11 @@ target_sources(common PRIVATE
set(SYSTEM_ALLOC_CC src/windows/system-alloc.cc)
set(TCMALLOC_CC src/windows/patch_functions.cc)
+if(GPERFTOOLS_WIN32_OVERRIDE)
+ set(TCMALLOC_CC src/windows/override_functions.cc)
+ add_definitions(-DWIN32_OVERRIDE_ALLOCATORS)
+endif()
+
# patch_function uses -lpsapi and spinlock bits use -synchronization
# and -lshlwapi
link_libraries(psapi synchronization shlwapi)

View File

@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)

View File

@ -0,0 +1,31 @@
{
"name": "vcpkg-ci-gperftools",
"version-string": "ci",
"description": "Validates gperftools",
"homepage": "https://github.com/microsoft/vcpkg",
"license": "MIT",
"dependencies": [
"gperftools",
{
"name": "gperftools",
"features": [
"tools"
],
"platform": "native"
},
{
"name": "gperftools",
"features": [
"libunwind"
],
"platform": "linux, osx"
},
{
"name": "gperftools",
"features": [
"override"
],
"platform": "windows & static & staticcrt & !mingw"
}
]
}

View File

@ -3237,8 +3237,8 @@
"port-version": 6 "port-version": 6
}, },
"gperftools": { "gperftools": {
"baseline": "2.10", "baseline": "2.16",
"port-version": 2 "port-version": 0
}, },
"gpgme": { "gpgme": {
"baseline": "1.23.2", "baseline": "1.23.2",

View File

@ -1,5 +1,10 @@
{ {
"versions": [ "versions": [
{
"git-tree": "942debf1003954f938f11be718ad6582b3059c00",
"version": "2.16",
"port-version": 0
},
{ {
"git-tree": "9de2b6bb7a1d0a80fe402a8561161e3cac4ede19", "git-tree": "9de2b6bb7a1d0a80fe402a8561161e3cac4ede19",
"version": "2.10", "version": "2.10",