@@ -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)
@@ -81,6 +81,7 @@ enum {
TRACECMD_OPTION_HOOK,
TRACECMD_OPTION_OFFSET,
TRACECMD_OPTION_CPUCOUNT,
+ TRACECMD_OPTION_VERSION,
};
enum {
@@ -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)
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(-)