linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] Separate trace-cmd and libtracecmd code
@ 2019-07-11 13:03 Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 1/7] trace-cmd: Move trace-output.c into the library code Tzvetomir Stoyanov (VMware)
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2019-07-11 13:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

libtracecmd is a library, containing functions that can be
used without trace-cmd application. However, some of the
functions declared as libtracecmd APIs in trace-cmd.h
depend on trace-cmd context. That causes a problem when
other application uses the library. The problem can be
observed when running kerneshark and there is a python
module, loaded by the python plugin - there is a bunch
of warnings.
To resolve the problem, implementations of all trace-cmd
independent functions are moved into libtracecmd. All
libtracecmd functions, that depend on trace-cmd context
are removed from the library and from trace-cmd.h file.

Tzvetomir Stoyanov (VMware) (7):
  trace-cmd: Move trace-output.c into the library code
  trace-cmd: Move trace-msg.c into the library.
  trace-cmd: Move trace-cmd global variable "quiet" to libtracecmd
  trace-cmd: Move trace-cmd global variable "debug" to libtracecmd
  trace-cmd: Move plog() function to libtracecmd.
  trace-cmd: Move trace-cmd APIs from trace-cmd.h to trace-local.h
  trace-cmd: Move tracecmd_stack_tracer_status() function to libtracecmd

 include/trace-cmd/trace-cmd.h                 |  19 +-
 .../include => include/trace-cmd}/trace-msg.h |   3 -
 lib/trace-cmd/Makefile                        |  12 +-
 {tracecmd => lib/trace-cmd}/trace-msg.c       |   4 +-
 {tracecmd => lib/trace-cmd}/trace-output.c    |   4 +-
 lib/trace-cmd/trace-util.c                    | 162 ++++++++++++++++++
 tracecmd/Makefile                             |   2 -
 tracecmd/include/trace-cmd-local.h            |   2 -
 tracecmd/include/trace-local.h                |  14 +-
 tracecmd/trace-cmd.c                          |   3 -
 tracecmd/trace-list.c                         |   2 +-
 tracecmd/trace-listen.c                       |  77 ++-------
 tracecmd/trace-read.c                         |   8 +-
 tracecmd/trace-record.c                       |   8 +-
 tracecmd/trace-stack.c                        |  56 +-----
 15 files changed, 221 insertions(+), 155 deletions(-)
 rename {tracecmd/include => include/trace-cmd}/trace-msg.h (79%)
 rename {tracecmd => lib/trace-cmd}/trace-msg.c (99%)
 rename {tracecmd => lib/trace-cmd}/trace-output.c (99%)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/7] trace-cmd: Move trace-output.c into the library code
  2019-07-11 13:03 [PATCH 0/7] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
@ 2019-07-11 13:03 ` Tzvetomir Stoyanov (VMware)
  2019-08-08 23:37   ` Steven Rostedt
  2019-07-11 13:03 ` [PATCH 2/7] trace-cmd: Move trace-msg.c into the library Tzvetomir Stoyanov (VMware)
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2019-07-11 13:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Functions, implemented in trace-output.c file, do not depend on
trace-cmd application context and can be used standalone. The file
is moved from trace-cmd to libtracecmd. It also fixes a warning
while loading python modules from kernelshark:
ImportError: ctracecmd.so: undefined symbol: tracecmd_append_cpu_data

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/trace-cmd/Makefile                     | 11 ++++++++++-
 {tracecmd => lib/trace-cmd}/trace-output.c |  0
 tracecmd/Makefile                          |  1 -
 3 files changed, 10 insertions(+), 2 deletions(-)
 rename {tracecmd => lib/trace-cmd}/trace-output.c (100%)

diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile
index 44c1332..9086eb6 100644
--- a/lib/trace-cmd/Makefile
+++ b/lib/trace-cmd/Makefile
@@ -4,12 +4,15 @@ include $(src)/scripts/utils.mk
 
 bdir:=$(obj)/lib/trace-cmd
 
-DEFAULT_TARGET = $(bdir)/libtracecmd.a
+TC_VERSION := $(bdir)/include/tc_version.h
+
+DEFAULT_TARGET = $(bdir)/libtracecmd.a $(TC_VERSION)
 
 OBJS =
 OBJS += trace-hash.o
 OBJS += trace-hooks.o
 OBJS += trace-input.o
+OBJS += trace-output.o
 OBJS += trace-recorder.o
 OBJS += trace-util.o
 OBJS += trace-filter-hash.o
@@ -29,6 +32,9 @@ $(bdir):
 $(OBJS): | $(bdir)
 $(DEPS): | $(bdir)
 
+$(TC_VERSION): force | $(bdir)/include
+	$(Q)$(call update_version.h)
+
 $(bdir)/libtracecmd.a: $(OBJS)
 	$(Q)$(call do_build_static_lib)
 
@@ -43,6 +49,8 @@ $(bdir)/trace-util.o: $(obj)/plugins/trace_plugin_dir
 $(DEPS): $(bdir)/.%.d: %.c
 	$(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@
 
+$(DEPS): $(TC_VERSION)
+
 $(OBJS): $(bdir)/%.o : $(bdir)/.%.d
 
 dep_includes := $(wildcard $(DEPS))
@@ -54,4 +62,5 @@ endif
 clean:
 	$(RM) $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d
 
+force:
 .PHONY: clean
diff --git a/tracecmd/trace-output.c b/lib/trace-cmd/trace-output.c
similarity index 100%
rename from tracecmd/trace-output.c
rename to lib/trace-cmd/trace-output.c
diff --git a/tracecmd/Makefile b/tracecmd/Makefile
index bcd437a..6968f83 100644
--- a/tracecmd/Makefile
+++ b/tracecmd/Makefile
@@ -29,7 +29,6 @@ TRACE_CMD_OBJS += trace-restore.o
 TRACE_CMD_OBJS += trace-check-events.o
 TRACE_CMD_OBJS += trace-show.o
 TRACE_CMD_OBJS += trace-list.o
-TRACE_CMD_OBJS += trace-output.o
 TRACE_CMD_OBJS += trace-usage.o
 TRACE_CMD_OBJS += trace-msg.o
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/7] trace-cmd: Move trace-msg.c into the library.
  2019-07-11 13:03 [PATCH 0/7] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 1/7] trace-cmd: Move trace-output.c into the library code Tzvetomir Stoyanov (VMware)
@ 2019-07-11 13:03 ` Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 3/7] trace-cmd: Move trace-cmd global variable "quiet" to libtracecmd Tzvetomir Stoyanov (VMware)
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2019-07-11 13:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Functions, implemented in trace-msg.c file, do not depend on
trace-cmd application context and can be used standalone.
The file is moved from trace-cmd to libtracecmd.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 {tracecmd/include => include/trace-cmd}/trace-msg.h | 0
 lib/trace-cmd/Makefile                              | 1 +
 {tracecmd => lib/trace-cmd}/trace-msg.c             | 0
 tracecmd/Makefile                                   | 1 -
 4 files changed, 1 insertion(+), 1 deletion(-)
 rename {tracecmd/include => include/trace-cmd}/trace-msg.h (100%)
 rename {tracecmd => lib/trace-cmd}/trace-msg.c (100%)

diff --git a/tracecmd/include/trace-msg.h b/include/trace-cmd/trace-msg.h
similarity index 100%
rename from tracecmd/include/trace-msg.h
rename to include/trace-cmd/trace-msg.h
diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile
index 9086eb6..5f7b111 100644
--- a/lib/trace-cmd/Makefile
+++ b/lib/trace-cmd/Makefile
@@ -16,6 +16,7 @@ OBJS += trace-output.o
 OBJS += trace-recorder.o
 OBJS += trace-util.o
 OBJS += trace-filter-hash.o
+OBJS += trace-msg.o
 
 # Additional util objects
 OBJS += trace-blk-hack.o
diff --git a/tracecmd/trace-msg.c b/lib/trace-cmd/trace-msg.c
similarity index 100%
rename from tracecmd/trace-msg.c
rename to lib/trace-cmd/trace-msg.c
diff --git a/tracecmd/Makefile b/tracecmd/Makefile
index 6968f83..d491aae 100644
--- a/tracecmd/Makefile
+++ b/tracecmd/Makefile
@@ -30,7 +30,6 @@ TRACE_CMD_OBJS += trace-check-events.o
 TRACE_CMD_OBJS += trace-show.o
 TRACE_CMD_OBJS += trace-list.o
 TRACE_CMD_OBJS += trace-usage.o
-TRACE_CMD_OBJS += trace-msg.o
 
 ALL_OBJS := $(TRACE_CMD_OBJS:%.o=$(bdir)/%.o)
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/7] trace-cmd: Move trace-cmd global variable "quiet" to libtracecmd
  2019-07-11 13:03 [PATCH 0/7] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 1/7] trace-cmd: Move trace-output.c into the library code Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 2/7] trace-cmd: Move trace-msg.c into the library Tzvetomir Stoyanov (VMware)
@ 2019-07-11 13:03 ` Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 4/7] trace-cmd: Move trace-cmd global variable "debug" " Tzvetomir Stoyanov (VMware)
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2019-07-11 13:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

A trace-cmd global variable "quiet" is used from libtracecmd and
should be defined there. A new library APIs are implemented to
access it:
 void tracecmd_set_quiet(int quiet);
 int tracecmd_get_quiet(void);

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/trace-cmd/trace-cmd.h      |  3 +++
 lib/trace-cmd/trace-output.c       |  4 ++--
 lib/trace-cmd/trace-util.c         | 21 +++++++++++++++++++++
 tracecmd/include/trace-cmd-local.h |  2 --
 tracecmd/include/trace-local.h     |  1 -
 tracecmd/trace-cmd.c               |  1 -
 tracecmd/trace-record.c            |  6 +++---
 7 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index 6f62ab9..8c8f87c 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -49,6 +49,9 @@ enum {
 void tracecmd_record_ref(struct tep_record *record);
 void free_record(struct tep_record *record);
 
+void tracecmd_set_quiet(int quiet);
+int tracecmd_get_quiet(void);
+
 struct tracecmd_input;
 struct tracecmd_output;
 struct tracecmd_recorder;
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 33d6ce3..6ca7110 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -1158,7 +1158,7 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle,
 		goto out_free;
 
 	for (i = 0; i < cpus; i++) {
-		if (!quiet)
+		if (!tracecmd_get_quiet())
 			fprintf(stderr, "CPU%d data recorded at offset=0x%llx\n",
 				i, (unsigned long long) offsets[i]);
 		offset = lseek64(handle->fd, offsets[i], SEEK_SET);
@@ -1173,7 +1173,7 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle,
 			    check_size, sizes[i]);
 			goto out_free;
 		}
-		if (!quiet)
+		if (!tracecmd_get_quiet())
 			fprintf(stderr, "    %llu bytes in size\n",
 				(unsigned long long)check_size);
 	}
diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 7c74bae..26b9a18 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -28,6 +28,7 @@
 
 int tracecmd_disable_sys_plugins;
 int tracecmd_disable_plugins;
+static int tracecmd_quiet;
 
 static struct registered_plugin_options {
 	struct registered_plugin_options	*next;
@@ -96,6 +97,26 @@ char **trace_util_list_plugin_options(void)
 	return list;
 }
 
+/**
+ * tracecmd_set_quiet - Set if to print output to the screen
+ * @quiet: If non zero, print no output to the screen
+ *
+ */
+void tracecmd_set_quiet(int quiet)
+{
+	tracecmd_quiet = quiet;
+}
+
+/**
+ * tracecmd_get_quiet - Get if to print output to the screen
+ * Returns non zero, if no output to the screen should be printed
+ *
+ */
+int tracecmd_get_quiet(void)
+{
+	return tracecmd_quiet;
+}
+
 void trace_util_free_plugin_options_list(char **list)
 {
 	tracecmd_free_list(list);
diff --git a/tracecmd/include/trace-cmd-local.h b/tracecmd/include/trace-cmd-local.h
index fa96d4f..16db7a3 100644
--- a/tracecmd/include/trace-cmd-local.h
+++ b/tracecmd/include/trace-cmd-local.h
@@ -11,8 +11,6 @@
 #include "trace-cmd.h"
 #include "event-utils.h"
 
-extern int quiet;
-
 static ssize_t __do_write(int fd, const void *data, size_t size)
 {
 	ssize_t tot = 0;
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 1cad3cc..8fbafa6 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -13,7 +13,6 @@
 #include "event-utils.h"
 
 extern int debug;
-extern int quiet;
 
 /* fix stupid glib guint64 typecasts and printf formats */
 typedef unsigned long long u64;
diff --git a/tracecmd/trace-cmd.c b/tracecmd/trace-cmd.c
index 797b303..5283ba7 100644
--- a/tracecmd/trace-cmd.c
+++ b/tracecmd/trace-cmd.c
@@ -17,7 +17,6 @@ int silence_warnings;
 int show_status;
 
 int debug;
-int quiet;
 
 void warning(const char *fmt, ...)
 {
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 5dc6f17..e647117 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3163,7 +3163,7 @@ static void print_stat(struct buffer_instance *instance)
 {
 	int cpu;
 
-	if (quiet)
+	if (tracecmd_get_quiet())
 		return;
 
 	if (!is_top_instance(instance))
@@ -3979,7 +3979,7 @@ static void check_plugin(const char *plugin)
 	}
 	die ("Plugin '%s' does not exist", plugin);
  out:
-	if (!quiet)
+	if (!tracecmd_get_quiet())
 		fprintf(stderr, "  plugin '%s'\n", plugin);
 	free(buf);
 }
@@ -4913,7 +4913,7 @@ static void parse_record_options(int argc,
 			break;
 		case OPT_quiet:
 		case 'q':
-			quiet = 1;
+			tracecmd_set_quiet(1);
 			break;
 		default:
 			usage(argv);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/7] trace-cmd: Move trace-cmd global variable "debug" to libtracecmd
  2019-07-11 13:03 [PATCH 0/7] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
                   ` (2 preceding siblings ...)
  2019-07-11 13:03 ` [PATCH 3/7] trace-cmd: Move trace-cmd global variable "quiet" to libtracecmd Tzvetomir Stoyanov (VMware)
@ 2019-07-11 13:03 ` Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 5/7] trace-cmd: Move plog() function " Tzvetomir Stoyanov (VMware)
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2019-07-11 13:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

A trace-cmd global variable "debug" is used from libtracecmd and
should be defined there. A new library APIs are implemented to
access it:
 void tracecmd_set_debug(bool debug);
 bool tracecmd_get_debug(void);

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/trace-cmd/trace-cmd.h  |  3 +++
 lib/trace-cmd/trace-msg.c      |  4 ++--
 lib/trace-cmd/trace-util.c     | 21 +++++++++++++++++++++
 tracecmd/include/trace-local.h |  2 --
 tracecmd/trace-cmd.c           |  2 --
 tracecmd/trace-list.c          |  2 +-
 tracecmd/trace-listen.c        |  8 ++++----
 tracecmd/trace-read.c          |  8 ++++----
 tracecmd/trace-record.c        |  2 +-
 9 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index 8c8f87c..2f524b6 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -51,6 +51,9 @@ void free_record(struct tep_record *record);
 
 void tracecmd_set_quiet(int quiet);
 int tracecmd_get_quiet(void);
+void tracecmd_set_debug(bool debug);
+bool tracecmd_get_debug(void);
+
 
 struct tracecmd_input;
 struct tracecmd_output;
diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c
index e2dd188..92562c7 100644
--- a/lib/trace-cmd/trace-msg.c
+++ b/lib/trace-cmd/trace-msg.c
@@ -32,7 +32,7 @@ static inline void dprint(const char *fmt, ...)
 {
 	va_list ap;
 
-	if (!debug)
+	if (!tracecmd_get_debug())
 		return;
 
 	va_start(ap, fmt);
@@ -351,7 +351,7 @@ static int tracecmd_msg_recv_wait(int fd, struct tracecmd_msg *msg)
 
 	pfd.fd = fd;
 	pfd.events = POLLIN;
-	ret = poll(&pfd, 1, debug ? -1 : msg_wait_to);
+	ret = poll(&pfd, 1, tracecmd_get_debug() ? -1 : msg_wait_to);
 	if (ret < 0)
 		return -errno;
 	else if (ret == 0)
diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 26b9a18..b5ce84f 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -29,6 +29,7 @@
 int tracecmd_disable_sys_plugins;
 int tracecmd_disable_plugins;
 static int tracecmd_quiet;
+static bool tracecmd_debug;
 
 static struct registered_plugin_options {
 	struct registered_plugin_options	*next;
@@ -117,6 +118,26 @@ int tracecmd_get_quiet(void)
 	return tracecmd_quiet;
 }
 
+/**
+ * tracecmd_set_quiet - Set if to print output to the screen
+ * @quiet: If non zero, print no output to the screen
+ *
+ */
+void tracecmd_set_debug(bool debug)
+{
+	tracecmd_debug = debug;
+}
+
+/**
+ * tracecmd_get_quiet - Get if to print output to the screen
+ * Returns non zero, if no output to the screen should be printed
+ *
+ */
+bool tracecmd_get_debug(void)
+{
+	return tracecmd_debug;
+}
+
 void trace_util_free_plugin_options_list(char **list)
 {
 	tracecmd_free_list(list);
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 8fbafa6..1dc2383 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -12,8 +12,6 @@
 #include "trace-cmd.h"
 #include "event-utils.h"
 
-extern int debug;
-
 /* fix stupid glib guint64 typecasts and printf formats */
 typedef unsigned long long u64;
 
diff --git a/tracecmd/trace-cmd.c b/tracecmd/trace-cmd.c
index 5283ba7..30691b6 100644
--- a/tracecmd/trace-cmd.c
+++ b/tracecmd/trace-cmd.c
@@ -16,8 +16,6 @@
 int silence_warnings;
 int show_status;
 
-int debug;
-
 void warning(const char *fmt, ...)
 {
 	va_list ap;
diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 00c6073..832540e 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -427,7 +427,7 @@ void trace_list(int argc, char **argv)
 				break;
 			case '-':
 				if (strcmp(argv[i], "--debug") == 0) {
-					debug = true;
+					tracecmd_set_debug(true);
 					break;
 				}
 				fprintf(stderr, "list: invalid option -- '%s'\n",
diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c
index 9132582..9dcb833 100644
--- a/tracecmd/trace-listen.c
+++ b/tracecmd/trace-listen.c
@@ -717,7 +717,7 @@ static int do_fork(int cfd)
 	pid_t pid;
 
 	/* in debug mode, we do not fork off children */
-	if (debug)
+	if (tracecmd_get_debug())
 		return 0;
 
 	pid = fork();
@@ -769,7 +769,7 @@ static int do_connection(int cfd, struct sockaddr_storage *peer_addr,
 
 	tracecmd_msg_handle_close(msg_handle);
 
-	if (!debug)
+	if (!tracecmd_get_debug())
 		exit(0);
 
 	return 0;
@@ -910,7 +910,7 @@ static void do_listen(char *port)
 	struct addrinfo *result, *rp;
 	int sfd, s;
 
-	if (!debug)
+	if (!tracecmd_get_debug())
 		signal_setup(SIGCHLD, sigstub);
 
 	make_pid_file();
@@ -1009,7 +1009,7 @@ void trace_listen(int argc, char **argv)
 			daemon = 1;
 			break;
 		case OPT_debug:
-			debug = 1;
+			tracecmd_set_debug(true);
 			break;
 		default:
 			usage(argv);
diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index d22c723..12b8b3d 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -782,10 +782,10 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record)
 				 cpu, record->missed_events);
 	else if (record->missed_events < 0)
 		trace_seq_printf(&s, "CPU:%d [EVENTS DROPPED]\n", cpu);
-	if (buffer_breaks || debug) {
+	if (buffer_breaks || tracecmd_get_debug()) {
 		if (tracecmd_record_at_buffer_start(handle, record)) {
 			trace_seq_printf(&s, "CPU:%d [SUBBUFFER START]", cpu);
-			if (debug)
+			if (tracecmd_get_debug())
 				trace_seq_printf(&s, " [%lld:0x%llx]",
 						 tracecmd_page_ts(handle, record),
 						 record->offset & ~(page_size - 1));
@@ -816,7 +816,7 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record)
 		tep_print_event(pevent, &s, record, use_trace_clock);
 	if (s.len && *(s.buffer + s.len - 1) == '\n')
 		s.len--;
-	if (debug) {
+	if (tracecmd_get_debug()) {
 		struct kbuffer *kbuf;
 		struct kbuffer_raw_info info;
 		void *page;
@@ -1616,7 +1616,7 @@ void trace_report (int argc, char **argv)
 			break;
 		case OPT_debug:
 			buffer_breaks = 1;
-			debug = 1;
+			tracecmd_set_debug(true);
 			break;
 		case OPT_profile:
 			profile = 1;
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index e647117..8e2c83a 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4902,7 +4902,7 @@ static void parse_record_options(int argc,
 			no_filter = true;
 			break;
 		case OPT_debug:
-			debug = 1;
+			tracecmd_set_debug(true);
 			break;
 		case OPT_module:
 			if (ctx->instance->filter_mod)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/7] trace-cmd: Move plog() function to libtracecmd.
  2019-07-11 13:03 [PATCH 0/7] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
                   ` (3 preceding siblings ...)
  2019-07-11 13:03 ` [PATCH 4/7] trace-cmd: Move trace-cmd global variable "debug" " Tzvetomir Stoyanov (VMware)
@ 2019-07-11 13:03 ` Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 6/7] trace-cmd: Move trace-cmd APIs from trace-cmd.h to trace-local.h Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 7/7] trace-cmd: Move tracecmd_stack_tracer_status() function to libtracecmd Tzvetomir Stoyanov (VMware)
  6 siblings, 0 replies; 12+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2019-07-11 13:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

plog() function writes logs into a log file. It is used in
libtracecmd and its implementation should be there.
The function is moved from trace-cmd into the library, and 2
additional APIs are implemented:
	int trace_set_log_file(char *logfile); - use it to set
the log file.
	void plog_error(const char *fmt, ...); - use it to log
an error message into the file.

The plog() function is used also from pdie() in trace-cmd.
pdie() depends on trace-cmd context and cannot be moved to
the library. It is reimplemented as macros, in order to utilize
the new plog() library function.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/trace-cmd/trace-cmd.h |  4 ++
 include/trace-cmd/trace-msg.h |  3 --
 lib/trace-cmd/trace-util.c    | 71 +++++++++++++++++++++++++++++++++++
 tracecmd/trace-listen.c       | 69 ++++------------------------------
 4 files changed, 83 insertions(+), 64 deletions(-)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index 2f524b6..5cfb028 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -388,6 +388,10 @@ struct hook_list {
 struct hook_list *tracecmd_create_event_hook(const char *arg);
 void tracecmd_free_hooks(struct hook_list *hooks);
 
+void plog(const char *fmt, ...);
+void plog_error(const char *fmt, ...);
+int trace_set_log_file(char *logfile);
+
 /* --- Hack! --- */
 int tracecmd_blk_hack(struct tracecmd_input *handle);
 
diff --git a/include/trace-cmd/trace-msg.h b/include/trace-cmd/trace-msg.h
index b7fe10b..aab8a69 100644
--- a/include/trace-cmd/trace-msg.h
+++ b/include/trace-cmd/trace-msg.h
@@ -12,7 +12,4 @@
 
 extern unsigned int page_size;
 
-void plog(const char *fmt, ...);
-void pdie(const char *fmt, ...);
-
 #endif /* _TRACE_MSG_H_ */
diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index b5ce84f..8c1a0a0 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -31,6 +31,8 @@ int tracecmd_disable_plugins;
 static int tracecmd_quiet;
 static bool tracecmd_debug;
 
+static FILE *trace_logfp;
+
 static struct registered_plugin_options {
 	struct registered_plugin_options	*next;
 	struct tep_plugin_option			*options;
@@ -1716,3 +1718,72 @@ void __weak *malloc_or_die(unsigned int size)
 		die("malloc");
 	return data;
 }
+
+#define LOG_BUF_SIZE 1024
+static void __plog(const char *prefix, const char *fmt, va_list ap, FILE *fp)
+{
+	static int newline = 1;
+	char buf[LOG_BUF_SIZE];
+	int r;
+
+	r = vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
+
+	if (r > LOG_BUF_SIZE)
+		r = LOG_BUF_SIZE;
+
+	if (trace_logfp) {
+		if (newline)
+			fprintf(trace_logfp, "[%d]%s%.*s", getpid(), prefix, r, buf);
+		else
+			fprintf(trace_logfp, "[%d]%s%.*s", getpid(), prefix, r, buf);
+		newline = buf[r - 1] == '\n';
+		fflush(trace_logfp);
+		return;
+	}
+
+	fprintf(fp, "%.*s", r, buf);
+}
+
+void plog(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	__plog("", fmt, ap, stdout);
+	va_end(ap);
+	/* Make sure it gets to the screen, in case we crash afterward */
+	fflush(stdout);
+}
+
+void plog_error(const char *fmt, ...)
+{
+	va_list ap;
+	char *str = "";
+
+	va_start(ap, fmt);
+	__plog("Error: ", fmt, ap, stderr);
+	va_end(ap);
+	if (errno)
+		str = strerror(errno);
+	if (trace_logfp)
+		fprintf(trace_logfp, "\n%s\n", str);
+	else
+		fprintf(stderr, "\n%s\n", str);
+}
+
+/**
+ * trace_set_log_file - Set file for logging
+ * @logfile: Name of the log file
+ *
+ * Returns 0 on successful completion or -1 in case of error
+ */
+int trace_set_log_file(char *logfile)
+{
+	if (trace_logfp)
+		fclose(trace_logfp);
+	trace_logfp = fopen(logfile, "w");
+	if (!trace_logfp)
+		return -1;
+	return 0;
+}
+
diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c
index 9dcb833..7c7d4ce 100644
--- a/tracecmd/trace-listen.c
+++ b/tracecmd/trace-listen.c
@@ -34,8 +34,6 @@ static char *output_dir;
 static char *default_output_file = "trace";
 static char *output_file;
 
-static FILE *logfp;
-
 static int backlog = 5;
 
 static int do_daemon;
@@ -44,6 +42,13 @@ static int do_daemon;
 static struct tracecmd_msg_handle *stop_msg_handle;
 static bool done;
 
+#define pdie(fmt, ...)				\
+	do {					\
+		plog_error(fmt, ##__VA_ARGS__);	\
+		remove_pid_file();		\
+		exit(-1);			\
+	} while (0)
+
 #define  TEMP_FILE_STR "%s.%s:%s.cpu%d", output_file, host, port, cpu
 static char *get_temp_file(const char *host, const char *port, int cpu)
 {
@@ -114,43 +119,6 @@ static void finish(int sig)
 	done = true;
 }
 
-#define LOG_BUF_SIZE 1024
-static void __plog(const char *prefix, const char *fmt, va_list ap,
-		   FILE *fp)
-{
-	static int newline = 1;
-	char buf[LOG_BUF_SIZE];
-	int r;
-
-	r = vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
-
-	if (r > LOG_BUF_SIZE)
-		r = LOG_BUF_SIZE;
-
-	if (logfp) {
-		if (newline)
-			fprintf(logfp, "[%d]%s%.*s", getpid(), prefix, r, buf);
-		else
-			fprintf(logfp, "[%d]%s%.*s", getpid(), prefix, r, buf);
-		newline = buf[r - 1] == '\n';
-		fflush(logfp);
-		return;
-	}
-
-	fprintf(fp, "%.*s", r, buf);
-}
-
-void plog(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	__plog("", fmt, ap, stdout);
-	va_end(ap);
-	/* Make sure it gets to the screen, in case we crash afterward */
-	fflush(stdout);
-}
-
 static void make_pid_name(int mode, char *buf)
 {
 	snprintf(buf, PATH_MAX, VAR_RUN_DIR "/trace-cmd-net.pid");
@@ -169,26 +137,6 @@ static void remove_pid_file(void)
 	unlink(buf);
 }
 
-void pdie(const char *fmt, ...)
-{
-	va_list ap;
-	char *str = "";
-
-	va_start(ap, fmt);
-	__plog("Error: ", fmt, ap, stderr);
-	va_end(ap);
-	if (errno)
-		str = strerror(errno);
-	if (logfp)
-		fprintf(logfp, "\n%s\n", str);
-	else
-		fprintf(stderr, "\n%s\n", str);
-
-	remove_pid_file();
-
-	exit(-1);
-}
-
 static int process_udp_child(int sfd, const char *host, const char *port,
 			     int cpu, int page_size, int use_tcp)
 {
@@ -1030,8 +978,7 @@ void trace_listen(int argc, char **argv)
 
 	if (logfile) {
 		/* set the writes to a logfile instead */
-		logfp = fopen(logfile, "w");
-		if (!logfp)
+		if (trace_set_log_file(logfile) < 0)
 			die("creating log file %s", logfile);
 	}
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/7] trace-cmd: Move trace-cmd APIs from trace-cmd.h to trace-local.h
  2019-07-11 13:03 [PATCH 0/7] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
                   ` (4 preceding siblings ...)
  2019-07-11 13:03 ` [PATCH 5/7] trace-cmd: Move plog() function " Tzvetomir Stoyanov (VMware)
@ 2019-07-11 13:03 ` Tzvetomir Stoyanov (VMware)
  2019-07-11 13:03 ` [PATCH 7/7] trace-cmd: Move tracecmd_stack_tracer_status() function to libtracecmd Tzvetomir Stoyanov (VMware)
  6 siblings, 0 replies; 12+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2019-07-11 13:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

These APIs depend on trace-cmd context and cannot be used standalone:
	tracecmd_create_top_instance()
	tracecmd_remove_instances()
	tracecmd_filter_pid()
	tracecmd_add_event()
	tracecmd_enable_events()
	tracecmd_disable_all_tracing()
	tracecmd_disable_tracing()
	tracecmd_enable_tracing()
	tracecmd_stat_cpu()
They are implemented in trace-cmd application, but declared as APIs in
trace-cmd.h. The declarations are moved from trace-cmd.h to trace-local.h,
local header file visible only to trace-cmd application.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/trace-cmd/trace-cmd.h  |  9 ---------
 tracecmd/include/trace-local.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index 5cfb028..409a6ab 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -130,8 +130,6 @@ int tracecmd_buffer_instances(struct tracecmd_input *handle);
 const char *tracecmd_buffer_instance_name(struct tracecmd_input *handle, int indx);
 struct tracecmd_input *tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx);
 int tracecmd_is_buffer_instance(struct tracecmd_input *handle);
-void tracecmd_create_top_instance(char *name);
-void tracecmd_remove_instances(void);
 
 void tracecmd_set_ts_offset(struct tracecmd_input *handle, unsigned long long offset);
 void tracecmd_set_ts2secs(struct tracecmd_input *handle, unsigned long long hz);
@@ -294,14 +292,7 @@ struct tracecmd_recorder *tracecmd_create_buffer_recorder_maxkb(const char *file
 
 int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep);
 void tracecmd_stop_recording(struct tracecmd_recorder *recorder);
-void tracecmd_stat_cpu(struct trace_seq *s, int cpu);
 long tracecmd_flush_recording(struct tracecmd_recorder *recorder);
-void tracecmd_filter_pid(int pid, int exclude);
-int tracecmd_add_event(const char *event_str, int stack);
-void tracecmd_enable_events(void);
-void tracecmd_disable_all_tracing(int disable_tracer);
-void tracecmd_disable_tracing(void);
-void tracecmd_enable_tracing(void);
 
 enum tracecmd_msg_flags {
 	TRACECMD_MSG_FL_USE_TCP		= 1 << 0,
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 1dc2383..38dfdee 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -206,6 +206,17 @@ void show_instance_file(struct buffer_instance *instance, const char *name);
 
 int count_cpus(void);
 
+/* moved from trace-cmd.h */
+void tracecmd_create_top_instance(char *name);
+void tracecmd_remove_instances(void);
+void tracecmd_filter_pid(int pid, int exclude);
+int tracecmd_add_event(const char *event_str, int stack);
+void tracecmd_enable_events(void);
+void tracecmd_disable_all_tracing(int disable_tracer);
+void tracecmd_disable_tracing(void);
+void tracecmd_enable_tracing(void);
+void tracecmd_stat_cpu(struct trace_seq *s, int cpu);
+
 /* No longer in event-utils.h */
 void __noreturn die(const char *fmt, ...); /* Can be overriden */
 void *malloc_or_die(unsigned int size); /* Can be overridden */
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/7] trace-cmd: Move tracecmd_stack_tracer_status() function to libtracecmd
  2019-07-11 13:03 [PATCH 0/7] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
                   ` (5 preceding siblings ...)
  2019-07-11 13:03 ` [PATCH 6/7] trace-cmd: Move trace-cmd APIs from trace-cmd.h to trace-local.h Tzvetomir Stoyanov (VMware)
@ 2019-07-11 13:03 ` Tzvetomir Stoyanov (VMware)
  6 siblings, 0 replies; 12+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2019-07-11 13:03 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

tracecmd_stack_tracer_status() function reads the stack tracer status
from the proc file system. It does not depend on trace-cmd context and
can be used standalone. The function is moved from trace-cmd application
into libtracecmd.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 lib/trace-cmd/trace-util.c | 49 +++++++++++++++++++++++++++++++++
 tracecmd/trace-stack.c     | 56 ++------------------------------------
 2 files changed, 51 insertions(+), 54 deletions(-)

diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c
index 8c1a0a0..d16a018 100644
--- a/lib/trace-cmd/trace-util.c
+++ b/lib/trace-cmd/trace-util.c
@@ -25,6 +25,7 @@
 #define LOCAL_PLUGIN_DIR ".trace-cmd/plugins"
 #define TRACEFS_PATH "/sys/kernel/tracing"
 #define DEBUGFS_PATH "/sys/kernel/debug"
+#define PROC_STACK_FILE "/proc/sys/kernel/stack_tracer_enabled"
 
 int tracecmd_disable_sys_plugins;
 int tracecmd_disable_plugins;
@@ -1787,3 +1788,51 @@ int trace_set_log_file(char *logfile)
 	return 0;
 }
 
+/**
+ * tracecmd_stack_tracer_status - Check stack trace status
+ * @status: Returned stack trace status:
+ *		0 - not configured, disabled
+ *		non 0 - enabled
+ *
+ * Returns -1 in case of an error, 0 if file does not exist
+ *  (stack tracer not enabled) or 1 on successful completion.
+ */
+int tracecmd_stack_tracer_status(int *status)
+{
+	struct stat stat_buf;
+	char buf[64];
+	long num;
+	int fd;
+	int n;
+
+	if (stat(PROC_STACK_FILE, &stat_buf) < 0) {
+		/* stack tracer not configured on running kernel */
+		*status = 0; /* not configured means disabled */
+		return 0;
+	}
+
+	fd = open(PROC_STACK_FILE, O_RDONLY);
+
+	if (fd < 0)
+		return -1;
+
+	n = read(fd, buf, sizeof(buf));
+	close(fd);
+
+	if (n <= 0)
+		return -1;
+
+	if (n >= sizeof(buf))
+		return -1;
+
+	buf[n] = 0;
+	errno = 0;
+	num = strtol(buf, NULL, 10);
+
+	/* Check for various possible errors */
+	if (num > INT_MAX || num < INT_MIN || (!num && errno))
+		return -1;
+
+	*status = num;
+	return 1; /* full success */
+}
diff --git a/tracecmd/trace-stack.c b/tracecmd/trace-stack.c
index 34b3b58..bb002c0 100644
--- a/tracecmd/trace-stack.c
+++ b/tracecmd/trace-stack.c
@@ -36,58 +36,6 @@ static void test_available(void)
 		die("stack tracer not configured on running kernel");
 }
 
-/*
- * Returns:
- *   -1 - Something went wrong
- *    0 - File does not exist (stack tracer not enabled)
- *    1 - Success
- */
-static int read_proc(int *status)
-{
-	struct stat stat_buf;
-	char buf[64];
-	long num;
-	int fd;
-	int n;
-
-	if (stat(PROC_FILE, &stat_buf) < 0) {
-		/* stack tracer not configured on running kernel */
-		*status = 0; /* not configured means disabled */
-		return 0;
-	}
-
-	fd = open(PROC_FILE, O_RDONLY);
-
-	if (fd < 0)
-		return -1;
-
-	n = read(fd, buf, sizeof(buf));
-	close(fd);
-
-	if (n <= 0)
-		return -1;
-
-	if (n >= sizeof(buf))
-		return -1;
-
-	buf[n] = 0;
-	errno = 0;
-	num = strtol(buf, NULL, 10);
-
-	/* Check for various possible errors */
-	if (num > INT_MAX || num < INT_MIN || (!num && errno))
-		return -1;
-
-	*status = num;
-	return 1; /* full success */
-}
-
-/* Public wrapper of read_proc() */
-int tracecmd_stack_tracer_status(int *status)
-{
-	return read_proc(status);
-}
-
 /* NOTE: this implementation only accepts new_status in the range [0..9]. */
 static void change_stack_tracer_status(unsigned new_status)
 {
@@ -102,7 +50,7 @@ static void change_stack_tracer_status(unsigned new_status)
 		return;
 	}
 
-	ret = read_proc(&status);
+	ret = tracecmd_stack_tracer_status(&status);
 	if (ret < 0)
 		die("error reading %s", PROC_FILE);
 
@@ -160,7 +108,7 @@ static void read_trace(void)
 	size_t n;
 	int r;
 
-	if (read_proc(&status) <= 0)
+	if (tracecmd_stack_tracer_status(&status) <= 0)
 		die("Invalid stack tracer state");
 
 	if (status > 0)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] trace-cmd: Move trace-output.c into the library code
  2019-07-11 13:03 ` [PATCH 1/7] trace-cmd: Move trace-output.c into the library code Tzvetomir Stoyanov (VMware)
@ 2019-08-08 23:37   ` Steven Rostedt
  2019-08-09 13:22     ` Tzvetomir Stoyanov
  0 siblings, 1 reply; 12+ messages in thread
From: Steven Rostedt @ 2019-08-08 23:37 UTC (permalink / raw)
  To: Tzvetomir Stoyanov (VMware); +Cc: linux-trace-devel

On Thu, 11 Jul 2019 16:03:01 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> Functions, implemented in trace-output.c file, do not depend on
> trace-cmd application context and can be used standalone. The file
> is moved from trace-cmd to libtracecmd. It also fixes a warning
> while loading python modules from kernelshark:
> ImportError: ctracecmd.so: undefined symbol: tracecmd_append_cpu_data
> 
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> ---
>  lib/trace-cmd/Makefile                     | 11 ++++++++++-
>  {tracecmd => lib/trace-cmd}/trace-output.c |  0
>  tracecmd/Makefile                          |  1 -
>  3 files changed, 10 insertions(+), 2 deletions(-)
>  rename {tracecmd => lib/trace-cmd}/trace-output.c (100%)
> 
> diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile
> index 44c1332..9086eb6 100644
> --- a/lib/trace-cmd/Makefile
> +++ b/lib/trace-cmd/Makefile
> @@ -4,12 +4,15 @@ include $(src)/scripts/utils.mk
>  
>  bdir:=$(obj)/lib/trace-cmd
>  
> -DEFAULT_TARGET = $(bdir)/libtracecmd.a
> +TC_VERSION := $(bdir)/include/tc_version.h
> +
> +DEFAULT_TARGET = $(bdir)/libtracecmd.a $(TC_VERSION)
>  
>  OBJS =
>  OBJS += trace-hash.o
>  OBJS += trace-hooks.o
>  OBJS += trace-input.o
> +OBJS += trace-output.o
>  OBJS += trace-recorder.o
>  OBJS += trace-util.o
>  OBJS += trace-filter-hash.o
> @@ -29,6 +32,9 @@ $(bdir):
>  $(OBJS): | $(bdir)
>  $(DEPS): | $(bdir)
>  
> +$(TC_VERSION): force | $(bdir)/include
> +	$(Q)$(call update_version.h)
> +

Hi Ceco,

Why the addition of TC_VERISON here? It's not stated in the change log
to why this was copied over. I ever removed all references from
TC_VERSION and it still builds fine.

-- Steve


>  $(bdir)/libtracecmd.a: $(OBJS)
>  	$(Q)$(call do_build_static_lib)
>  
> @@ -43,6 +49,8 @@ $(bdir)/trace-util.o: $(obj)/plugins/trace_plugin_dir
>  $(DEPS): $(bdir)/.%.d: %.c
>  	$(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@
>  
> +$(DEPS): $(TC_VERSION)
> +
>  $(OBJS): $(bdir)/%.o : $(bdir)/.%.d
>  
>  dep_includes := $(wildcard $(DEPS))
> @@ -54,4 +62,5 @@ endif
>  clean:
>  	$(RM) $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d
>  
> +force:
>  .PHONY: clean
> diff --git a/tracecmd/trace-output.c b/lib/trace-cmd/trace-output.c
> similarity index 100%
> rename from tracecmd/trace-output.c
> rename to lib/trace-cmd/trace-output.c
> diff --git a/tracecmd/Makefile b/tracecmd/Makefile
> index bcd437a..6968f83 100644
> --- a/tracecmd/Makefile
> +++ b/tracecmd/Makefile
> @@ -29,7 +29,6 @@ TRACE_CMD_OBJS += trace-restore.o
>  TRACE_CMD_OBJS += trace-check-events.o
>  TRACE_CMD_OBJS += trace-show.o
>  TRACE_CMD_OBJS += trace-list.o
> -TRACE_CMD_OBJS += trace-output.o
>  TRACE_CMD_OBJS += trace-usage.o
>  TRACE_CMD_OBJS += trace-msg.o
>  


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] trace-cmd: Move trace-output.c into the library code
  2019-08-08 23:37   ` Steven Rostedt
@ 2019-08-09 13:22     ` Tzvetomir Stoyanov
  2019-08-09 13:59       ` Steven Rostedt
  0 siblings, 1 reply; 12+ messages in thread
From: Tzvetomir Stoyanov @ 2019-08-09 13:22 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Tzvetomir Stoyanov (VMware), Linux Trace Devel

On Fri, Aug 9, 2019 at 2:37 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Thu, 11 Jul 2019 16:03:01 +0300
> "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:
>
> > Functions, implemented in trace-output.c file, do not depend on
> > trace-cmd application context and can be used standalone. The file
> > is moved from trace-cmd to libtracecmd. It also fixes a warning
> > while loading python modules from kernelshark:
> > ImportError: ctracecmd.so: undefined symbol: tracecmd_append_cpu_data
> >
> > Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> > ---
> >  lib/trace-cmd/Makefile                     | 11 ++++++++++-
> >  {tracecmd => lib/trace-cmd}/trace-output.c |  0
> >  tracecmd/Makefile                          |  1 -
> >  3 files changed, 10 insertions(+), 2 deletions(-)
> >  rename {tracecmd => lib/trace-cmd}/trace-output.c (100%)
> >
> > diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile
> > index 44c1332..9086eb6 100644
> > --- a/lib/trace-cmd/Makefile
> > +++ b/lib/trace-cmd/Makefile
> > @@ -4,12 +4,15 @@ include $(src)/scripts/utils.mk
> >
> >  bdir:=$(obj)/lib/trace-cmd
> >
> > -DEFAULT_TARGET = $(bdir)/libtracecmd.a
> > +TC_VERSION := $(bdir)/include/tc_version.h
> > +
> > +DEFAULT_TARGET = $(bdir)/libtracecmd.a $(TC_VERSION)
> >
> >  OBJS =
> >  OBJS += trace-hash.o
> >  OBJS += trace-hooks.o
> >  OBJS += trace-input.o
> > +OBJS += trace-output.o
> >  OBJS += trace-recorder.o
> >  OBJS += trace-util.o
> >  OBJS += trace-filter-hash.o
> > @@ -29,6 +32,9 @@ $(bdir):
> >  $(OBJS): | $(bdir)
> >  $(DEPS): | $(bdir)
> >
> > +$(TC_VERSION): force | $(bdir)/include
> > +     $(Q)$(call update_version.h)
> > +
>
> Hi Ceco,
>
> Why the addition of TC_VERISON here? It's not stated in the change log
> to why this was copied over. I ever removed all references from
> TC_VERSION and it still builds fine.
>
> -- Steve
>
There is a dependency: trace-output.c includes version.h, which
includes tc_version.h.
When trace-output.c is moved to the lib/trace-cmd directory, it
includes tc_version.h from
lib/trace-cmd/include. It makes sense, otherwise the libtracecmd will
depend on the trace-cmd
application. That's why I duplicated that TC_VERISON logic in
lib/trace-cmd/Makefile. It
forces lib/trace-cmd/include/tc_version.h to be generated on every
libtracecmd build.
Now we have two auto generated files:
    lib/trace-cmd/include/tc_version.h
    tracecmd/include/tc_version.h

May be we should move tc_version.h to be generated in include/, so we
can use the same file from
both the application and the library ?

>
> >  $(bdir)/libtracecmd.a: $(OBJS)
> >       $(Q)$(call do_build_static_lib)
> >
> > @@ -43,6 +49,8 @@ $(bdir)/trace-util.o: $(obj)/plugins/trace_plugin_dir
> >  $(DEPS): $(bdir)/.%.d: %.c
> >       $(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@
> >
> > +$(DEPS): $(TC_VERSION)
> > +
> >  $(OBJS): $(bdir)/%.o : $(bdir)/.%.d
> >
> >  dep_includes := $(wildcard $(DEPS))
> > @@ -54,4 +62,5 @@ endif
> >  clean:
> >       $(RM) $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d
> >
> > +force:
> >  .PHONY: clean
> > diff --git a/tracecmd/trace-output.c b/lib/trace-cmd/trace-output.c
> > similarity index 100%
> > rename from tracecmd/trace-output.c
> > rename to lib/trace-cmd/trace-output.c
> > diff --git a/tracecmd/Makefile b/tracecmd/Makefile
> > index bcd437a..6968f83 100644
> > --- a/tracecmd/Makefile
> > +++ b/tracecmd/Makefile
> > @@ -29,7 +29,6 @@ TRACE_CMD_OBJS += trace-restore.o
> >  TRACE_CMD_OBJS += trace-check-events.o
> >  TRACE_CMD_OBJS += trace-show.o
> >  TRACE_CMD_OBJS += trace-list.o
> > -TRACE_CMD_OBJS += trace-output.o
> >  TRACE_CMD_OBJS += trace-usage.o
> >  TRACE_CMD_OBJS += trace-msg.o
> >
>


-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] trace-cmd: Move trace-output.c into the library code
  2019-08-09 13:22     ` Tzvetomir Stoyanov
@ 2019-08-09 13:59       ` Steven Rostedt
  2019-08-09 15:02         ` Steven Rostedt
  0 siblings, 1 reply; 12+ messages in thread
From: Steven Rostedt @ 2019-08-09 13:59 UTC (permalink / raw)
  To: Tzvetomir Stoyanov; +Cc: Tzvetomir Stoyanov (VMware), Linux Trace Devel

On Fri, 9 Aug 2019 13:22:29 +0000
Tzvetomir Stoyanov <tstoyanov@vmware.com> wrote:

> > > +$(TC_VERSION): force | $(bdir)/include
> > > +     $(Q)$(call update_version.h)
> > > +  
> >
> > Hi Ceco,
> >
> > Why the addition of TC_VERISON here? It's not stated in the change log
> > to why this was copied over. I ever removed all references from
> > TC_VERSION and it still builds fine.
> >
> > -- Steve
> >  
> There is a dependency: trace-output.c includes version.h, which
> includes tc_version.h.
> When trace-output.c is moved to the lib/trace-cmd directory, it
> includes tc_version.h from
> lib/trace-cmd/include. It makes sense, otherwise the libtracecmd will
> depend on the trace-cmd
> application. That's why I duplicated that TC_VERISON logic in
> lib/trace-cmd/Makefile. It
> forces lib/trace-cmd/include/tc_version.h to be generated on every
> libtracecmd build.

Yeah, we can't have that.

> Now we have two auto generated files:
>     lib/trace-cmd/include/tc_version.h
>     tracecmd/include/tc_version.h
> 
> May be we should move tc_version.h to be generated in include/, so we
> can use the same file from
> both the application and the library ?

I looked at why we have version.h there, and it's to get
FILE_VERSION_STRING, which is only used in trace-output.c.

And this is created via the Makefile. Hmm, we may need to move all the
file version logic into lib/trace-event as the only files that should
ever care about this is trace-output.c and trace-input.c, which are
both in the lib/trace-event (not something trace-cmd should worry
about).

-- Steve


> 
> >  
> > >  $(bdir)/libtracecmd.a: $(OBJS)
> > >       $(Q)$(call do_build_static_lib)
> > >
> > > @@ -43,6 +49,8 @@ $(bdir)/trace-util.o: $(obj)/plugins/trace_plugin_dir
> > >  $(DEPS): $(bdir)/.%.d: %.c
> > >       $(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@
> > >
> > > +$(DEPS): $(TC_VERSION)
> > > +
> > >  $(OBJS): $(bdir)/%.o : $(bdir)/.%.d
> > >
> > >  dep_includes := $(wildcard $(DEPS))
> > > @@ -54,4 +62,5 @@ endif
> > >  clean:
> > >       $(RM) $(bdir)/*.a $(bdir)/*.so $(bdir)/*.o $(bdir)/.*.d
> > >
> > > +force:
> > >  .PHONY: clean
> > > diff --git a/tracecmd/trace-output.c b/lib/trace-cmd/trace-output.c
> > > similarity index 100%
> > > rename from tracecmd/trace-output.c
> > > rename to lib/trace-cmd/trace-output.c
> > > diff --git a/tracecmd/Makefile b/tracecmd/Makefile
> > > index bcd437a..6968f83 100644
> > > --- a/tracecmd/Makefile
> > > +++ b/tracecmd/Makefile
> > > @@ -29,7 +29,6 @@ TRACE_CMD_OBJS += trace-restore.o
> > >  TRACE_CMD_OBJS += trace-check-events.o
> > >  TRACE_CMD_OBJS += trace-show.o
> > >  TRACE_CMD_OBJS += trace-list.o
> > > -TRACE_CMD_OBJS += trace-output.o
> > >  TRACE_CMD_OBJS += trace-usage.o
> > >  TRACE_CMD_OBJS += trace-msg.o
> > >  
> >  
> 
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/7] trace-cmd: Move trace-output.c into the library code
  2019-08-09 13:59       ` Steven Rostedt
@ 2019-08-09 15:02         ` Steven Rostedt
  0 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2019-08-09 15:02 UTC (permalink / raw)
  To: Tzvetomir Stoyanov; +Cc: Tzvetomir Stoyanov (VMware), Linux Trace Devel

On Fri, 9 Aug 2019 09:59:07 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> And this is created via the Makefile. Hmm, we may need to move all the
> file version logic into lib/trace-event as the only files that should

 sorry, that should have said lib/trace-cmd/

-- Steve

> ever care about this is trace-output.c and trace-input.c, which are
> both in the lib/trace-event (not something trace-cmd should worry
> about).
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-08-09 15:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-11 13:03 [PATCH 0/7] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
2019-07-11 13:03 ` [PATCH 1/7] trace-cmd: Move trace-output.c into the library code Tzvetomir Stoyanov (VMware)
2019-08-08 23:37   ` Steven Rostedt
2019-08-09 13:22     ` Tzvetomir Stoyanov
2019-08-09 13:59       ` Steven Rostedt
2019-08-09 15:02         ` Steven Rostedt
2019-07-11 13:03 ` [PATCH 2/7] trace-cmd: Move trace-msg.c into the library Tzvetomir Stoyanov (VMware)
2019-07-11 13:03 ` [PATCH 3/7] trace-cmd: Move trace-cmd global variable "quiet" to libtracecmd Tzvetomir Stoyanov (VMware)
2019-07-11 13:03 ` [PATCH 4/7] trace-cmd: Move trace-cmd global variable "debug" " Tzvetomir Stoyanov (VMware)
2019-07-11 13:03 ` [PATCH 5/7] trace-cmd: Move plog() function " Tzvetomir Stoyanov (VMware)
2019-07-11 13:03 ` [PATCH 6/7] trace-cmd: Move trace-cmd APIs from trace-cmd.h to trace-local.h Tzvetomir Stoyanov (VMware)
2019-07-11 13:03 ` [PATCH 7/7] trace-cmd: Move tracecmd_stack_tracer_status() function to libtracecmd Tzvetomir Stoyanov (VMware)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).