trace-cmd: Append metadata about trace-cmd's version when recording
diff mbox series

Message ID 20190604124826.6716-1-kaslevs@vmware.com
State Accepted
Commit 8e35e58b2cba0d7eb5c1df89f9bd80cc98585585
Headers show
Series
  • trace-cmd: Append metadata about trace-cmd's version when recording
Related show

Commit Message

Slavomir Kaslev June 4, 2019, 12:48 p.m. UTC
Add metadata when recording to the output trace about trace-cmd's version and
git commit. When debugging this can be useful to know which version of trace-cmd
recorded this trace.dat file.

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=203547
Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com>
---
 Makefile                      |  3 +++
 include/trace-cmd/trace-cmd.h |  1 +
 tracecmd/trace-record.c       | 15 ++++++++++++++-
 3 files changed, 18 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/Makefile b/Makefile
index cde45f8..2062d97 100644
--- a/Makefile
+++ b/Makefile
@@ -238,6 +238,9 @@  endif
 override CFLAGS += $(INCLUDES) $(PLUGIN_DIR_SQ) $(VAR_DIR)
 override CFLAGS += $(udis86-flags) $(blk-flags)
 
+# Append version define
+override CFLAGS += -DTRACECMD_VERSION=\"$(TRACECMD_VERSION)\"
+override CFLAGS += -DTRACECMD_VERSION_GIT=\"$(shell git log -1 --pretty=format:"%H")\"
 
 CMD_TARGETS = trace-cmd $(BUILD_PYTHON)
 
diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index ceb03f4..ca9fc44 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -81,6 +81,7 @@  enum {
 	TRACECMD_OPTION_HOOK,
 	TRACECMD_OPTION_OFFSET,
 	TRACECMD_OPTION_CPUCOUNT,
+	TRACECMD_OPTION_VERSION,
 };
 
 enum {
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 4523128..c38d279 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3145,6 +3145,19 @@  static void add_uname(struct tracecmd_output *handle)
 	free(str);
 }
 
+static void add_version(struct tracecmd_output *handle)
+{
+	char *str;
+	int len;
+
+	len = asprintf(&str, "%s %s", TRACECMD_VERSION, TRACECMD_VERSION_GIT);
+	if (len < 0)
+		return;
+
+	tracecmd_add_option(handle, TRACECMD_OPTION_VERSION, len+1, str);
+	free(str);
+}
+
 static void print_stat(struct buffer_instance *instance)
 {
 	int cpu;
@@ -3182,7 +3195,7 @@  static void add_options(struct tracecmd_output *handle, struct common_record_con
 	tracecmd_add_option(handle, TRACECMD_OPTION_TRACECLOCK, 0, NULL);
 	add_option_hooks(handle);
 	add_uname(handle);
-
+	add_version(handle);
 }
 
 static void record_data(struct common_record_context *ctx)