diff mbox series

[1/5] kernel-shark: Start using libtracecmd

Message ID 20210105155453.41228-2-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit ed0cfb5b8ce0224537b76ad949c86c0fc2e3bdb2
Headers show
Series kernel-shark: Improve the build system | expand

Commit Message

Yordan Karadzhov Jan. 5, 2021, 3:54 p.m. UTC
libtracecmd is now a stand-alone libraries, similar to libtraceevent
and libtracefs. Start building and linking KernelShark against this
independent library.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 CMakeLists.txt             |   4 +-
 build/FindTraceCmd.cmake   | 101 ++++++++++++++++++++++---------------
 build/FindTraceEvent.cmake |   1 -
 build/FindTraceFS.cmake    |   1 -
 src/CMakeLists.txt         |   2 +-
 src/libkshark-tepdata.c    |  18 +++----
 6 files changed, 72 insertions(+), 55 deletions(-)
diff mbox series

Patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 303e47e..59bbe72 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,11 +21,11 @@  if (NOT _LIBDIR)
     set(_LIBDIR "${_INSTALL_PREFIX}/lib")
 endif (NOT _LIBDIR)
 
-include(${KS_DIR}/build/FindTraceCmd.cmake)
-
 set(CMAKE_MODULE_PATH "${KS_DIR}/build")
 find_package(TraceEvent REQUIRED)
 find_package(TraceFS    REQUIRED)
+find_package(TraceCmd   REQUIRED)
+
 find_package(JSONC      REQUIRED)
 
 find_package(Doxygen)
diff --git a/build/FindTraceCmd.cmake b/build/FindTraceCmd.cmake
index 5df2789..23eefed 100644
--- a/build/FindTraceCmd.cmake
+++ b/build/FindTraceCmd.cmake
@@ -1,59 +1,78 @@ 
-# Find traceevent and trace-cmd
-# This module finds an installed trace-cmd package.
-#
-# It sets the following variables:
-#  TRACEEVENT_LIBRARY, traceevent the library.
-#  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.
+# SPDX-License-Identifier: LGPL-2.1
 
-# MESSAGE(" Looking for trace-cmd ...")
+#[=======================================================================[.rst:
+FindTraceCmd
+-------
 
-# First search in the user provided paths.
-if (CMAKE_BUILD_TYPE MATCHES Debug)
+Finds the tracecmd library.
 
-  find_program(TRACECMD_EXECUTABLE   NAMES  trace-cmd
-                                     PATHS  $ENV{TRACE_CMD}/tracecmd/
-                                     NO_DEFAULT_PATH)
+Imported Targets
+^^^^^^^^^^^^^^^^
 
-endif (CMAKE_BUILD_TYPE MATCHES Debug)
+This module defines the :prop_tgt:`IMPORTED` targets:
 
-if (NOT TRACECMD_EXECUTABLE)
+``trace::cmd``
+ Defined if the system has libtracecmd.
 
-  set(TRACECMD_EXECUTABLE "${_INSTALL_PREFIX}/bin/trace-cmd")
+Result Variables
+^^^^^^^^^^^^^^^^
 
-endif (NOT TRACECMD_EXECUTABLE)
+``TraceCmd_FOUND``
+  True if the system has the libtracecmd library.
+``TraceCmd_VERSION``
+  The version of the libtracecmd library which was found.
+``TraceCmd_INCLUDE_DIRS``
+  Include directories needed to use libtracecmd.
+``TraceCmd_LIBRARIES``
+  Libraries needed to link to libtracecmd.
 
-find_path(TRACECMD_INCLUDE_DIR  NAMES  trace-cmd/trace-cmd.h
-                                PATHS  $ENV{TRACE_CMD}/include/
-                                NO_DEFAULT_PATH)
+Cache Variables
+^^^^^^^^^^^^^^^
 
-find_library(TRACECMD_LIBRARY   NAMES  trace-cmd/libtracecmd.a
-                                PATHS  $ENV{TRACE_CMD}/lib/
-                                NO_DEFAULT_PATH)
+``TraceCmd_INCLUDE_DIR``
+  The directory containing ``trace-cmd.h``.
+``TraceCmd_LIBRARY``
+  The path to the tracecmd library.
 
-# If not found, search in the default system paths. Note that if the previous
-# 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_library(TRACECMD_LIBRARY    NAMES  trace-cmd/libtracecmd.so)
+#]=======================================================================]
 
-IF (TRACECMD_INCLUDE_DIR AND TRACECMD_LIBRARY)
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_TraceCmd QUIET libtracecmd)
 
-  SET(TRACECMD_FOUND TRUE)
+set(TraceCmd_VERSION     ${PC_TraceCmd_VERSION})
+set(TraceCmd_DEFINITIONS ${PC_TraceCmd_CFLAGS_OTHER})
 
-ENDIF (TRACECMD_INCLUDE_DIR AND TRACECMD_LIBRARY)
+find_path(TraceCmd_INCLUDE_DIR NAMES trace-cmd/trace-cmd.h
+                               HINTS ${PC_TraceCmd_INCLUDE_DIRS}
+                                     ${PC_TraceCmd_INCLUDEDIR})
 
-IF (TRACECMD_FOUND)
+find_library(TraceCmd_LIBRARY  NAMES tracecmd libtracecmd
+                               HINTS ${PC_TraceCmd_LIBDIR}
+                                     ${PC_TraceCmdLIBRARY_DIRS})
 
-  MESSAGE(STATUS "Found trace-cmd: ${TRACECMD_LIBRARY}")
+mark_as_advanced(TraceCmd_INCLUDE_DIR TraceCmd_LIBRARY)
 
-ELSE (TRACECMD_FOUND)
+include(FindPackageHandleStandardArgs)
 
-  MESSAGE(FATAL_ERROR "\nCould not find trace-cmd!\n")
+find_package_handle_standard_args(TraceCmd DEFAULT_MSG
+                                  TraceCmd_LIBRARY TraceCmd_INCLUDE_DIR)
 
-ENDIF (TRACECMD_FOUND)
+if(TraceCmd_FOUND)
+
+  set(TraceCmd_LIBRARIES    ${TraceCmd_LIBRARY})
+  set(TraceCmd_INCLUDE_DIRS ${TraceCmd_INCLUDE_DIR})
+
+  if(NOT TARGET trace::cmd)
+    add_library(trace::cmd UNKNOWN IMPORTED)
+
+    set_target_properties(trace::cmd
+                          PROPERTIES
+                            INTERFACE_INCLUDE_DIRECTORIES "${TraceCmd_INCLUDE_DIRS}"
+                            INTERFACE_COMPILE_DEFINITIONS "${TraceCmd_DEFINITIONS}"
+                            IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+                            IMPORTED_LOCATION "${TraceCmd_LIBRARIES}")
+  endif()
+
+endif()
+
+find_program(TRACECMD_EXECUTABLE NAMES trace-cmd)
diff --git a/build/FindTraceEvent.cmake b/build/FindTraceEvent.cmake
index 8525697..f3feca9 100644
--- a/build/FindTraceEvent.cmake
+++ b/build/FindTraceEvent.cmake
@@ -1,4 +1,3 @@ 
-
 #[=======================================================================[.rst:
 FindTraceevent
 -------
diff --git a/build/FindTraceFS.cmake b/build/FindTraceFS.cmake
index 982a61d..2a5f7bd 100644
--- a/build/FindTraceFS.cmake
+++ b/build/FindTraceFS.cmake
@@ -1,4 +1,3 @@ 
-
 #[=======================================================================[.rst:
 FindTraceFS
 -------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 285f88a..b393468 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -9,7 +9,7 @@  add_library(kshark SHARED libkshark.c
                           libkshark-configio.c
                           libkshark-collection.c)
 
-target_link_libraries(kshark ${TRACECMD_LIBRARY}
+target_link_libraries(kshark trace::cmd
                              trace::fs
                              trace::event
                              jsonc::jsonc
diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c
index a82f5c5..724cff2 100644
--- a/src/libkshark-tepdata.c
+++ b/src/libkshark-tepdata.c
@@ -277,7 +277,7 @@  static void free_rec_list(struct rec_list **rec_list, int n_cpus,
 			temp_rec = rec_list[cpu];
 			rec_list[cpu] = temp_rec->next;
 			if (type == REC_RECORD)
-				free_record(temp_rec->rec);
+				tracecmd_free_record(temp_rec->rec);
 			free(temp_rec);
 		}
 	}
@@ -379,7 +379,7 @@  static ssize_t get_records(struct kshark_context *kshark_ctx,
 				    tep_filter_match(adv_filter, rec) != FILTER_MATCH)
 					unset_event_filter_flag(kshark_ctx, entry);
 
-				free_record(rec);
+				tracecmd_free_record(rec);
 				break;
 			} /* REC_ENTRY */
 			}
@@ -571,7 +571,7 @@  static ssize_t tepdata_load_matrix(struct kshark_data_stream *stream,
  *
  * @param kshark_ctx: Input location for the session context pointer.
  * @param sd: Data stream identifier.
- * @param data_rows: Output location for the trace data. Use free_record()
+ * @param data_rows: Output location for the trace data. Use tracecmd_free_record()
  *	 	     to free the elements of the outputted array.
  *
  * @returns The size of the outputted data in the case of success, or a
@@ -657,7 +657,7 @@  static const int tepdata_get_event_id(struct kshark_data_stream *stream,
 		if (record)
 			event_id = tep_data_type(kshark_get_tep(stream), record);
 
-		free_record(record);
+		tracecmd_free_record(record);
 
 		pthread_mutex_unlock(&stream->input_mutex);
 	}
@@ -749,7 +749,7 @@  static const int tepdata_get_pid(struct kshark_data_stream *stream,
 		if (record)
 			pid = tep_data_pid(kshark_get_tep(stream), record);
 
-		free_record(record);
+		tracecmd_free_record(record);
 
 		pthread_mutex_unlock(&stream->input_mutex);
 	}
@@ -798,7 +798,7 @@  static char *tepdata_get_latency(struct kshark_data_stream *stream,
 	tep_print_event(kshark_get_tep(stream), &seq, record,
 			"%s", TEP_PRINT_LATENCY);
 
-	free_record(record);
+	tracecmd_free_record(record);
 
 	pthread_mutex_unlock(&stream->input_mutex);
 
@@ -869,7 +869,7 @@  static char *tepdata_get_info(struct kshark_data_stream *stream,
 	if (event)
 		info = get_info_str(stream, record, event);
 
-	free_record(record);
+	tracecmd_free_record(record);
 
 	pthread_mutex_unlock(&stream->input_mutex);
 
@@ -1178,7 +1178,7 @@  int tepdata_read_event_field(struct kshark_data_stream *stream,
 
 	ret = tep_read_number_field(evt_field, record->data,
 				    (unsigned long long *) val);
-	free_record(record);
+	tracecmd_free_record(record);
 
 	return ret;
 }
@@ -1308,7 +1308,7 @@  static int kshark_tep_stream_init(struct kshark_data_stream *stream,
 		goto fail;
 
 	tep_handle->input = input;
-	tep_handle->tep = tracecmd_get_pevent(tep_handle->input);
+	tep_handle->tep = tracecmd_get_tep(tep_handle->input);
 	if (!tep_handle->tep)
 		goto fail;