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

Message ID 20190604121441.19305-1-kaslevs@vmware.com
State Superseded
Headers show
Series
  • trace-cmd: Append metadata about trace-cmd's version when recording
Related show

Commit Message

Slavomir Kaslev June 4, 2019, 12:14 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       | 17 ++++++++++++++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

Comments

Steven Rostedt June 4, 2019, 12:24 p.m. UTC | #1
On Tue,  4 Jun 2019 15:14:41 +0300
Slavomir Kaslev <kaslevs@vmware.com> wrote:

> 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.

Awesome! Some nits below...

> 
> 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       | 17 ++++++++++++++++-
>  3 files changed, 20 insertions(+), 1 deletion(-)
> 
> 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..4c4840b 100644
> --- a/tracecmd/trace-record.c
> +++ b/tracecmd/trace-record.c
> @@ -3145,6 +3145,21 @@ static void add_uname(struct tracecmd_output *handle)
>  	free(str);
>  }
>  
> +static void add_version(struct tracecmd_output *handle)
> +{
> +	char *str;
> +	int len;
> +
> +	len = strlen(TRACECMD_VERSION) + strlen(TRACECMD_VERSION_GIT) + 2;
> +	str = malloc(len);
> +	if (!str)
> +		return;
> +
> +	sprintf(str, "%s %s", TRACECMD_VERSION, TRACECMD_VERSION_GIT);

The above should use asprintf():

	ret = asprintf(&str, "%s %s", TRACECMD_VERSION, TRACE_cMD_VERSION_GIT);
	if (ret < 0)
		return;

But other than that, looks good!

-- Steve

> +	tracecmd_add_option(handle, TRACECMD_OPTION_VERSION, len, str);
> +	free(str);
> +}
> +
>  static void print_stat(struct buffer_instance *instance)
>  {
>  	int cpu;
> @@ -3182,7 +3197,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)

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..4c4840b 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3145,6 +3145,21 @@  static void add_uname(struct tracecmd_output *handle)
 	free(str);
 }
 
+static void add_version(struct tracecmd_output *handle)
+{
+	char *str;
+	int len;
+
+	len = strlen(TRACECMD_VERSION) + strlen(TRACECMD_VERSION_GIT) + 2;
+	str = malloc(len);
+	if (!str)
+		return;
+
+	sprintf(str, "%s %s", TRACECMD_VERSION, TRACECMD_VERSION_GIT);
+	tracecmd_add_option(handle, TRACECMD_OPTION_VERSION, len, str);
+	free(str);
+}
+
 static void print_stat(struct buffer_instance *instance)
 {
 	int cpu;
@@ -3182,7 +3197,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)