trace-cmd: Append metadata about trace-cmd's version when recording
Subsystems (2)
PATCH 1/1 trace-cmd: Append metadata about trace-cmd's version when recording
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.
--- Makefile | 3 +++ include/trace-cmd/trace-cmd.h | 1 + tracecmd/trace-record.c | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-)
Makefile +3 -0
@@ -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)
include/trace-cmd/trace-cmd.h +1 -0
@@ -81,6 +81,7 @@ enum {TRACECMD_OPTION_HOOK ,TRACECMD_OPTION_OFFSET ,TRACECMD_OPTION_CPUCOUNT , + TRACECMD_OPTION_VERSION, }; enum {
tracecmd/trace-record.c +16 -1
@@ -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_contracecmd_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)
Signature · 1 line
2.20.1
Quoted 3 lines · On Tue, 4 Jun 2019 15:14:41 +0300 Slavomir Kaslev <[email protected]> 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...
Quoted 45 lines
Suggested-by Steven Rostedt (VMware) <[email protected]>Signed-off-by Slavomir Kaslev <[email protected]>--- Makefile | 3 +++ include/trace-cmd/trace-cmd.h | 1 + tracecmd/trace-record.c | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-)Makefile +3
-0@@ -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)include/trace-cmd/trace-cmd.h +1
-0@@ -81,6 +81,7 @@ enum {TRACECMD_OPTION_HOOK ,TRACECMD_OPTION_OFFSET ,TRACECMD_OPTION_CPUCOUNT , + TRACECMD_OPTION_VERSION, }; enum {tracecmd/trace-record.c +1
-0@@ -3145,6 +3145,21 @@ static void add_uname(struct tracecmd_output *handle)free (str); } +static void add_version (struct tracecmd_output *handle)
tracecmd/trace-record.c static void add_uname(struct tracecmd_output *handle) · line 3158
Quoted 10 lines
tracecmd/trace-record.c +10
-0+{ +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
Quoted 16 lines
tracecmd/trace-record.c +5
-1+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_contracecmd_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 1/1 trace-cmd: Append metadata about trace-cmd's version when recording
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.
--- Makefile | 3 +++ include/trace-cmd/trace-cmd.h | 1 + tracecmd/trace-record.c | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-)
Makefile +3 -0
@@ -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)
include/trace-cmd/trace-cmd.h +1 -0
@@ -81,6 +81,7 @@ enum {TRACECMD_OPTION_HOOK ,TRACECMD_OPTION_OFFSET ,TRACECMD_OPTION_CPUCOUNT , + TRACECMD_OPTION_VERSION, }; enum {
tracecmd/trace-record.c +14 -1
@@ -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_contracecmd_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)
Signature · 1 line
2.20.1
PATCH 1/1 trace-cmd: Add trace-cmd report --version to extract version info
From: "Steven Rostedt (VMware)" <[email protected]>
Now that the trace.dat file can save the version of the executable that was used to create it, save that information. This will be useful if a user has a problem with a trace.dat file. It can let the developers know what version was used to create it. We need a way to extract this information. Adding a new "--version" to trace-cmd report will display the saved version in the trace.dat file if it exists.
--- Documentation/trace-cmd-report.1.txt | 4 ++++ include/trace-cmd/trace-cmd.h | 1 + lib/trace-cmd/trace-input.c | 19 +++++++++++++++++++ tracecmd/trace-read.c | 12 ++++++++++++ tracecmd/trace-usage.c | 1 + 5 files changed, 37 insertions(+)
Documentation/trace-cmd-report.1.txt +4 -0
@@ -248,6 +248,10 @@ OPTIONS If the trace.dat file recorded uname during the run, this will retrieve that information. +*--version*:: + If the trace.dat file recorded the version of the executable used to create + it, report that version. + *--ts-offset* offset:: Add (or subtract if negative) an offset for all timestamps of the previous data file specified with *-i*. This is useful to merge sort multiple trace.dat
include/trace-cmd/trace-cmd.h +1 -0
@@ -138,6 +138,7 @@ int tracecmd_init_data(struct tracecmd_input *handle);void tracecmd_print_stats (struct tracecmd_input *handle);void tracecmd_print_uname (struct tracecmd_input *handle); +void tracecmd_print_version (struct tracecmd_input *handle);struct tep_record * tracecmd_read_page_record(struct tep_handle *pevent, void *page, int size,
lib/trace-cmd/trace-input.c +19 -0
@@ -94,6 +94,7 @@ struct tracecmd_input {double ts2secs;char * cpustats;char * uname; +char * version;struct input_buffer_instance *buffers;int parsing_failures;
@@ -2220,6 +2221,9 @@ static int handle_options(struct tracecmd_input *handle)case TRACECMD_OPTION_UNAME : handle->uname =strdup (buf);break ; +case TRACECMD_OPTION_VERSION : + handle->version =strdup (buf); +break ;case TRACECMD_OPTION_HOOK : hook =tracecmd_create_event_hook (buf); hook->next = handle->hooks;
@@ -2598,6 +2602,21 @@ void tracecmd_print_uname(struct tracecmd_input *handle)printf (" uname was not recorded in this file\n" ); } +/** +* tracecmd_print_uname - prints the recorded uname if it was recorded +* @handle: input handle for the trace.dat file +* +* Looks for the option TRACECMD_OPTION_VERSION and prints out what's +* stored there, if it is found. Otherwise it prints that none were found. +*/ +void tracecmd_print_version (struct tracecmd_input *handle) +{ +if (handle->version) +printf ("%s\n" , handle->version); +else +printf (" version was not recorded in this file\n" ); +} +/** * tracecmd_hooks - return the event hooks that were used in record * @handle: input handle for the trace.dat file
tracecmd/trace-read.c +12 -0
@@ -1112,6 +1112,7 @@ enum output_type {OUTPUT_NORMAL ,OUTPUT_STAT_ONLY ,OUTPUT_UNAME_ONLY , + OUTPUT_VERSION_ONLY, }; static void read_data_info(struct list_head *handle_list, enum output_type otype,
@@ -1160,6 +1161,8 @@ static void read_data_info(struct list_head *handle_list, enum output_type otypecontinue ;case OUTPUT_UNAME_ONLY :tracecmd_print_uname (handles->handle); +case OUTPUT_VERSION_ONLY : +tracecmd_print_version (handles->handle);continue ; }
@@ -1386,6 +1389,7 @@ static void add_hook(const char *arg) }enum { + OPT_version =238 , OPT_tsdiff =239 , OPT_ts2secs =240 , OPT_tsoffset =241 ,
@@ -1427,6 +1431,7 @@ void trace_report (int argc, char **argv)int show_page_size =0 ;int show_printk =0 ;int show_uname =0 ; +int show_version =0 ;int latency_format =0 ;int show_events =0 ;int print_events =0 ;
@@ -1468,6 +1473,7 @@ void trace_report (int argc, char **argv) {"debug", no_argument, NULL, OPT_debug}, {"profile", no_argument, NULL, OPT_profile}, {"uname", no_argument, NULL, OPT_uname}, + {"version", no_argument, NULL, OPT_version}, {"by-comm", no_argument, NULL, OPT_bycomm}, {"ts-offset", required_argument, NULL, OPT_tsoffset}, {"ts2secs", required_argument, NULL, OPT_ts2secs},
@@ -1618,6 +1624,9 @@ void trace_report (int argc, char **argv)case OPT_uname: show_uname =1 ;break ; +case OPT_version: + show_version =1 ; +break ;case OPT_bycomm:trace_profile_set_merge_like_comms ();break ;
@@ -1767,6 +1776,9 @@ void trace_report (int argc, char **argv)/* yeah yeah, uname overrides stat */ if (show_uname) otype =OUTPUT_UNAME_ONLY ; +/* and version overrides uname! */ +if (show_version) + otype =OUTPUT_VERSION_ONLY ;read_data_info (&handle_list, otype, global);list_for_each_entry (handles, &handle_list, list) {
tracecmd/trace-usage.c +1 -0
@@ -166,6 +166,7 @@ static struct usage_help usage_help[] = {" --check-events return whether all event formats can be parsed\n" " --stat - show the buffer stats that were reported at the end of the record.\n" " --uname - show uname of the record, if it was saved\n" +" --version - show version used to build the trace-cmd exec that created the file\n" " --profile report stats on where tasks are blocked and such\n" " -G when profiling, set soft and hard irqs as global\n" " -H Allows users to hook two events together for timings\n"
Signature · 1 line
2.20.1
Re: [PATCH] trace-cmd: Add trace-cmd report --version to extract version info
Quoted 14 lines · Steven Rostedt
From: "Steven Rostedt (VMware)" <[email protected]>
Now that the trace.dat file can save the version of the executable that was
used to create it, save that information. This will be useful if a user has
a problem with a trace.dat file. It can let the developers know what version
was used to create it. We need a way to extract this information. Adding a
new "--version" to trace-cmd report will display the saved version in the
trace.dat file if it exists.
Quoted 2 lines
Signed-off-by Steven Rostedt (VMware) <[email protected]>---
Looks great.
Cheers!
-- Slavi