All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 1/5] kernel-shark: Start using libtracecmd
Date: Tue,  5 Jan 2021 17:54:49 +0200	[thread overview]
Message-ID: <20210105155453.41228-2-y.karadz@gmail.com> (raw)
In-Reply-To: <20210105155453.41228-1-y.karadz@gmail.com>

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 --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;
 
-- 
2.25.1


  reply	other threads:[~2021-01-05 15:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-05 15:54 [PATCH 0/5] kernel-shark: Improve the build system Yordan Karadzhov (VMware)
2021-01-05 15:54 ` Yordan Karadzhov (VMware) [this message]
2021-01-05 15:54 ` [PATCH 2/5] kernel-shark: Add missing SPDX license identifiers Yordan Karadzhov (VMware)
2021-01-05 15:54 ` [PATCH 3/5] kernel-shark: Change default libraries install location Yordan Karadzhov (VMware)
2021-01-05 15:54 ` [PATCH 4/5] kernel-shark: Split the installation in two components Yordan Karadzhov (VMware)
2021-01-05 21:29   ` Steven Rostedt
2021-01-06 11:20     ` Yordan Karadzhov (VMware)
2021-01-05 15:54 ` [PATCH 5/5] kernel-shark: Fix "github Actions" workflow Yordan Karadzhov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210105155453.41228-2-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.