链接到 gperftools 时遇到核心转储

问题描述 投票:0回答:1

我有一个客户库,将由java通过JNI调用,然后我想通过gperftools对其进行分析,代码如下:

查找性能工具:

include(ExternalProject)

set(GPERFTOOLS_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/gperftools-install")

set(GPERFTOOLS_CONFIGURE_ARGS
    "AR=${CMAKE_AR}"
    "RANLIB=${CMAKE_RANLIB}"
    "CC=${CMAKE_C_COMPILER}"
    "CXX=${CMAKE_CXX_COMPILER}"
    "--disable-shared"
    "--enable-hidden-visibility"
    "--prefix=${GPERFTOOLS_PREFIX}"
    "CFLAGS=-fPIC"
    "CXXFLAGS=-fPIC")

ExternalProject_Add(
        gperftools
        GIT_REPOSITORY https://github.com/gperftools/gperftools.git
        GIT_TAG gperftools-2.15.90
        UPDATE_COMMAND "./autogen.sh"
        CONFIGURE_COMMAND ./configure --prefix=${GPERFTOOLS_CONFIGURE_ARGS}
        BUILD_COMMAND ""
        BUILD_IN_SOURCE true
        INSTALL_COMMAND $(MAKE) install
        INSTALL_DIR ${GPERFTOOLS_PREFIX}
)

ExternalProject_Get_Property(gperftools INSTALL_DIR)

set(GPERFTOOLS_INCLUDE_DIR ${INSTALL_DIR}/include)
message(STATUS "gperftools include dir: ${GPERFTOOLS_INCLUDE_DIR}")

set(GPERFTOOLS_LIBRARY ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}profiler${CMAKE_STATIC_LIBRARY_SUFFIX})
message(STATUS "gperftools static library: ${GPERFTOOLS_LIBRARY}")

FIND_PACKAGE_HANDLE_STANDARD_ARGS(gperftools DEFAULT_MSG GPERFTOOLS_INCLUDE_DIR GPERFTOOLS_LIBRARY)

set(GPERFTOOLS_LIBRARYS ${GPERFTOOLS_LIBRARY})
set(GPERFTOOLS_INCLUDE_DIRS ${GPERFTOOLS_INCLUDE_DIR})

项目CMakeLists.txt:

if(ENABLE_GPERFTOOLS)
  find_package(gperftools)
  if(NOT gperftools_FOUND)
    message(STATUS "gperftools not found!")
  endif()
  add_dependencies(customer_lib gperftools)

  add_definitions(-DENABLE_GPERFTOOLS)
  target_include_directories(customer_lib PRIVATE ${GPERFTOOLS_INCLUDE_DIRS})
  target_link_libraries(customer_lib PRIVATE ${GPERFTOOLS_LIBRARYS})
endif()

源代码:

#ifdef ENABLE_GPERFTOOLS
  ProfilerStart("")
#endif

other code

#ifdef ENABLE_GPERFTOOLS
  ProfilerStop()
#endif

我在我的笔记本电脑(linux)上运行良好,在生产环境中,它将像这样进行核心转储:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fb5a84ea94f, pid=36567, tid=0x00007fb56d3ff700
#
# Problematic frame:
# C  [libgcc_s.so.1+0xf94f]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

顺便说一句,核心是偶然的。

非常感谢任何建议!

c++ cmake profiling coredump gperftools
1个回答
0
投票

添加编译参数

--enable-frame-pointers
可以解决这个问题,更多信息请参考https://github.com/gperftools/gperftools/issues/1561

© www.soinside.com 2019 - 2024. All rights reserved.