Skip to contentSkip to conversation

trace-cmd/kernelshark: Fixed build, cleanups and fix kernelshark

PATCH New Steven Rostedt 1 participant 7 messages Dec 16, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

v2 cover trace-cmd/kernelshark: Fixed build, cleanups and fix kernelshark

Sent out a v1, but the change log of patch 2 had issues that quilt could not deal with, and was rejected. The v1 had just the first three patches. This series has more to handle KernelShark v1 building.

Steven Rostedt (VMware) (5):
trace-cmd: Move add_event_pid() out of #ifndef NO_PTRACE
trace-cmd: Add #include <fcntl.h> to trace-cmd-private.h
trace-cmd: Add a make-trace-cmd.sh script to simplify creating a trace-cmd package
trace-cmd: Do not have local builds of libtraceevent or libtracefs use system headers
kernelshark: Build libtraceevent and libtracefs locally

Yordan Karadzhov (VMware) (1):
trace-cmd: Re-enable the build of KernelShark v1

----

 Makefile                                          | 24 ++++++++++++------
 PACKAGING                                         | 30 ++++++++++++++++++++++
 kernel-shark/CMakeLists.txt                       |  1 +
 kernel-shark/build/FindTraceCmd.cmake             | 29 +++++----------------
 kernel-shark/src/libkshark.c                      | 14 ++++++----
 kernel-shark/src/libkshark.h                      |  2 +-
 lib/trace-cmd/include/private/trace-cmd-private.h |  1 +
 lib/traceevent/Makefile                           |  6 +++++
 lib/tracefs/Makefile                              |  8 ++++++
 make-trace-cmd.sh                                 | 31 +++++++++++++++++++++++
 tracecmd/trace-record.c                           | 12 ++++-----
 11 files changed, 115 insertions(+), 43 deletions(-)
 create mode 100644 PACKAGING
 create mode 100755 make-trace-cmd.sh
#1 lore raw

PATCH v2 1/6 trace-cmd: Move add_event_pid() out of #ifndef NO_PTRACE

From: "Steven Rostedt (VMware)" <[email protected]>

When NO_PTRACE is defined, add_event_pid() is also not defined, but it is used outside of NO_PTRACE pre processor block. And this causes a "add_event_pid" not defined build failure.

Fixes 0844cff1c ("trace-cmd: Fix "trace-cmd reset" command to restore the default value of set_event_pid")
---
 tracecmd/trace-record.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tracecmd/trace-record.c +6 -6
index f8baed7dcd47..e2d1cedf05fb 100644
@@ -1312,8 +1312,13 @@ out:
 	free(pidfds);
 	return ret;
 }
-#ifndef NO_PTRACE
 
+static void add_event_pid(struct buffer_instance *instance, const char *buf)
+{
+	tracefs_instance_file_write(instance->tracefs, "set_event_pid", buf);
+}
+
+#ifndef NO_PTRACE
 /**
  * append_pid_filter - add a new pid to an existing filter
  * @curr_filter: the filter to append to. If NULL, then allocate one
@@ -1369,11 +1374,6 @@ static void update_sched_events(struct buffer_instance *instance, int pid)
 static int open_instance_fd(struct buffer_instance *instance,
 			    const char *file, int flags);
 
-static void add_event_pid(struct buffer_instance *instance, const char *buf)
-{
-	tracefs_instance_file_write(instance->tracefs, "set_event_pid", buf);
-}
-
 static void add_new_filter_child_pid(int pid, int child)
 {
 	struct buffer_instance *instance;
Signature · 1 line
2.29.2
#2 lore raw

PATCH v2 2/6 trace-cmd: Add #include <fcntl.h> to trace-cmd-private.h

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Getting the following warning in the build:

lib/trace-cmd/include/private/trace-cmd-private.h:276:41: warning: struct iovec declared inside parameter list will not be visible outside of this definition or declaration
276 | unsigned short id, const struct iovec *vector, int count);
| ^~~~~

The file trace-cmd-private.h needs to include fcntl.h to get the iovec structure definition.

---
 lib/trace-cmd/include/private/trace-cmd-private.h | 1 +
 1 file changed, 1 insertion(+)
lib/trace-cmd/include/private/trace-cmd-private.h +1 -0
index a0dac5da14d6..6494581527a3 100644
@@ -6,6 +6,7 @@
 #ifndef _TRACE_CMD_PRIVATE_H
 #define _TRACE_CMD_PRIVATE_H
 
+#include <fcntl.h> /* for iovec */
 #include <sys/types.h>
 #include "traceevent/event-parse.h"
 #include "trace-cmd/trace-cmd.h"
Signature · 1 line
2.29.2
#3 lore raw

PATCH v2 3/6 trace-cmd: Add a make-trace-cmd.sh script to simplify creating a trace-cmd package

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Add a script "make-trace-cmd.sh" and a help file "PACKAGKING" to describe what it does. The make-trace-cmd.sh will help create a full directory that has libtraceevent, libtracefs, libtracecmd and trace-cmd binary without needing to install them on the host machine.

As described in PACKAGING, the steps to do so are:

git clone git://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git
git clone git://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git
git clone git://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git

cd libtraceevent
INSTALL_PATH=/tmp/install ../trace-cmd/make-trace-cmd.sh install

cd ../libtracefs
INSTALL_PATH=/tmp/install ../trace-cmd/make-trace-cmd.sh install

cd ../trace-cmd
INSTALL_PATH=/tmp/install ./make-trace-cmd.sh install install_libs

cd /tmp/install
tar cvjf /tmp/trace-cmd-files.tar.bz2 .

And then the tarball of /tmp/trace-cmd-files.tar.bz2 will can be extracted on another machine at the root directory, and trace-cmd will be installed there.

Note, the above process uses the /usr prefix. To have the package be installed in /usr/local, add:

PREFIX=/usr/local

in front of each of the make-trace-cmd.sh commands.

---
 PACKAGING         | 30 ++++++++++++++++++++++++++++++
 make-trace-cmd.sh | 31 +++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 PACKAGING
 create mode 100755 make-trace-cmd.sh
PACKAGING new file +30 -0
new file mode 100644
index 000000000000..7e7d20653017
@@ -0,0 +1,30 @@
+The libtracefs and libtraceevent packages are required for trace-cmd
+and libtracecmd.so
+
+In order to create a package directory with libtraceevent, libtracefs
+and libtracecmd and trace-cmd, you can follow these steps:
+
+ git clone git://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git
+ git clone git://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git
+ git clone git://git.kernel.org/pub/scm/utils/trace-cmd/trace-cmd.git
+
+ cd libtraceevent
+ INSTALL_PATH=/tmp/install ../trace-cmd/make-trace-cmd.sh install
+
+ cd ../libtracefs
+ INSTALL_PATH=/tmp/install ../trace-cmd/make-trace-cmd.sh install
+
+ cd ../trace-cmd
+ INSTALL_PATH=/tmp/install ./make-trace-cmd.sh install install_libs
+
+ cd /tmp/install
+ tar cvjf /tmp/trace-cmd-files.tar.bz2 .
+
+And then the tarball of /tmp/trace-cmd-files.tar.bz2 will can be extracted
+on another machine at the root directory, and trace-cmd will be installed there.
+
+Note, to define a prefix, add a PREFIX variable before calling make-trace-cmd.sh
+
+ For example:
+
+  PREFIX=/usr/local INSTALL_PATH=/tmp/install ./make-trace-cmd.sh install
make-trace-cmd.sh new file +31 -0
new file mode 100755
index 000000000000..ddff18146c84
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+if [ -z "$INSTALL_PATH" ]; then
+	echo
+	echo 'Error: No $INSTALL_PATH defined'
+	echo
+	echo "   usage: [PREFIX=prefix][BUILD_PATH=/path/to/build] INSTALL_PATH=/path/to/install make-trace-cmd.sh install|install_libs|clean|uninstall"
+	echo
+	echo "     Used to create a self contained directory to copy to other machines."
+	echo
+	echo "   Please read PACKAGING for more information."
+	echo
+	exit
+fi
+
+if [ ! -d $INSTALL_PATH ]; then
+	mkdir $INSTALL_PATH
+fi
+
+if [ ! -z "$BUILD_PATH" ]; then
+	if [ ! -d $BUILD_PATH ]; then
+		mkdir $BUILD_PATH
+	fi
+	O_PATH="O=$BUILD_PATH"
+fi
+
+if [ -z "$PREFIX" ]; then
+	PREFIX="/usr"
+fi
+
+PKG_CONFIG="pkg-config --with-path $INSTALL_PATH/usr/lib64/pkgconfig --define-variable=prefix=$INSTALL_PATH/$PREFIX" CFLAGS="-g -Wall -I$INSTALL_PATH/$PREFIX/include" make DESTDIR=$INSTALL_PATH  $O_PATH prefix=$PREFIX $@
Signature · 1 line
2.29.2
#4 lore raw

PATCH v2 4/6 trace-cmd: Do not have local builds of libtraceevent or libtracefs use system headers

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

If building locally, do not use system includes. This is needed for kernelshark v1 to build libtraceevent and libtracefs. If the system header files are used, there may be a mismatch with the frozen version of libtraceevent or libtracefs that kernelshark will use, and the system headers, and the build will fail.

---
 lib/traceevent/Makefile | 4 ++++
 lib/tracefs/Makefile    | 5 +++++
 2 files changed, 9 insertions(+)
lib/traceevent/Makefile +4 -0
index 0dcd90c13328..21ef5a4ea59f 100644
@@ -6,8 +6,12 @@ bdir:=$(obj)/lib/traceevent
 
 DEFAULT_TARGET = $(bdir)/libtraceevent.a
 
+LIBTRACEEVENT_CFLAGS = -I$(src)/include/traceevent -I$(src)/lib/traceevent/include
+
 CFLAGS += -I$(bdir)/include
 
+CFLAGS := $(LIBTRACEEVENT_CFLAGS) $(CFLAGS)
+
 OBJS =
 OBJS += event-parse.o
 OBJS += event-plugin.o
lib/tracefs/Makefile +5 -0
index 021ae2b040de..6f4370d96f10 100644
@@ -6,8 +6,13 @@ bdir:=$(obj)/lib/tracefs
 
 DEFAULT_TARGET = $(bdir)/libtracefs.a
 
+LIBTRACEEVENT_CFLAGS = -I$(src)/include/traceevent -I$(src)/lib/traceevent/include
+LIBTRACEFS_CFLAGS = -I$(src)/include/tracefs -I$(src)/lib/tracefs/include
+
 CFLAGS += -I$(bdir)/include
 
+CFLAGS := $(LIBTRACEEVENT_CFLAGS) $(LIBTRACEFS_CFLAGS) $(CFLAGS)
+
 OBJS =
 OBJS += tracefs-utils.o
 OBJS += tracefs-instance.o
Signature · 1 line
2.29.2
#5 lore raw

PATCH v2 5/6 kernelshark: Build libtraceevent and libtracefs locally

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

kernelshark v1 is now frozen in favor of developing kernelshark v2. Do not use the system libraries libtraceevent or libtracefs for kernelshark v1, as they may not be suitable. Use the frozen libtraceevent and libtracefs that is in the local repository.

---
 Makefile                | 24 ++++++++++++++++--------
 lib/traceevent/Makefile |  2 ++
 lib/tracefs/Makefile    |  3 +++
 3 files changed, 21 insertions(+), 8 deletions(-)
Makefile +16 -8
index 662d24ba288f..7aef50b34a56 100644
@@ -354,19 +354,14 @@ $(PKG_CONFIG_FILE) : ${PKG_CONFIG_SOURCE_FILE}.template $(BUILD_PREFIX)
 $(kshark-dir)/build/Makefile: $(kshark-dir)/CMakeLists.txt
 	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -D_INSTALL_PREFIX=$(prefix) -D_LIBDIR=$(libdir) ..
 
-gui: force
-	$(MAKE) $(CMD_TARGETS)
-	$(MAKE) $(kshark-dir)/build/Makefile
-	$(Q)$(MAKE) $(S) -C $(kshark-dir)/build
-	@echo "gui build complete"
-	@echo "  kernelshark located at $(kshark-dir)/bin"
-
 trace-cmd: force $(LIBTRACEEVENT_STATIC_BUILD) $(LIBTRACECMD_STATIC) $(LIBTRACEFS_STATIC_BUILD) \
 	force $(obj)/lib/trace-cmd/plugins/tracecmd_plugin_dir
 	$(Q)$(MAKE) -C $(src)/tracecmd $(obj)/tracecmd/$@
 
-$(LIBTRACEEVENT_STATIC): force $(obj)/lib/traceevent/plugins/trace_python_dir \
+LIBTRACEEVENT_DEPENDS = $(obj)/lib/traceevent/plugins/trace_python_dir \
 			 $(obj)/lib/traceevent/plugins/traceevent_plugin_dir
+
+$(LIBTRACEEVENT_STATIC): force $(LIBTRACEEVENT_DEPENDS)
 	$(Q)$(MAKE) -C $(src)/lib/traceevent libtraceevent
 
 $(LIBTRACECMD_STATIC): force
@@ -385,6 +380,19 @@ libtracefs.a: $(LIBTRACEFS_STATIC)
 
 libs: $(LIBTRACECMD_SHARED) $(LIBTRACEEVENT_STATIC_BUILD) $(LIBTRACEFS_STATIC_BUILD) $(PKG_CONFIG_FILE)
 
+libtraceevent_nowarn: $(LIBTRACEEVENT_DEPENDS)
+	$(Q)$(MAKE) -C $(src)/lib/traceevent $@
+
+libtracefs_nowarn: force
+	$(Q)$(MAKE) -C $(src)/lib/tracefs $@
+
+
+gui: force $(CMD_TARGETS) libtraceevent_nowarn libtracefs_nowarn
+	$(MAKE) $(kshark-dir)/build/Makefile
+	$(Q)$(MAKE) $(S) -C $(kshark-dir)/build
+	@echo "gui build complete"
+	@echo "  kernelshark located at $(kshark-dir)/bin"
+
 test: force $(LIBTRACEEVENT_STATIC_BUILD) $(LIBTRACEFS_STATIC_BUILD) $(LIBTRACECMD_STATIC)
 ifneq ($(CUNIT_INSTALLED),1)
 	$(error CUnit framework not installed, cannot build unit tests))
lib/traceevent/Makefile +2 -0
index 21ef5a4ea59f..21eaffd21f7a 100644
@@ -50,6 +50,8 @@ $(bdir)/libtraceevent.a: $(OBJS)
 
 libtraceevent: $(bdir)/libtraceevent.a warning
 
+libtraceevent_nowarn: $(bdir)/libtraceevent.a
+
 $(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
 
lib/tracefs/Makefile +3 -0
index 6f4370d96f10..74cb8829979f 100644
@@ -47,6 +47,9 @@ $(bdir)/libtracefs.a: $(OBJS)
 	$(Q)$(call do_build_static_lib)
 
 libtracefs: $(bdir)/libtracefs.a warning
+
+libtracefs_nowarn: $(bdir)/libtracefs.a
+
 $(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
 
Signature · 1 line
2.29.2
#6 lore raw

PATCH v2 6/6 trace-cmd: Re-enable the build of KernelShark v1

In reply to Steven Rostedt

From: "Yordan Karadzhov (VMware)" <[email protected]>

libtraceevent and libtracefs are now stand-alone libraries, independent from trace-cmd, but nevertheless trace-cmd still provides legacy/obsolete versions of this libraries. Since we are "freezing" KernelShark v1 and all active development is now focused on KernelShark v2, we will keep v1 use the legacy/obsolete versions of the libraries.

An additional problem is that trace-filter-hash.h is no longer a public header of libtracecmd. For this reason we are adding the path to the tarce-cmd private headers to the list of header file locations.

We also remove the inclusion of event-utils.h in parse-utils.c in order to fix a compilation error when building libtraceevent.a.

[ Removed Makefile libtraceevent updates as other commits handle them ]
---
 kernel-shark/CMakeLists.txt           |  1 +
 kernel-shark/build/FindTraceCmd.cmake | 29 ++++++---------------------
 kernel-shark/src/libkshark.c          | 14 ++++++++-----
 kernel-shark/src/libkshark.h          |  2 +-
 4 files changed, 17 insertions(+), 29 deletions(-)
kernel-shark/CMakeLists.txt +1 -0
index c95249e9a235..0c0b8255d7a1 100644
@@ -81,6 +81,7 @@ include_directories(${KS_DIR}/src/
                     ${KS_DIR}/build/src/
                     ${JSONC_INCLUDE_DIR}
                     ${TRACECMD_INCLUDE_DIR}
+                    ${TRACECMD_PRIVATE_INCLUDE_DIR}
                     ${TRACEFS_INCLUDE_DIR})
 
 message("")
kernel-shark/build/FindTraceCmd.cmake +6 -23
index c29b77911361..a40f70e54093 100644
@@ -14,25 +14,15 @@
 # MESSAGE(" Looking for trace-cmd ...")
 
 # First search in the user provided paths.
-if (CMAKE_BUILD_TYPE MATCHES Debug)
-
-  find_program(TRACECMD_EXECUTABLE   NAMES  trace-cmd
-                                     PATHS  $ENV{TRACE_CMD}/tracecmd/
-                                            ${CMAKE_SOURCE_DIR}/../tracecmd/
-                                     NO_DEFAULT_PATH)
-
-endif (CMAKE_BUILD_TYPE MATCHES Debug)
-
-if (NOT TRACECMD_EXECUTABLE)
-
-  set(TRACECMD_EXECUTABLE "${_INSTALL_PREFIX}/bin/trace-cmd")
-
-endif (NOT TRACECMD_EXECUTABLE)
 
 find_path(TRACECMD_INCLUDE_DIR  NAMES  trace-cmd/trace-cmd.h
                                 PATHS  $ENV{TRACE_CMD}/include/
                                        ${CMAKE_SOURCE_DIR}/../include/
                                 NO_DEFAULT_PATH)
+find_path(TRACECMD_PRIVATE_INCLUDE_DIR  NAMES private/trace-filter-hash.h
+                                PATHS  $ENV{TRACE_CMD}/lib/trace-cmd/include/
+                                       ${CMAKE_SOURCE_DIR}/../lib/trace-cmd/include/
+                                NO_DEFAULT_PATH)
 find_path(TRACEFS_INCLUDE_DIR   NAMES  tracefs/tracefs.h
                                 PATHS  $ENV{TRACE_CMD}/include/
                                        ${CMAKE_SOURCE_DIR}/../include/
@@ -53,20 +43,13 @@ find_library(TRACEEVENT_LIBRARY NAMES  traceevent/libtraceevent.a
                                        ${CMAKE_SOURCE_DIR}/../lib/
                                 NO_DEFAULT_PATH)
 
-# 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_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_library(TRACEEVENT_LIBRARY NAMES  traceevent/libtraceevent.so)
 
-IF (TRACECMD_INCLUDE_DIR AND TRACECMD_LIBRARY)
+IF (TRACECMD_INCLUDE_DIR AND TRACECMD_PRIVATE_INCLUDE_DIR AND TRACECMD_LIBRARY)
 
   SET(TRACECMD_FOUND TRUE)
 
-ENDIF (TRACECMD_INCLUDE_DIR AND TRACECMD_LIBRARY)
+ENDIF (TRACECMD_INCLUDE_DIR AND TRACECMD_PRIVATE_INCLUDE_DIR AND TRACECMD_LIBRARY)
 
 IF (TRACECMD_FOUND)
 
kernel-shark/src/libkshark.c +9 -5
index 52aacd3044eb..4e625a25e902 100644
@@ -141,10 +141,14 @@ bool kshark_open(struct kshark_context *kshark_ctx, const char *file)
 
 	kshark_free_task_list(kshark_ctx);
 
-	handle = tracecmd_open(file);
+	handle = tracecmd_open_head(file);
 	if (!handle)
 		return false;
 
+	/* Read the tracing data from the file. */
+	if (tracecmd_init_data(handle) < 0)
+		return false;
+
 	if (pthread_mutex_init(&kshark_ctx->input_mutex, NULL) != 0) {
 		tracecmd_close(handle);
 		return false;
@@ -696,7 +700,7 @@ static ssize_t get_records(struct kshark_context *kshark_ctx,
 	int pid;
 	int cpu;
 
-	n_cpus = tracecmd_cpus(kshark_ctx->handle);
+	n_cpus = tep_get_cpus(kshark_ctx->pevent);;
 	cpu_list = calloc(n_cpus, sizeof(*cpu_list));
 	if (!cpu_list)
 		return -ENOMEM;
@@ -867,7 +871,7 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx,
 	if (total < 0)
 		goto fail;
 
-	n_cpus = tracecmd_cpus(kshark_ctx->handle);
+	n_cpus = tep_get_cpus(kshark_ctx->pevent);;
 
 	rows = calloc(total, sizeof(struct kshark_entry *));
 	if (!rows)
@@ -923,7 +927,7 @@ ssize_t kshark_load_data_records(struct kshark_context *kshark_ctx,
 	if (total < 0)
 		goto fail;
 
-	n_cpus = tracecmd_cpus(kshark_ctx->handle);
+	n_cpus = tep_get_cpus(kshark_ctx->pevent);;
 
 	rows = calloc(total, sizeof(struct tep_record *));
 	if (!rows)
@@ -1047,7 +1051,7 @@ size_t kshark_load_data_matrix(struct kshark_context *kshark_ctx,
 	if (total < 0)
 		goto fail;
 
-	n_cpus = tracecmd_cpus(kshark_ctx->handle);
+	n_cpus = tep_get_cpus(kshark_ctx->pevent);;
 
 	status = data_matrix_alloc(total, offset_array,
 					  cpu_array,
kernel-shark/src/libkshark.h +1 -1
index 0d6c50d10c1b..a9cba054a32f 100644
@@ -26,7 +26,7 @@ extern "C" {
 
 // trace-cmd
 #include "trace-cmd/trace-cmd.h"
-#include "trace-cmd/trace-filter-hash.h"
+#include "private/trace-filter-hash.h"
 #include "traceevent/event-parse.h"
 #include "tracefs/tracefs.h"
 
Signature · 1 line
2.29.2