Skip to content

Commit

Permalink
libpfm service ported directly from libpfm example
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredo-gimenez committed May 10, 2017
1 parent 0c6e7ea commit 390119e
Show file tree
Hide file tree
Showing 14 changed files with 1,433 additions and 400 deletions.
20 changes: 13 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ option(WITH_DOCS "Build Caliper documentation" FALSE)
option(WITH_CUDA "Enable Caliper CUDA services" FALSE)
option(WITH_NETOUT "Enable netout service (requires curl)" FALSE)
option(WITH_PAPI "Enable PAPI hardware counter service (requires papi)" TRUE)
option(WITH_PERF_EVENT "Enable perf_event collection service (requires perf_event)" TRUE)
option(WITH_LIBPFM "Enable libpfm (perf_event) sampling" TRUE)
option(WITH_CALLPATH "Enable callpath service (requires libunwind)" TRUE)
option(WITH_MPI "Enable MPI" TRUE)

Expand Down Expand Up @@ -93,12 +93,18 @@ if (WITH_PAPI)
endif()
endif()

# Find perf_event
if (WITH_PERF_EVENT)
include(FindPerfEvent)
if (PerfEvent_FOUND)
set(CALIPER_HAVE_PERF_EVENT TRUE)
message(STATUS "perf_event detected, adding perf_event service")
# Find libpfm
if (WITH_LIBPFM)
include(FindLibpfm)
if(LIBPFM_FOUND)
message(STATUS "Found perfmon/pfmlib_perf_event.h in " ${LIBPFM_INCLUDE_DIR})
message(STATUS "Found libpfm.so in " ${LIBPFM_LIBRARY})
set(CALIPER_HAVE_LIBPFM TRUE)
list(APPEND CALIPER_EXTERNAL_LIBS ${LIBPFM_LIBRARY})
else()
message(STATUS "Could not find libpfm header. \
use -DLIBPFM_INSTALL=<path to libpfm src directory> \
e.g. -DLIBPFM_INSTALL=~/papi/src/libpfm4")
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion caliper-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#cmakedefine CALIPER_HAVE_LIBUNWIND
#cmakedefine CALIPER_HAVE_LIBCURL
#cmakedefine CALIPER_HAVE_PAPI
#cmakedefine CALIPER_HAVE_PERF_EVENT
#cmakedefine CALIPER_HAVE_LIBPFM
#cmakedefine CALIPER_HAVE_MITOS
#cmakedefine CALIPER_HAVE_SAMPLER
#cmakedefine CALIPER_HAVE_NVVP
Expand Down
31 changes: 31 additions & 0 deletions cmake/FindLibpfm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# - Find libpfm
#
# LIBPFM_INCLUDE_DIR - Path to libpfm.h
# LIBPFM_LIBRARY - List of libraries for using libpfm
# LIBPFM_FOUND - True if libpfm was found

set(LIBPFM_INSTALL "" CACHE PATH "libpfm install directory")

if(LIBPFM_INSTALL)
# install dir specified, only search them
find_path(LIBPFM_INCLUDE_DIR "perfmon/pfmlib_perf_event.h"
PATHS ${LIBPFM_INSTALL} ${LIBPFM_INSTALL}/include
NO_DEFAULT_PATH)

find_library(LIBPFM_LIBRARY pfm
PATHS ${LIBPFM_INSTALL} ${LIBPFM_INSTALL}/lib
NO_DEFAULT_PATH)
else()
# no install dir specified, look in default and PAPI
find_path(LIBPFM_INCLUDE_DIR "perfmon/pfmlib_perf_event.h"
HINTS ${PAPI_INCLUDE_DIRS} ${PAPI_INCLUDE_DIRS}/libpfm4/include)

find_library(LIBPFM_LIBRARY pfm
HINTS ${PAPI_LIBRARIES} ${PAPI_LIBRARIES}/libpfm4/include)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libpfm DEFAULT_MSG LIBPFM_LIBRARY LIBPFM_INCLUDE_DIR)

mark_as_advanced(LIBPFM_LIBRARY LIBPFM_INCLUDE_DIR)
16 changes: 0 additions & 16 deletions cmake/FindPerfEvent.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions src/services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ endif()
if (CALIPER_HAVE_PAPI)
add_subdirectory(papi)
endif()
if (CALIPER_HAVE_PERF_EVENT)
add_subdirectory(perf_event)
if (CALIPER_HAVE_LIBPFM)
add_subdirectory(libpfm)
endif()
if (CALIPER_HAVE_LIBCURL)
add_subdirectory(netout)
Expand Down
10 changes: 10 additions & 0 deletions src/services/libpfm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include_directories(${LIBPFM_INCLUDE_DIR})

set(CALIPER_LIBPFM_SOURCES
Libpfm.cpp
perf_util.c)

add_library(caliper-libpfm OBJECT ${CALIPER_LIBPFM_SOURCES})

add_service_objlib("caliper-libpfm")
add_caliper_service("libpfm CALIPER_HAVE_LIBPFM")
Loading

0 comments on commit 390119e

Please sign in to comment.