diff mbox series

[1/2] KernelShark2.0: Link KernelShark to libtracefs

Message ID 20200306092902.48786-2-tz.stoyanov@gmail.com (mailing list archive)
State New
Headers show
Series KernelShark2.0: Use libtracefs APIs to access tracefs | expand

Commit Message

Tzvetomir Stoyanov (VMware) March 6, 2020, 9:29 a.m. UTC
From: Tzvetomir (VMware)  Stoyanov <tz.stoyanov@gmail.com>

The tracefs library provides APIs for accessing files from tracefs.
The library is part of trace-cmd, it is installed as part of trace-cmd
installation. KernelShark uses some of those APIs and must be linked with
the library

Signed-off-by: Tzvetomir (VMware)  Stoyanov <tz.stoyanov@gmail.com>
---
 CMakeLists.txt           |  3 ++-
 build/FindTraceCmd.cmake | 28 ++++++++++++++++++++++++++++
 src/CMakeLists.txt       |  2 ++
 3 files changed, 32 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ce2a5ef..846fcf2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,7 +79,8 @@  include_directories(${KS_DIR}/src/
                     ${KS_DIR}/build/src/
                     ${JSONC_INCLUDE_DIR}
                     ${TRACECMD_INCLUDE_DIR}
-                    ${TRACEEVENT_INCLUDE_DIR})
+                    ${TRACEEVENT_INCLUDE_DIR}
+                    ${TRACEFS_INCLUDE_DIR})
 
 message("")
 message(STATUS "C flags      : " ${CMAKE_C_FLAGS})
diff --git a/build/FindTraceCmd.cmake b/build/FindTraceCmd.cmake
index 6278190..802d42e 100644
--- a/build/FindTraceCmd.cmake
+++ b/build/FindTraceCmd.cmake
@@ -6,6 +6,8 @@ 
 #  TRACEEVENT_FOUND, If false, do not try to use traceevent.
 #
 #  TRACECMD_INCLUDE_DIR, where to find trace-cmd header.
+#  TRACEFS_INCLUDE_DIR, where to find tracefs header.
+#  TRACEFS_LIBRARY, the tracefs library.
 #  TRACECMD_LIBRARY, the trace-cmd library.
 #  TRACECMD_FOUND, If false, do not try to use trace-cmd.
 
@@ -31,10 +33,18 @@  find_path(TRACECMD_INCLUDE_DIR   NAMES  trace-cmd/trace-cmd.h
                                  PATHS  $ENV{TRACE_CMD}/include/
                                  NO_DEFAULT_PATH)
 
+find_path(TRACEFS_INCLUDE_DIR    NAMES  tracefs/tracefs.h
+                                 PATHS  $ENV{TRACE_CMD}/include/
+                                NO_DEFAULT_PATH)
+
 find_library(TRACECMD_LIBRARY    NAMES  trace-cmd/libtracecmd.so
                                  PATHS  $ENV{TRACE_CMD}/lib/
                                  NO_DEFAULT_PATH)
 
+find_library(TRACEFS_LIBRARY    NAMES  tracefs/libtracefs.so
+                                PATHS  $ENV{TRACE_CMD}/lib/
+                                NO_DEFAULT_PATH)
+
 find_path(TRACEEVENT_INCLUDE_DIR NAMES  traceevent/event-parse.h
                                  PATHS  $ENV{TRACE_CMD}/include/
                                  NO_DEFAULT_PATH)
@@ -47,7 +57,9 @@  find_library(TRACEEVENT_LIBRARY  NAMES  traceevent/libtraceevent.so
 # search was successful "find_path" will do nothing this time.
 find_program(TRACECMD_EXECUTABLE NAMES  trace-cmd)
 find_path(TRACECMD_INCLUDE_DIR   NAMES  trace-cmd/trace-cmd.h)
+find_path(TRACEFS_INCLUDE_DIR   NAMES  tracefs/tracefs.h)
 find_library(TRACECMD_LIBRARY    NAMES  trace-cmd/libtracecmd.so)
+find_library(TRACEFS_LIBRARY    NAMES  tracefs/libtracefs.so)
 find_path(TRACEEVENT_INCLUDE_DIR NAMES  traceevent/event-parse.h)
 find_library(TRACEEVENT_LIBRARY  NAMES  traceevent/libtraceevent.so)
 
@@ -67,6 +79,22 @@  ELSE (TRACECMD_FOUND)
 
 ENDIF (TRACECMD_FOUND)
 
+IF (TRACEFS_INCLUDE_DIR AND TRACEFS_LIBRARY)
+
+  SET(TRACEFS_FOUND TRUE)
+
+ENDIF (TRACEFS_INCLUDE_DIR AND TRACEFS_LIBRARY)
+
+IF (TRACEFS_FOUND)
+
+  MESSAGE(STATUS "Found tracefs: ${TRACEFS_LIBRARY}")
+
+ELSE (TRACEFS_FOUND)
+
+  MESSAGE(FATAL_ERROR "\nCould not find tracefs!\n")
+
+ENDIF (TRACEFS_FOUND)
+
 
 IF (TRACEEVENT_INCLUDE_DIR AND TRACEEVENT_LIBRARY)
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dbd33ab..8ffc66c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,6 +19,7 @@  add_library(kshark SHARED libkshark.c
 
 target_link_libraries(kshark ${TRACEEVENT_LIBRARY}
                              ${TRACECMD_LIBRARY}
+                             ${TRACEFS_LIBRARY}
                              ${JSONC_LIBRARY}
                              ${CMAKE_DL_LIBS})
 
@@ -104,6 +105,7 @@  if (Qt5Widgets_FOUND AND Qt5Network_FOUND)
                                      Qt5::Network
                                      ${TRACEEVENT_LIBRARY}
                                      ${TRACECMD_LIBRARY}
+                                     ${TRACEFS_LIBRARY}
                                      ${CMAKE_DL_LIBS})
 
     set_target_properties(kshark-gui PROPERTIES  SUFFIX ".so.${KS_VERSION_STRING}")