Clay4megtr
Clay4megtr

Reputation: 21

core dump encountered when linking against to gperftools

I have a customer library which will be invoked by java through JNI, then I want to do a profiling with that through gperftools, the code is below:

Findgperftools:

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})

project 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()

Source code:

#ifdef ENABLE_GPERFTOOLS
  ProfilerStart("")
#endif

other code

#ifdef ENABLE_GPERFTOOLS
  ProfilerStop()
#endif

I works fine on my laptop(linux), by in the production env, it will core dump like this:

#
# 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

btw, the core is accidental.

Any suggestions are very appreciated!

Upvotes: 0

Views: 65

Answers (1)

Clay4megtr
Clay4megtr

Reputation: 21

Add compile args --enable-frame-pointers can fix this issue, more info please refer to https://github.com/gperftools/gperftools/issues/1561

Upvotes: 0

Related Questions