Skip to contentSkip to conversation

Remove redundant trace-cmd plugin handling logic

PATCH Superseded Tzvetomir Stoyanov (VMware) 2 participants 8 messages Aug 2, 2019 – Aug 30, 2019 Kbuild

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Remove redundant trace-cmd plugin handling logic

Currently there are no trace-cmd related plugins, all of them are designed to be used with libtraceeevnt. As both libtraceevent and trace-cmd have logic for managing plugins, the one in trace-cmd is redundant. Those redundant code is removed and replaced with calls to libtraceeevnt plugin APIs. When trace-cmd has to load any plugins, it uses libtraceeevnt to do the job.

All existing plugins are moved from plugins/ to plugins/traceevent/ directory, as all of them (except plugin_python) are designed to be used with the traceevent library. This change paves the way for implementing trace-cmd specific plugins.

Tzvetomir Stoyanov (VMware) (1):
trace-cmd: Remove trace-cmd plugin handling routines

Tzvetomir Stoyanov (1):
trace-cmd: Change plugin install directories

Tzvetomir Stoyanov (VMware) (4):
trace-cmd: Move kernel_stack event handler to "function" plugin.
trace-cmd: Move plugin options from trace-cmd to libtraceevent.
trace-cmd: Move libtraceevent plugins in its own directory.
trace-cmd: Load libtraceevent plugins from build folder, if exists.

 .gitignore                                    |   2 +-
 Makefile                                      |  44 +-
 include/trace-cmd/trace-cmd.h                 |  24 -
 include/traceevent/event-parse.h              |   8 +
 kernel-shark/src/libkshark.c                  |   4 +-
 lib/trace-cmd/Makefile                        |   2 -
 lib/trace-cmd/trace-ftrace.c                  |  56 +-
 lib/trace-cmd/trace-input.c                   |   9 +-
 lib/trace-cmd/trace-util.c                    | 752 +-----------------
 lib/traceevent/event-plugin.c                 | 226 +++++-
 plugins/{ => traceevent}/Makefile             |  12 +-
 plugins/{ => traceevent}/plugin_blk.c         |   0
 plugins/{ => traceevent}/plugin_cfg80211.c    |   0
 plugins/{ => traceevent}/plugin_function.c    |  45 +-
 plugins/{ => traceevent}/plugin_futex.c       |   0
 plugins/{ => traceevent}/plugin_hrtimer.c     |   0
 plugins/{ => traceevent}/plugin_jbd2.c        |   0
 plugins/{ => traceevent}/plugin_kmem.c        |   0
 plugins/{ => traceevent}/plugin_kvm.c         |   0
 plugins/{ => traceevent}/plugin_mac80211.c    |   0
 plugins/{ => traceevent}/plugin_python.c      |   9 +-
 .../{ => traceevent}/plugin_sched_switch.c    |   0
 plugins/{ => traceevent}/plugin_scsi.c        |   0
 plugins/{ => traceevent}/plugin_tlb.c         |   0
 plugins/{ => traceevent}/plugin_xen.c         |   0
 tracecmd/trace-check-events.c                 |  10 +-
 tracecmd/trace-list.c                         |  23 +-
 tracecmd/trace-read.c                         |   2 +-
 28 files changed, 338 insertions(+), 890 deletions(-)
 rename plugins/{ => traceevent}/Makefile (86%)
 rename plugins/{ => traceevent}/plugin_blk.c (100%)
 rename plugins/{ => traceevent}/plugin_cfg80211.c (100%)
 rename plugins/{ => traceevent}/plugin_function.c (79%)
 rename plugins/{ => traceevent}/plugin_futex.c (100%)
 rename plugins/{ => traceevent}/plugin_hrtimer.c (100%)
 rename plugins/{ => traceevent}/plugin_jbd2.c (100%)
 rename plugins/{ => traceevent}/plugin_kmem.c (100%)
 rename plugins/{ => traceevent}/plugin_kvm.c (100%)
 rename plugins/{ => traceevent}/plugin_mac80211.c (100%)
 rename plugins/{ => traceevent}/plugin_python.c (91%)
 rename plugins/{ => traceevent}/plugin_sched_switch.c (100%)
 rename plugins/{ => traceevent}/plugin_scsi.c (100%)
 rename plugins/{ => traceevent}/plugin_tlb.c (100%)
 rename plugins/{ => traceevent}/plugin_xen.c (100%)
Signature · 1 line
2.21.0
#1 lore raw

PATCH v2 1/6 trace-cmd: Move kernel_stack event handler to "function" plugin.

The "kernel_stack" event handler does not depend on any trace-cmd context, it can be used aside from the application. The code is moved to libtraceevent "function" plugin.

---
 lib/trace-cmd/trace-ftrace.c | 52 ------------------------------------
 plugins/plugin_function.c    | 41 ++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 52 deletions(-)
lib/trace-cmd/trace-ftrace.c +0 -52
index ed68099..22e5213 100644
@@ -31,17 +31,6 @@ struct tep_plugin_option trace_ftrace_options[] = {
 static struct tep_plugin_option *fgraph_tail = &trace_ftrace_options[0];
 static struct tep_plugin_option *fgraph_depth = &trace_ftrace_options[1];
 
-static void find_long_size(struct tracecmd_ftrace *finfo)
-{
-	finfo->long_size = tracecmd_long_size(finfo->handle);
-}
-
-#define long_size_check(handle)				\
-	do {						\
-		if (!finfo->long_size)				\
-			find_long_size(finfo);		\
-	} while (0)
-
 static int find_ret_event(struct tracecmd_ftrace *finfo, struct tep_handle *pevent)
 {
 	struct tep_event *event;
@@ -361,44 +350,6 @@ fgraph_ret_handler(struct trace_seq *s, struct tep_record *record,
 	return 0;
 }
 
-static int
-trace_stack_handler(struct trace_seq *s, struct tep_record *record,
-		    struct tep_event *event, void *context)
-{
-	struct tracecmd_ftrace *finfo = context;
-	struct tep_format_field *field;
-	unsigned long long addr;
-	const char *func;
-	void *data = record->data;
-
-	field = tep_find_any_field(event, "caller");
-	if (!field) {
-		trace_seq_printf(s, "<CANT FIND FIELD %s>", "caller");
-		return 0;
-	}
-
-	trace_seq_puts(s, "<stack trace>\n");
-
-	long_size_check(finfo);
-
-	for (data += field->offset; data < record->data + record->size;
-	     data += finfo->long_size) {
-		addr = tep_read_number(event->tep, data, finfo->long_size);
-
-		if ((finfo->long_size == 8 && addr == (unsigned long long)-1) ||
-		    ((int)addr == -1))
-			break;
-
-		func = tep_find_function(event->tep, addr);
-		if (func)
-			trace_seq_printf(s, "=> %s (%llx)\n", func, addr);
-		else
-			trace_seq_printf(s, "=> %llx\n", addr);
-	}
-
-	return 0;
-}
-
 /**
  * tracecmd_ftrace_load_options - load the ftrace options
  *
@@ -430,9 +381,6 @@ int tracecmd_ftrace_overrides(struct tracecmd_input *handle,
 	tep_register_event_handler(pevent, -1, "ftrace", "funcgraph_exit",
 				      fgraph_ret_handler, finfo);
 
-	tep_register_event_handler(pevent, -1, "ftrace", "kernel_stack",
-				      trace_stack_handler, finfo);
-
 	trace_util_add_options("ftrace", trace_ftrace_options);
 
 	/* Store the func ret id and event for later use */
plugins/plugin_function.c +41 -0

52 lines not on this page · raw message

Signature · 1 line
2.21.0
#2 lore raw

PATCH v2 2/6 trace-cmd: Move plugin options from trace-cmd to libtraceevent.

In reply to Tzvetomir Stoyanov (VMware)

There are two different implementations of plugin options, which work in parallel - one in trace-cmd and the other one in libtraceevent. Both have the same functionality and most of the implementation is the same, duplicated. As currently there are only libtraceevent plugins,the implementation plugin options should be in libtraceevent only.

---
 include/trace-cmd/trace-cmd.h    |   6 -
 include/traceevent/event-parse.h |   2 +
 kernel-shark/src/libkshark.c     |   4 +-
 lib/trace-cmd/trace-ftrace.c     |   4 +-
 lib/trace-cmd/trace-util.c       | 422 -------------------------------
 lib/traceevent/event-plugin.c    | 173 +++++++++++++
 plugins/plugin_function.c        |   4 +-
 tracecmd/trace-list.c            |   2 +-
 tracecmd/trace-read.c            |   2 +-
 9 files changed, 183 insertions(+), 436 deletions(-)
include/trace-cmd/trace-cmd.h +0 -6
index 6f62ab9..c06067e 100644
@@ -337,9 +337,6 @@ void tracecmd_msg_set_done(struct tracecmd_msg_handle *msg_handle);
 /* --- Plugin handling --- */
 extern struct tep_plugin_option trace_ftrace_options[];
 
-int trace_util_add_options(const char *name, struct tep_plugin_option *options);
-void trace_util_remove_options(struct tep_plugin_option *options);
-int trace_util_add_option(const char *name, const char *val);
 int trace_util_load_plugins(struct tep_handle *pevent, const char *suffix,
 			    int (*load_plugin)(struct tep_handle *pevent,
 					       const char *path,
@@ -352,10 +349,7 @@ char **trace_util_find_plugin_files(const char *suffix);
 void trace_util_free_plugin_files(char **files);
 void trace_util_print_plugins(struct trace_seq *s, const char *prefix, const char *suffix,
 			      const struct tep_plugin_list *list);
-void trace_util_print_plugin_options(struct trace_seq *s);
-char **trace_util_list_plugin_options(void);
 void trace_util_free_plugin_options_list(char **list);
-const char *trace_util_plugin_option_value(const char *name);
 
 /* Used for trace-cmd list */
 void tracecmd_ftrace_load_options(void);
include/traceevent/event-parse.h +2 -0
index 65cabd9..a51b73f 100644
@@ -386,7 +386,9 @@ char **tep_plugin_list_options(void);
 void tep_plugin_free_options_list(char **list);
 int tep_plugin_add_options(const char *name,
 			   struct tep_plugin_option *options);
+int tep_plugin_add_option(const char *name, const char *val);
 void tep_plugin_remove_options(struct tep_plugin_option *options);
+void tep_plugin_print_options(struct trace_seq *s);
 void tep_print_plugins(struct trace_seq *s,
 			const char *prefix, const char *suffix,
 			const struct tep_plugin_list *list);
kernel-shark/src/libkshark.c +2 -2
index 4201fa0..47ec9c2 100644
@@ -160,8 +160,8 @@ bool kshark_open(struct kshark_context *kshark_ctx, const char *file)
 	 * Turn off function trace indent and turn on show parent
 	 * if possible.
 	 */
-	trace_util_add_option("ftrace:parent", "1");
-	trace_util_add_option("ftrace:indent", "0");
+	tep_plugin_add_option("ftrace:parent", "1");
+	tep_plugin_add_option("ftrace:indent", "0");
 
 	return true;
 }
lib/trace-cmd/trace-ftrace.c +2 -2
index 22e5213..20bf71f 100644
@@ -359,7 +359,7 @@ fgraph_ret_handler(struct trace_seq *s, struct tep_record *record,
  */
 void tracecmd_ftrace_load_options(void)
 {
-	trace_util_add_options("ftrace", trace_ftrace_options);
+	tep_plugin_add_options("ftrace", trace_ftrace_options);
 }
 
 int tracecmd_ftrace_overrides(struct tracecmd_input *handle,
@@ -381,7 +381,7 @@ int tracecmd_ftrace_overrides(struct tracecmd_input *handle,
 	tep_register_event_handler(pevent, -1, "ftrace", "funcgraph_exit",
 				      fgraph_ret_handler, finfo);
 
-	trace_util_add_options("ftrace", trace_ftrace_options);
+	tep_plugin_add_options("ftrace", trace_ftrace_options);
 
 	/* Store the func ret id and event for later use */
 	event = tep_find_event_by_name(pevent, "ftrace", "funcgraph_exit");
lib/trace-cmd/trace-util.c +0 -422

463 lines not on this page · raw message

lib/traceevent/event-plugin.c +173 -0

197 lines not on this page · raw message

plugins/plugin_function.c +2 -2
index 21ee531..80fdfc3 100644
@@ -215,7 +215,7 @@ int TEP_PLUGIN_LOADER(struct tep_handle *tep)
 	tep_register_event_handler(tep, -1, "ftrace", "kernel_stack",
 				      trace_stack_handler, NULL);
 
-	trace_util_add_options("ftrace", plugin_options);
+	tep_plugin_add_options("ftrace", plugin_options);
 
 	return 0;
 }
@@ -233,7 +233,7 @@ void TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
 		free(fstack[i].stack);
 	}
 
-	trace_util_remove_options(plugin_options);
+	tep_plugin_remove_options(plugin_options);
 
 	free(fstack);
 	fstack = NULL;
tracecmd/trace-list.c +1 -1
index 00c6073..155e297 100644
@@ -320,7 +320,7 @@ static void show_plugin_options(void)
 	trace_seq_init(&s);
 
 	list = tracecmd_load_plugins(pevent);
-	trace_util_print_plugin_options(&s);
+	tep_plugin_print_options(&s);
 	trace_seq_do_printf(&s);
 	tracecmd_unload_plugins(list, pevent);
 	tep_free(pevent);
tracecmd/trace-read.c +1 -1
index d22c723..f8d20ee 100644
@@ -1337,7 +1337,7 @@ static void process_plugin_option(char *option)
 		*p = '\0';
 		val = p+1;
 	}
-	trace_util_add_option(name, val);
+	tep_plugin_add_option(name, val);
 }
 
 static void set_event_flags(struct tep_handle *pevent, struct event_str *list,
Signature · 1 line
2.21.0
#3 lore raw

PATCH v2 3/6 trace-cmd: Remove trace-cmd plugin handling routines

In reply to Tzvetomir Stoyanov (VMware)

From: Tzvetomir Stoyanov (VMware) <[email protected]>

Currently there are no trace-cmd related plugins, all of them are designed to be used with libtraceeevnt. As both libtraceevent and trace-cmd have logic for managing plugins, the one in trace-cmd is redundant. Those redundant code is removed and replaced with calls to libtraceeevnt plugin APIs. When trace-cmd has to load any plugins, it uses libtraceeevnt to do the job.

Removed trace-cmd functions:
tracecmd_load_plugins()
tracecmd_unload_plugins()
trace_util_load_plugins()
trace_util_read_plugin_options()
trace_util_free_options()
trace_util_print_plugins()
trace_util_free_plugin_options_list()

A new libtraceevent API is added:
tep_load_plugins_hook() - the local static
function load_plugins() is exposed as API, as this functionality is needed be trace-cmd.

---
 include/trace-cmd/trace-cmd.h    |  18 --
 include/traceevent/event-parse.h |   6 +
 lib/trace-cmd/trace-input.c      |   9 +-
 lib/trace-cmd/trace-util.c       | 330 +------------------------------
 lib/traceevent/event-plugin.c    |  19 +-
 plugins/plugin_python.c          |   9 +-
 tracecmd/trace-check-events.c    |  10 +-
 tracecmd/trace-list.c            |  21 +-
 8 files changed, 54 insertions(+), 368 deletions(-)
include/trace-cmd/trace-cmd.h +0 -18
index c06067e..94d4f02 100644
@@ -25,10 +25,6 @@ void tracecmd_parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigne
 extern int tracecmd_disable_sys_plugins;
 extern int tracecmd_disable_plugins;
 
-struct tep_plugin_list;
-struct tep_plugin_list *tracecmd_load_plugins(struct tep_handle *pevent);
-void tracecmd_unload_plugins(struct tep_plugin_list *list, struct tep_handle *pevent);
-
 char **tracecmd_event_systems(const char *tracing_dir);
 char **tracecmd_system_events(const char *tracing_dir, const char *system);
 struct tep_handle *tracecmd_local_events(const char *tracing_dir);
@@ -334,22 +330,8 @@ int tracecmd_msg_collect_data(struct tracecmd_msg_handle *msg_handle, int ofd);
 bool tracecmd_msg_done(struct tracecmd_msg_handle *msg_handle);
 void tracecmd_msg_set_done(struct tracecmd_msg_handle *msg_handle);
 
-/* --- Plugin handling --- */
-extern struct tep_plugin_option trace_ftrace_options[];
-
-int trace_util_load_plugins(struct tep_handle *pevent, const char *suffix,
-			    int (*load_plugin)(struct tep_handle *pevent,
-					       const char *path,
-					       const char *name,
-					       void *data),
-			    void *data);
-struct tep_plugin_option *trace_util_read_plugin_options(void);
-void trace_util_free_options(struct tep_plugin_option *options);
 char **trace_util_find_plugin_files(const char *suffix);
 void trace_util_free_plugin_files(char **files);
-void trace_util_print_plugins(struct trace_seq *s, const char *prefix, const char *suffix,
-			      const struct tep_plugin_list *list);
-void trace_util_free_plugin_options_list(char **list);
 
 /* Used for trace-cmd list */
 void tracecmd_ftrace_load_options(void);
include/traceevent/event-parse.h +6 -0
index a51b73f..99da5ef 100644
@@ -382,6 +382,12 @@ struct tep_plugin_list;
 struct tep_plugin_list *tep_load_plugins(struct tep_handle *tep);
 void tep_unload_plugins(struct tep_plugin_list *plugin_list,
 			struct tep_handle *tep);
+void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
+			   void (*load_plugin)(struct tep_handle *tep,
+					       const char *path,
+					       const char *name,
+					       void *data),
+			   void *data);
 char **tep_plugin_list_options(void);
 void tep_plugin_free_options_list(char **list);
 int tep_plugin_add_options(const char *name,
lib/trace-cmd/trace-input.c +7 -2
index 654101f..d28bfa8 100644
@@ -2687,10 +2687,15 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd)
 	if (!handle->pevent)
 		goto failed_read;
 
+	if (tracecmd_disable_plugins)
+		tep_set_flag(handle->pevent, TEP_DISABLE_PLUGINS);
+	if (tracecmd_disable_sys_plugins)
+		tep_set_flag(handle->pevent, TEP_DISABLE_SYS_PLUGINS);
+
 	/* register default ftrace functions first */
 	tracecmd_ftrace_overrides(handle, &handle->finfo);
 
-	handle->plugin_list = tracecmd_load_plugins(handle->pevent);
+	handle->plugin_list = tep_load_plugins(handle->pevent);
 
 	tep_set_file_bigendian(handle->pevent, buf[0]);
 	tep_set_local_bigendian(handle->pevent, tracecmd_host_bigendian());
@@ -2852,7 +2857,7 @@ void tracecmd_close(struct tracecmd_input *handle)
 		tracecmd_close(handle->parent);
 	else {
 		/* Only main handle frees plugins and pevent */
-		tracecmd_unload_plugins(handle->plugin_list, handle->pevent);
+		tep_unload_plugins(handle->plugin_list, handle->pevent);
 		tep_free(handle->pevent);
 	}
 	free(handle);
lib/trace-cmd/trace-util.c +4 -326

384 lines not on this page · raw message

lib/traceevent/event-plugin.c +9 -10
index 43961d9..bc10205 100644
@@ -538,20 +538,19 @@ load_plugins_dir(struct tep_handle *tep, const char *suffix,
 	closedir(dir);
 }
 
-static void
-load_plugins(struct tep_handle *tep, const char *suffix,
-	     void (*load_plugin)(struct tep_handle *tep,
-				 const char *path,
-				 const char *name,
-				 void *data),
-	     void *data)
+void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
+			   void (*load_plugin)(struct tep_handle *tep,
+					       const char *path,
+					       const char *name,
+					       void *data),
+			   void *data)
 {
 	char *home;
 	char *path;
 	char *envdir;
 	int ret;
 
-	if (tep->flags & TEP_DISABLE_PLUGINS)
+	if (tep && tep->flags & TEP_DISABLE_PLUGINS)
 		return;
 
 	/*
@@ -559,7 +558,7 @@ load_plugins(struct tep_handle *tep, const char *suffix,
 	 * check that first.
 	 */
 #ifdef PLUGIN_DIR
-	if (!(tep->flags & TEP_DISABLE_SYS_PLUGINS))
+	if (!tep || !(tep->flags & TEP_DISABLE_SYS_PLUGINS))
 		load_plugins_dir(tep, suffix, PLUGIN_DIR,
 				 load_plugin, data);
 #endif
@@ -596,7 +595,7 @@ tep_load_plugins(struct tep_handle *tep)
 {
 	struct tep_plugin_list *list = NULL;
 
-	load_plugins(tep, ".so", load_plugin, &list);
+	tep_load_plugins_hook(tep, ".so", load_plugin, &list);
 	return list;
 }
 
plugins/plugin_python.c +4 -5
index e725ad8..8a7dacd 100644
@@ -20,7 +20,7 @@ static const char pyload[] =
 "finally:\n"
 "   file.close()\n";
 
-static int load_plugin(struct tep_handle *pevent, const char *path,
+static void load_plugin(struct tep_handle *pevent, const char *path,
 		       const char *name, void *data)
 {
 	PyObject *globals = data;
@@ -33,7 +33,7 @@ static int load_plugin(struct tep_handle *pevent, const char *path,
 	PyObject *res;
 
 	if (!full || !n)
-		return -ENOMEM;
+		return;
 
 	strcpy(full, path);
 	strcat(full, "/");
@@ -44,7 +44,7 @@ static int load_plugin(struct tep_handle *pevent, const char *path,
 
 	err = asprintf(&load, pyload, full, n);
 	if (err < 0)
-		return err;
+		return;
 
 	res = PyRun_String(load, Py_file_input, globals, globals);
 	if (!res) {
@@ -55,7 +55,6 @@ static int load_plugin(struct tep_handle *pevent, const char *path,
 
 	free(load);
 
-	return res ? 0 : -1;
 }
 
 int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
@@ -95,7 +94,7 @@ int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
 	Py_DECREF(py_pevent);
 	Py_DECREF(str);
 
-	trace_util_load_plugins(pevent, ".py", load_plugin, globals);
+	tep_load_plugins_hook(pevent, ".py", load_plugin, globals);
 
 	return 0;
 }
tracecmd/trace-check-events.c +8 -2
index 5fd5d4a..b09fcd0 100644
@@ -42,11 +42,17 @@ void trace_check_events(int argc, char **argv)
 	pevent = tep_alloc();
 	if (!pevent)
 		exit(EINVAL);
-	list = tracecmd_load_plugins(pevent);
+
+	if (tracecmd_disable_plugins)
+		tep_set_flag(pevent, TEP_DISABLE_PLUGINS);
+	if (tracecmd_disable_sys_plugins)
+		tep_set_flag(pevent, TEP_DISABLE_SYS_PLUGINS);
+
+	list = tep_load_plugins(pevent);
 	ret = tracecmd_fill_local_events(tracing, pevent, &parsing_failures);
 	if (ret || parsing_failures)
 		ret = EINVAL;
-	tracecmd_unload_plugins(list, pevent);
+	tep_unload_plugins(list, pevent);
 	tep_free(pevent);
 
 	return;
tracecmd/trace-list.c +16 -5
index 155e297..41d45d0 100644
@@ -317,12 +317,17 @@ static void show_plugin_options(void)
 	if (!pevent)
 		die("Can not allocate pevent\n");
 
+	if (tracecmd_disable_plugins)
+		tep_set_flag(pevent, TEP_DISABLE_PLUGINS);
+	if (tracecmd_disable_sys_plugins)
+		tep_set_flag(pevent, TEP_DISABLE_SYS_PLUGINS);
+
 	trace_seq_init(&s);
 
-	list = tracecmd_load_plugins(pevent);
+	list = tep_load_plugins(pevent);
 	tep_plugin_print_options(&s);
 	trace_seq_do_printf(&s);
-	tracecmd_unload_plugins(list, pevent);
+	tep_unload_plugins(list, pevent);
 	tep_free(pevent);
 }
 
@@ -343,12 +348,18 @@ static void show_plugins(void)
 	if (!pevent)
 		die("Can not allocate pevent\n");
 
+	if (tracecmd_disable_plugins)
+		tep_set_flag(pevent, TEP_DISABLE_PLUGINS);
+	if (tracecmd_disable_sys_plugins)
+		tep_set_flag(pevent, TEP_DISABLE_SYS_PLUGINS);
+
 	trace_seq_init(&s);
 
-	list = tracecmd_load_plugins(pevent);
-	trace_util_print_plugins(&s, "  ", "\n", list);
+	list = tep_load_plugins(pevent);
+	tep_print_plugins(&s, "  ", "\n", list);
+
 	trace_seq_do_printf(&s);
-	tracecmd_unload_plugins(list, pevent);
+	tep_unload_plugins(list, pevent);
 	tep_free(pevent);
 }
 
Signature · 1 line
2.21.0
#4 lore raw

PATCH v2 4/6 trace-cmd: Move libtraceevent plugins in its own directory.

In reply to Tzvetomir Stoyanov (VMware)

All existing plugins are moved from plugins/ to plugins/traceevent/ directory, as all of them (except plugin_python) are designed to be used with the traceevent library. This change paves the way for implementing trace-cmd specific plugins.

---
 .gitignore                                    |  2 +-
 Makefile                                      | 28 +++++++++----------
 lib/trace-cmd/Makefile                        |  2 --
 plugins/{ => traceevent}/Makefile             |  6 ++--
 plugins/{ => traceevent}/plugin_blk.c         |  0
 plugins/{ => traceevent}/plugin_cfg80211.c    |  0
 plugins/{ => traceevent}/plugin_function.c    |  0
 plugins/{ => traceevent}/plugin_futex.c       |  0
 plugins/{ => traceevent}/plugin_hrtimer.c     |  0
 plugins/{ => traceevent}/plugin_jbd2.c        |  0
 plugins/{ => traceevent}/plugin_kmem.c        |  0
 plugins/{ => traceevent}/plugin_kvm.c         |  0
 plugins/{ => traceevent}/plugin_mac80211.c    |  0
 plugins/{ => traceevent}/plugin_python.c      |  0
 .../{ => traceevent}/plugin_sched_switch.c    |  0
 plugins/{ => traceevent}/plugin_scsi.c        |  0
 plugins/{ => traceevent}/plugin_tlb.c         |  0
 plugins/{ => traceevent}/plugin_xen.c         |  0
 18 files changed, 18 insertions(+), 20 deletions(-)
 rename plugins/{ => traceevent}/Makefile (93%)
 rename plugins/{ => traceevent}/plugin_blk.c (100%)
 rename plugins/{ => traceevent}/plugin_cfg80211.c (100%)
 rename plugins/{ => traceevent}/plugin_function.c (100%)
 rename plugins/{ => traceevent}/plugin_futex.c (100%)
 rename plugins/{ => traceevent}/plugin_hrtimer.c (100%)
 rename plugins/{ => traceevent}/plugin_jbd2.c (100%)
 rename plugins/{ => traceevent}/plugin_kmem.c (100%)
 rename plugins/{ => traceevent}/plugin_kvm.c (100%)
 rename plugins/{ => traceevent}/plugin_mac80211.c (100%)
 rename plugins/{ => traceevent}/plugin_python.c (100%)
 rename plugins/{ => traceevent}/plugin_sched_switch.c (100%)
 rename plugins/{ => traceevent}/plugin_scsi.c (100%)
 rename plugins/{ => traceevent}/plugin_tlb.c (100%)
 rename plugins/{ => traceevent}/plugin_xen.c (100%)
.gitignore +1 -1
index b7b405f..20bb5a3 100644
@@ -18,5 +18,5 @@ ctracecmdgui_wrap.c
 tags
 TAGS
 cscope*
-trace_plugin_dir
+traceevent_plugin_dir
 trace_python_dir
Makefile +14 -14
index ad74a96..8b228f5 100644
@@ -266,16 +266,16 @@ gui: force $(CMD_TARGETS) $(kshark-dir)/build/Makefile
 trace-cmd: force $(LIBTRACEEVENT_STATIC) $(LIBTRACECMD_STATIC)
 	$(Q)$(MAKE) -C $(src)/tracecmd $(obj)/tracecmd/$@
 
-$(LIBTRACEEVENT_SHARED): force
+$(LIBTRACEEVENT_SHARED): force $(obj)/plugins/traceevent/traceevent_plugin_dir
 	$(Q)$(MAKE) -C $(src)/lib/traceevent $@
 
-$(LIBTRACEEVENT_STATIC): force
+$(LIBTRACEEVENT_STATIC): force $(obj)/plugins/traceevent/traceevent_plugin_dir
 	$(Q)$(MAKE) -C $(src)/lib/traceevent $@
 
-$(LIBTRACECMD_STATIC): force $(obj)/plugins/trace_plugin_dir
+$(LIBTRACECMD_STATIC): force
 	$(Q)$(MAKE) -C $(src)/lib/trace-cmd $@
 
-$(LIBTRACECMD_SHARED): force $(obj)/plugins/trace_plugin_dir
+$(LIBTRACECMD_SHARED): force
 	$(Q)$(MAKE) -C $(src)/lib/trace-cmd $@
 
 libtraceevent.so: $(LIBTRACEEVENT_SHARED)
@@ -285,14 +285,14 @@ libtracecmd.so: $(LIBTRACECMD_SHARED)
 
 libs: $(LIBTRACECMD_SHARED) $(LIBTRACEEVENT_SHARED)
 
-plugins: force $(obj)/plugins/trace_plugin_dir $(obj)/plugins/trace_python_dir
-	$(Q)$(MAKE) -C $(src)/plugins
+plugins: force $(obj)/plugins/traceevent/traceevent_plugin_dir $(obj)/plugins/traceevent/trace_python_dir
+	$(Q)$(MAKE) -C $(src)/plugins/traceevent
 
-$(obj)/plugins/trace_plugin_dir: force
-	$(Q)$(MAKE) -C $(src)/plugins $@
+$(obj)/plugins/traceevent/traceevent_plugin_dir: force
+	$(Q)$(MAKE) -C $(src)/plugins/traceevent $@
 
-$(obj)/plugins/trace_python_dir: force
-	$(Q)$(MAKE) -C $(src)/plugins $@
+$(obj)/plugins/traceevent/trace_python_dir: force
+	$(Q)$(MAKE) -C $(src)/plugins/traceevent $@
 
 show_gui_make:
 	@echo "Note: to build the gui, type \"make gui\""
@@ -318,7 +318,7 @@ cscope: force
 	$(call find_tag_files) | cscope -b -q
 
 install_plugins: force
-	$(Q)$(MAKE) -C $(src)/plugins $@
+	$(Q)$(MAKE) -C $(src)/plugins/traceevent $@
 
 install_python: force
 	$(Q)$(MAKE) -C $(src)/python $@
@@ -356,7 +356,7 @@ clean:
 	$(RM) tags TAGS cscope*
 	$(MAKE) -C $(src)/lib/traceevent clean
 	$(MAKE) -C $(src)/lib/trace-cmd clean
-	$(MAKE) -C $(src)/plugins clean
+	$(MAKE) -C $(src)/plugins/traceevent clean
 	$(MAKE) -C $(src)/python clean
 	$(MAKE) -C $(src)/tracecmd clean
 	if [ -f $(kshark-dir)/build/Makefile ]; then $(MAKE) -C $(kshark-dir)/build clean; fi
@@ -405,8 +405,8 @@ python-gui: $(PYTHON_GUI)
 PHONY += python-plugin
 python-plugin: $(PYTHON_PLUGINS)
 
-plugin_python.so: force $(obj)/plugins/trace_python_dir
-	$(Q)$(MAKE) -C $(src)/plugins $(obj)/plugins/plugin_python.so
+plugin_python.so: force $(obj)/plugins/traceevent/trace_python_dir
+	$(Q)$(MAKE) -C $(src)/plugins/traceevent $(obj)/plugins/traceevent/plugin_python.so
 
 dist:
 	git archive --format=tar --prefix=trace-cmd-$(TRACECMD_VERSION)/ HEAD \
lib/trace-cmd/Makefile +0 -2
index 44c1332..6f9a013 100644
@@ -38,8 +38,6 @@ $(bdir)/libtracecmd.so: $(OBJS)
 $(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
 
-$(bdir)/trace-util.o: $(obj)/plugins/trace_plugin_dir
-
 $(DEPS): $(bdir)/.%.d: %.c
 	$(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@
 
plugins/traceevent/Makefile renamed from plugins/Makefile +3 -3
similarity index 93%
rename from plugins/Makefile
rename to plugins/traceevent/Makefile
index 4598e83..8ed65d3 100644
@@ -1,6 +1,6 @@
 include $(src)/scripts/utils.mk
 
-bdir:=$(obj)/plugins
+bdir:=$(obj)/plugins/traceevent
 
 PLUGIN_OBJS =
 PLUGIN_OBJS += plugin_jbd2.o
@@ -61,7 +61,7 @@ install_plugins: $(PLUGINS_INSTALL)
 # and $(PYTHON_DIR) change. Without them, a full clean build would necessary
 # in order to get the binaries updated.
 
-$(bdir)/trace_plugin_dir: $(bdir) force
+$(bdir)/traceevent_plugin_dir: $(bdir) force
 	$(Q)$(N)$(call update_dir, 'PLUGIN_DIR=$(PLUGIN_DIR)')
 
 $(bdir)/trace_python_dir: $(bdir) force
@@ -75,7 +75,7 @@ ifneq ($(dep_includes),)
 endif
 
 clean:
-	$(RM) -f $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d $(bdir)/trace_plugin_dir $(bdir)/trace_python_dir
+	$(RM) -f $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d $(bdir)/traceevent_plugin_dir $(bdir)/trace_python_dir
 
 force:
 .PHONY: clean force
plugins/traceevent/plugin_blk.c renamed from plugins/plugin_blk.c +0 -0
similarity index 100%
rename from plugins/plugin_blk.c
rename to plugins/traceevent/plugin_blk.c
plugins/traceevent/plugin_cfg80211.c renamed from plugins/plugin_cfg80211.c +0 -0
similarity index 100%
rename from plugins/plugin_cfg80211.c
rename to plugins/traceevent/plugin_cfg80211.c
plugins/traceevent/plugin_function.c renamed from plugins/plugin_function.c +0 -0
similarity index 100%
rename from plugins/plugin_function.c
rename to plugins/traceevent/plugin_function.c
plugins/traceevent/plugin_futex.c renamed from plugins/plugin_futex.c +0 -0
similarity index 100%
rename from plugins/plugin_futex.c
rename to plugins/traceevent/plugin_futex.c
plugins/traceevent/plugin_hrtimer.c renamed from plugins/plugin_hrtimer.c +0 -0
similarity index 100%
rename from plugins/plugin_hrtimer.c
rename to plugins/traceevent/plugin_hrtimer.c
plugins/traceevent/plugin_jbd2.c renamed from plugins/plugin_jbd2.c +0 -0
similarity index 100%
rename from plugins/plugin_jbd2.c
rename to plugins/traceevent/plugin_jbd2.c
plugins/traceevent/plugin_kmem.c renamed from plugins/plugin_kmem.c +0 -0
similarity index 100%
rename from plugins/plugin_kmem.c
rename to plugins/traceevent/plugin_kmem.c
plugins/traceevent/plugin_kvm.c renamed from plugins/plugin_kvm.c +0 -0
similarity index 100%
rename from plugins/plugin_kvm.c
rename to plugins/traceevent/plugin_kvm.c
plugins/traceevent/plugin_mac80211.c renamed from plugins/plugin_mac80211.c +0 -0
similarity index 100%
rename from plugins/plugin_mac80211.c
rename to plugins/traceevent/plugin_mac80211.c
plugins/traceevent/plugin_python.c renamed from plugins/plugin_python.c +0 -0
similarity index 100%
rename from plugins/plugin_python.c
rename to plugins/traceevent/plugin_python.c
plugins/traceevent/plugin_sched_switch.c renamed from plugins/plugin_sched_switch.c +0 -0
similarity index 100%
rename from plugins/plugin_sched_switch.c
rename to plugins/traceevent/plugin_sched_switch.c
plugins/traceevent/plugin_scsi.c renamed from plugins/plugin_scsi.c +0 -0
similarity index 100%
rename from plugins/plugin_scsi.c
rename to plugins/traceevent/plugin_scsi.c
plugins/traceevent/plugin_tlb.c renamed from plugins/plugin_tlb.c +0 -0
similarity index 100%
rename from plugins/plugin_tlb.c
rename to plugins/traceevent/plugin_tlb.c
plugins/traceevent/plugin_xen.c renamed from plugins/plugin_xen.c +0 -0
similarity index 100%
rename from plugins/plugin_xen.c
rename to plugins/traceevent/plugin_xen.c
Signature · 1 line
2.21.0
#5 lore raw

Re: [PATCH v2 4/6] trace-cmd: Move libtraceevent plugins in its own directory.

Quoted 7 lines · On Fri, 2 Aug 2019 14:00:59 +0300 "Tzvetomir Stoyanov (VMware)"…

All existing plugins are moved from plugins/ to plugins/traceevent/ directory, as all of them (except plugin_python) are designed to be used with the traceevent library. This change paves the way for implementing trace-cmd specific plugins.

To make this more consistent with the kernel, let's move it to:

lib/traceevent/plugins

and I would suggest making a patch for the kernel to move all the plugin code to:

tools/lib/traceevent/plugins

We could then have the trace-cmd plugins be in:

lib/trace-cmd/plugins

That way we know what goes with what library.

-- Steve

#6 lore raw

PATCH v2 5/6 trace-cmd: Load libtraceevent plugins from build folder, if exists.

In reply to Tzvetomir Stoyanov (VMware)

When a development version of trace-cmd is built and run on the machine, by default it loads only installed plugins, from system drierctories. Thus, the development plugins will not be loaded. To simplify the development process, a new logic is added:
At plugins load time, check the location of trace-cmd application and look for "plugins" directory around it. If found, load plugins from it. Those pluigins will be loaded last, so in case of duplication the "development" plugins win.

---
 lib/traceevent/event-plugin.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
lib/traceevent/event-plugin.c +28 -0
index bc10205..fdaadba 100644
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <errno.h>
+#include <libgen.h>
 #include "event-parse.h"
 #include "event-parse-local.h"
 #include "event-utils.h"
@@ -538,6 +539,27 @@ load_plugins_dir(struct tep_handle *tep, const char *suffix,
 	closedir(dir);
 }
 
+static char *get_source_plugins_dir(void)
+{
+	char *p, path[PATH_MAX+1];
+	int ret;
+
+	ret = readlink("/proc/self/exe", path, PATH_MAX);
+	if (ret > PATH_MAX || ret < 0)
+		return NULL;
+
+	dirname(path);
+	p = strrchr(path, '/');
+	if (!p)
+		return NULL;
+	/* Check if we are in the the source tree */
+	if (strcmp(p, "/tracecmd") != 0)
+		return NULL;
+
+	strcpy(p, "/plugins/traceevent");
+	return strdup(path);
+}
+
 void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
 			   void (*load_plugin)(struct tep_handle *tep,
 					       const char *path,
@@ -588,6 +610,12 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
 	load_plugins_dir(tep, suffix, path, load_plugin, data);
 
 	free(path);
+
+	path = get_source_plugins_dir();
+	if (path) {
+		load_plugins_dir(tep, suffix, path, load_plugin, data);
+		free(path);
+	}
 }
 
 struct tep_plugin_list*
Signature · 1 line
2.21.0
#7 lore raw

PATCH v2 6/6 trace-cmd: Change plugin install directories

In reply to Tzvetomir Stoyanov (VMware)

From: Tzvetomir Stoyanov <[email protected]>

To be compliant with XDG user directory layout, the user's plugin directory is changed from ~/.traceevent/plugins to ~/.local/lib/traceevent/plugins/ Thanks to Patrick McLean:
https://lore.kernel.org/linux-trace-devel/20190313144206.41e75cf8@patrickm/

The system plugin directory is changed from (install_prefix)/lib/trace-cmd/plugins to (install_prefix)/lib/traceevent/plugins This change paves the way for implementing trace-cmd specific plugins.

---
 Makefile                      | 16 ++++++++--------
 lib/traceevent/event-plugin.c |  6 +++---
 plugins/traceevent/Makefile   |  6 +++---
 3 files changed, 14 insertions(+), 14 deletions(-)
Makefile +8 -8
index 8b228f5..5bfb558 100644
@@ -59,15 +59,15 @@ export img_install img_install_SQ
 export DESTDIR DESTDIR_SQ
 
 ifeq ($(prefix),$(HOME))
-plugin_dir = $(HOME)/.trace-cmd/plugins
+plugin_traceevent_dir = $(HOME)/.local/lib/traceevent/plugins
 python_dir = $(HOME)/.trace-cmd/python
 var_dir = $(HOME)/.trace-cmd/
 else
-plugin_dir = $(libdir)/trace-cmd/plugins
+plugin_traceevent_dir = $(libdir)/traceevent/plugins
 python_dir = $(libdir)/trace-cmd/python
-PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
+PLUGIN_TRACEEVENT_DIR = -DPLUGIN_DIR="$(plugin_traceevent_dir)"
 PYTHON_DIR = -DPYTHON_DIR="$(python_dir)"
-PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
+PLUGIN_TRACEEVENT_DIR_SQ = '$(subst ','\'',$(PLUGIN_TRACEEVENT_DIR))'
 PYTHON_DIR_SQ = '$(subst ','\'',$(PYTHON_DIR))'
 var_dir = /var
 endif
@@ -75,7 +75,7 @@ endif
 # Shell quotes
 bindir_SQ = $(subst ','\'',$(bindir))
 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
-plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
+plugin_traceevent_dir_SQ = $(subst ','\'',$(plugin_traceevent_dir))
 python_dir_SQ = $(subst ','\'',$(python_dir))
 
 VAR_DIR = -DVAR_DIR="$(var_dir)"
@@ -88,10 +88,10 @@ HELP_DIR_SQ = '$(subst ','\'',$(HELP_DIR))'
 
 BASH_COMPLETE_DIR ?= /etc/bash_completion.d
 
-export PLUGIN_DIR
+export PLUGIN_TRACEEVENT_DIR
 export PYTHON_DIR
 export PYTHON_DIR_SQ
-export plugin_dir_SQ
+export plugin_traceevent_dir_SQ
 export python_dir_SQ
 export var_dir
 
@@ -235,7 +235,7 @@ LIBS += -laudit
 endif
 
 # Append required CFLAGS
-override CFLAGS += $(INCLUDES) $(PLUGIN_DIR_SQ) $(VAR_DIR)
+override CFLAGS += $(INCLUDES) $(PLUGIN_TRACEEVENT_DIR_SQ) $(VAR_DIR)
 override CFLAGS += $(udis86-flags) $(blk-flags)
 
 CMD_TARGETS = trace-cmd $(BUILD_PYTHON)
lib/traceevent/event-plugin.c +3 -3
index fdaadba..383a8be 100644
@@ -20,7 +20,7 @@
 #include "event-utils.h"
 #include "trace-seq.h"
 
-#define LOCAL_PLUGIN_DIR ".traceevent/plugins"
+#define LOCAL_PLUGIN_DIR ".local/lib/traceevent/plugins/"
 
 static struct registered_plugin_options {
 	struct registered_plugin_options	*next;
@@ -579,9 +579,9 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
 	 * If a system plugin directory was defined,
 	 * check that first.
 	 */
-#ifdef PLUGIN_DIR
+#ifdef PLUGIN_TRACEEVENT_DIR
 	if (!tep || !(tep->flags & TEP_DISABLE_SYS_PLUGINS))
-		load_plugins_dir(tep, suffix, PLUGIN_DIR,
+		load_plugins_dir(tep, suffix, PLUGIN_TRACEEVENT_DIR,
 				 load_plugin, data);
 #endif
 
plugins/traceevent/Makefile +3 -3
index 8ed65d3..98fcc4d 100644
@@ -53,16 +53,16 @@ $(bdir)/plugin_python.so: $(bdir)/%.so: $(bdir)/%.o
 PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS))
 
 $(PLUGINS_INSTALL): $(bdir)/%.install : $(bdir)/%.so force
-	$(Q)$(call do_install_data,$<,$(plugin_dir_SQ))
+	$(Q)$(call do_install_data,$<,$(plugin_traceevent_dir_SQ))
 
 install_plugins: $(PLUGINS_INSTALL)
 
-# The following targets are necessary to trigger a rebuild when $(PLUGIN_DIR)
+# The following targets are necessary to trigger a rebuild when $(PLUGIN_TRACEEVENT_DIR)
 # and $(PYTHON_DIR) change. Without them, a full clean build would necessary
 # in order to get the binaries updated.
 
 $(bdir)/traceevent_plugin_dir: $(bdir) force
-	$(Q)$(N)$(call update_dir, 'PLUGIN_DIR=$(PLUGIN_DIR)')
+	$(Q)$(N)$(call update_dir, 'PLUGIN_TRACEEVENT_DIR=$(PLUGIN_TRACEEVENT_DIR)')
 
 $(bdir)/trace_python_dir: $(bdir) force
 	$(Q)$(N)$(call update_dir, 'PYTHON_DIR=$(PYTHON_DIR)')
Signature · 1 line
2.21.0