Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace BFD with libelf, rework IP-resolution, decrease unkown function rate significantly, add support for DWARF and debuginfod #351

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install binutils-dev libiberty-dev libsensors-dev
sudo apt-get install libelf-dev libdw-dev libsensors-dev
sudo pip install git-archive-all
- name: Cache OTF2
id: cache-otf2
Expand Down
36 changes: 27 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,54 @@ set_property(CACHE lo2s_USE_STATIC_LIBS PROPERTY STRINGS "MOSTLY" "OFF" "ALL")

IfUpdatedUnsetAll(lo2s_USE_STATIC_LIBS
Dl_USE_STATIC_LIBS
Binutils_USE_STATIC_LIBS
LibElf_USE_STATIC_LIBS
OTF2_USE_STATIC_LIBS
OTF2XX_USE_STATIC_LIBS
Libpfm_USE_STATIC_LIBS
X86Adapt_STATIC
x86_energy_STATIC
CUDA_USE_STATIC_LIBS
Debuginfod_USE_STATIC_LIBS
)

if(lo2s_USE_STATIC_LIBS STREQUAL "OFF")
set(Dl_USE_STATIC_LIBS OFF CACHE BOOL "")
set(Binutils_USE_STATIC_LIBS OFF CACHE BOOL "")
set(LibElf_USE_STATIC_LIBS OFF CACHE BOOL "")
set(OTF2_USE_STATIC_LIBS OFF CACHE BOOL "")
set(OTF2XX_USE_STATIC_LIBS OFF CACHE BOOL "")
set(X86Adapt_STATIC OFF CACHE BOOL "")
set(x86_energy_STATIC OFF CACHE BOOL "")
set(Sensors_USE_STATIC_LIBS OFF CACHE BOOL "")
set(Libpfm_USE_STATIC_LIBS OFF CACHE BOOL "")
set(CUDA_USE_STATIC_LIBS OFF CACHE BOOL "")
set(Debuginfod_USE_STATIC_LIBS OFF CACHE BOOL "")
endif()

if(lo2s_USE_STATIC_LIBS STREQUAL "MOSTLY")
set(Dl_USE_STATIC_LIBS OFF CACHE BOOL "")
set(Binutils_USE_STATIC_LIBS ON CACHE BOOL "")
set(LibElf_USE_STATIC_LIBS ON CACHE BOOL "")
set(OTF2_USE_STATIC_LIBS ON CACHE BOOL "")
set(OTF2XX_USE_STATIC_LIBS ON CACHE BOOL "")
set(X86Adapt_STATIC ON CACHE BOOL "")
set(x86_energy_STATIC ON CACHE BOOL "")
set(Sensors_USE_STATIC_LIBS ON CACHE BOOL "")
set(Libpfm_USE_STATIC_LIBS ON CACHE BOOL "")
set(CUDA_USE_STATIC_LIBS ON CACHE BOOL "")
set(Debuginfod_USE_STATIC_LIBS ON CACHE BOOL "")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif()

if(lo2s_USE_STATIC_LIBS STREQUAL "ALL")
set(Dl_USE_STATIC_LIBS ON CACHE BOOL "")
set(Binutils_USE_STATIC_LIBS ON CACHE BOOL "")
set(LibElf_USE_STATIC_LIBS ON CACHE BOOL "")
set(OTF2_USE_STATIC_LIBS ON CACHE BOOL "")
set(OTF2XX_USE_STATIC_LIBS ON CACHE BOOL "")
set(X86Adapt_STATIC ON CACHE BOOL "")
set(x86_energy_STATIC ON CACHE BOOL "")
set(Sensors_USE_STATIC_LIBS ON CACHE BOOL "")
set(Libpfm_USE_STATIC_LIBS ON CACHE BOOL "")
set(CUDA_USE_STATIC_LIBS ON CACHE BOOL "")
set(Debuginfod_USE_STATIC_LIBS ON CACHE BOOL "")

# Doesn't seem to work with clang, even though it should,
# but at least it doesn't complain about it either
Expand Down Expand Up @@ -101,7 +105,6 @@ include(lib/x86_adapt/x86_adapt.cmake)

# find external dependencies
find_package(Git)
find_package(Binutils REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG true)
find_package(Threads REQUIRED)
find_package(Doxygen COMPONENTS dot)
Expand All @@ -112,6 +115,8 @@ find_package(Veosinfo)
find_package(Libpfm)
find_package(PkgConfig)
find_package(CUDAToolkit)
find_package(LibElf REQUIRED)
find_package(Debuginfod)

if(PkgConfig_FOUND)
pkg_check_modules(Audit audit)
Expand All @@ -136,6 +141,8 @@ CMAKE_DEPENDENT_OPTION(USE_VEOSINFO "Use libveosinfo to sample NEC SX-Aurora Tsu
add_feature_info("USE_VEOSINFO" USE_VEOSINFO "Use libveosinfo to sample NEC SX-Aurora Tsubasa cards.")
CMAKE_DEPENDENT_OPTION(USE_CUPTI "Use CUPTI to record CUDA activity." ON "CUDAToolkit_FOUND" OFF)
add_feature_info("USE_CUPTI" USE_CUPTI "Use CUPTI to record CUDA activity.")
CMAKE_DEPENDENT_OPTION(USE_DEBUGINFOD "Use Debuginfod to download debug information on-demand." ON "Debuginfod_FOUND" OFF)
add_feature_info("USE_DEBUGINFOD" USE_DEBUGINFOD "Use Debuginfod to download debug information on-demand.")
# system configuration checks
CHECK_INCLUDE_FILES(linux/hw_breakpoint.h HAVE_HW_BREAKPOINT_H)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_attr" clockid linux/perf_event.h HAVE_PERF_EVENT_ATTR_CLOCKID)
Expand Down Expand Up @@ -164,6 +171,7 @@ if(NOT HAVE_PERF_RECORD_SWITCH)
message(FATAL_ERROR "lo2s requires support for perf context switch recording. Make sure that you are running on a kernel that support context_switch with perf_event_open")
endif()


# detect version of running kernel
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LINUX_VERSION ${CMAKE_SYSTEM_VERSION})

Expand Down Expand Up @@ -206,8 +214,8 @@ set(SOURCE_FILES

src/config.cpp src/main.cpp src/monitor/process_monitor.cpp
src/platform.cpp
src/topology.cpp src/bfd_resolve.cpp src/pipe.cpp
src/mmap.cpp
src/process_info.cpp
src/topology.cpp src/pipe.cpp src/dwarf_resolve.cpp
src/util.cpp
src/perf/util.cpp
src/syscalls.cpp
Expand All @@ -226,10 +234,11 @@ target_link_libraries(lo2s
Nitro::dl
Nitro::options
Threads::Threads
Binutils::Binutils
fmt::fmt
std::filesystem
)
LibElf::LibElf
LibElf::LibDw
)

# old glibc versions require -lrt for clock_gettime()
if(NOT CLOCK_GETTIME_FOUND)
Expand Down Expand Up @@ -310,6 +319,15 @@ if (USE_VEOSINFO)
endif()
endif()

if (USE_DEBUGINFOD)
if (Debuginfod_FOUND)
target_compile_definitions(lo2s PUBLIC HAVE_DEBUGINFOD)
target_link_libraries(lo2s PRIVATE Debuginfod::Debuginfod)
else()
message(SEND_ERROR "Debuginfod not found but requested")
endif()
endif()

if (USE_LIBPFM)
if (Libpfm_FOUND)
target_compile_definitions(lo2s PUBLIC HAVE_LIBPFM)
Expand Down
56 changes: 56 additions & 0 deletions cmake/FindDebuginfod.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2022, Technische Universität Dresden, Germany
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the
# distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include(${CMAKE_CURRENT_LIST_DIR}/UnsetIfUpdated.cmake)

# Linking libelf isn't a great default because it produces warnings
option(Debuginfod_USE_STATIC_LIBS "Link debuginfod statically." OFF)

UnsetIfUpdated(Debuginfod_LIBRARY Debuginfod_USE_STATIC_LIBS)

find_path(Debuginfod_INCLUDE_DIRS libelf.h
PATHS ENV C_INCLUDE_PATH ENV CPATH
PATH_SUFFIXES include)

if(Debuginfod_USE_STATIC_LIBS)
find_library(Debuginfod_LIBRARY NAMES libdebuginfod.a
HINTS ENV LIBRARY_PATH)
else()
find_library(Debuginfod_LIBRARY NAMES libdebuginfod.so
HINTS ENV LIBRARY_PATH LD_LIBRARY_PATH)
endif()

include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Debuginfod DEFAULT_MSG
Debuginfod_LIBRARY
Debuginfod_INCLUDE_DIRS)

if(Debuginfod_FOUND)
add_library(Debuginfod::Debuginfod UNKNOWN IMPORTED)
set_property(TARGET Debuginfod::Debuginfod PROPERTY IMPORTED_LOCATION ${Debuginfod_LIBRARY})
target_include_directories(Debuginfod::Debuginfod INTERFACE ${Debuginfod_INCLUDE_DIRS})
endif()

mark_as_advanced(Debuginfod_LIBRARY Debuginfod_INCLUDE_DIRS)
69 changes: 69 additions & 0 deletions cmake/FindLibElf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) 2022, Technische Universität Dresden, Germany
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the
# distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include(${CMAKE_CURRENT_LIST_DIR}/UnsetIfUpdated.cmake)

# Linking libelf isn't a great default because it produces warnings
option(LibElf_USE_STATIC_LIBS "Link libelf statically." OFF)

UnsetIfUpdated(LibElf_LIBRARIES LibElf_USE_STATIC_LIBS)

find_path(LibElf_INCLUDE_DIRS libelf.h
PATHS ENV C_INCLUDE_PATH ENV CPATH
PATH_SUFFIXES include)

find_path(LibDw_INCLUDE_DIRS elfutils/libdw.h
PATHS ENV C_INCLUDE_PATH ENV CPATH
PATH_SUFFIXES include)

if(LibElf_USE_STATIC_LIBS)
find_library(LibElf_LIBRARY NAMES libelf.a
HINTS ENV LIBRARY_PATH)
find_library(LibDw_LIBRARY NAMES libdw.a
HINTS ENV LIBRARY_PATH)
set(LibElf_LIBRARIES ${LibElf_LIBRARY} ${LibDw_LIBRARY})
else()
find_library(LibElf_LIBRARY NAMES libelf.so
HINTS ENV LIBRARY_PATH LD_LIBRARY_PATH)
find_library(LibDw_LIBRARY NAMES libdw.so
HINTS ENV LIBRARY_PATH LD_LIBRARY_PATH)
set(LibElf_LIBRARIES ${LibElf_LIBRARY} ${LibDw_LIBRARY})
endif()

include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibElf DEFAULT_MSG
LibElf_LIBRARIES
LibElf_INCLUDE_DIRS)

if(LibElf_FOUND)
add_library(LibElf::LibElf UNKNOWN IMPORTED)
set_property(TARGET LibElf::LibElf PROPERTY IMPORTED_LOCATION ${LibElf_LIBRARY})
target_include_directories(LibElf::LibElf INTERFACE ${LibElf_INCLUDE_DIRS})
add_library(LibElf::LibDw UNKNOWN IMPORTED)
set_property(TARGET LibElf::LibDw PROPERTY IMPORTED_LOCATION ${LibDw_LIBRARY})
target_include_directories(LibElf::LibDw INTERFACE ${LibDw_INCLUDE_DIRS})
endif()

mark_as_advanced(LibElf_LIBRARIES LibElf_INCLUDE_DIRS)
Loading
Loading