Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [ltt-dev] [PATCH] Adding filtering 'metadata' channel to formattedDump
@ 2011-02-01 18:21 Vincent Attard
  2011-02-01 19:42 ` Mathieu Desnoyers
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Attard @ 2011-02-01 18:21 UTC (permalink / raw)


User can still have them with -M option.
Small changes for optimization: Parse options only one time at the init until everytime.
---
 lttv/modules/text/formattedDump.c |   83 +++++++++++++++++++++++-------------
 1 files changed, 53 insertions(+), 30 deletions(-)

diff --git a/lttv/modules/text/formattedDump.c b/lttv/modules/text/formattedDump.c
index 8fc2fbf..4d08f7e 100644
--- a/lttv/modules/text/formattedDump.c
+++ b/lttv/modules/text/formattedDump.c
@@ -51,7 +51,7 @@ static gboolean a_no_field_names;
 static gboolean a_state;
 static gboolean a_text;
 static gboolean a_strace;
-
+static gboolean a_meta;
 static char *a_file_name;
 static char *a_format;
 
@@ -59,18 +59,40 @@ static LttvHooks *before_traceset;
 static LttvHooks *event_hook;
 
 static const char default_format[] =
-		"channel:%c event:%e timestamp:%t elapsed:%l cpu:%u pid:%d ppid:%i "
-		"tgpid:%g process:%p brand:%b state:%a payload:{ %m }";
+		"channel:%c event:%e timestamp:%t elapsed:%l cpu:%u pid:%d "
+		"ppid:%i tgpid:%g process:%p brand:%b state:%a payload:{ %m }";
 static const char textDump_format[] =
 		"%c.%e: %s.%n (%r/%c_%u), %d, %g, %p, %b, %i, %y, %a { %m }";
 static const char strace_format[] = "%e(%m) %s.%n";
+static const char *fmt;
 
 static FILE *a_file;
 
 static GString *a_string;
 
+static int output_format_len;
+
 static gboolean open_output_file(void *hook_data, void *call_data)
 {
+	if (a_text) {
+		/* textDump format (used with -T command option) */
+		fmt = textDump_format;
+	} else if (a_strace) {
+		/* strace-like format (used with -S command option) */
+		fmt = strace_format;
+	} else if (!a_format) {
+		/* Default format (used if no option) */
+		fmt = default_format;
+	} else {
+		/*
+		 * formattedDump format
+		 * (used with -F command option following by the desired format)
+		 */
+		fmt = a_format;
+	}
+
+	output_format_len = strlen(fmt);
+
 	g_info("Open the output file");
 	if (a_file_name == NULL) {
 		a_file = stdout;
@@ -118,6 +140,20 @@ static int write_event_content(void *hook_data, void *call_data)
 		}
 	}
 
+	/*
+	 * By default, metadata's channel won't be display: it goes directly
+	 * to the next event. You can have metadata's informations with -M
+	 * switch (a_meta option).
+	 */
+	if (!a_meta && ltt_tracefile_name(tfs->parent.tf) ==
+			g_quark_from_string("metadata")) {
+		return FALSE;
+		/*
+		 * TODO:
+		 * Investigate the use of filter to do it.
+		 */
+	}
+
 	lttv_event_to_string(e, a_string, TRUE, !a_no_field_names, tfs);
 
 	if (a_state) {
@@ -126,7 +162,6 @@ static int write_event_content(void *hook_data, void *call_data)
 	}
 
 	g_string_append_printf(a_string, "\n");
-
 	fputs(a_string->str, a_file);
 	return FALSE;
 }
@@ -136,18 +171,17 @@ void lttv_event_to_string(LttEvent *e, GString *string_buffer, gboolean mandator
 {
 	struct marker_field *field;
 	struct marker_info *info;
-	LttTime time;
 
+	LttTime time;
+	LttTime elapse;
 	static LttTime time_prev = {0, 0};
 	/*
 	 * TODO:
 	 * Added this static value into state.c and reset each time you do a
 	 * seek for using it in the GUI.
 	 */
-	LttTime elapse;
-	const char *fmt;
+
 	int i;
-	int len;
 	guint cpu = tfs->cpu;
 	LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
 	LttvProcessState *process = ts->running_process[cpu];
@@ -171,30 +205,12 @@ void lttv_event_to_string(LttEvent *e, GString *string_buffer, gboolean mandator
 			time_prev = time;
 		}
 	}
-	if (a_text) {
-		/* textDump format (used with -T command option) */
-		fmt = textDump_format;
-	} else if (a_strace) {
-		/* strace-like format (used with -S command option) */
-		fmt = strace_format;
-	} else if (!a_format) {
-		/* Default format (used if no option) */
-		fmt = default_format;
-	} else {
-		/*
-		 * formattedDump format
-		 * (used with -F command option following by the desired format)
-		 */
-		fmt = a_format;
-	}
-
 	g_string_set_size(string_buffer, 0);
 	/*
 	 * Switch case:
 	 * all '%-' are replaced by the desired value in 'string_buffer'
 	 */
-	len = strlen(fmt);
-	for (i = 0; i < len; i++) {
+	for (i = 0; i < output_format_len; i++) {
 		if (fmt[i] == '%') {
 			switch (fmt[++i]) {
 			case 't':
@@ -238,8 +254,8 @@ void lttv_event_to_string(LttEvent *e, GString *string_buffer, gboolean mandator
 						g_quark_to_string(process->name));
 				break;
 			case 'b':
-				g_string_append_printf(string_buffer, "%u",
-						process->brand);
+				g_string_append(string_buffer,
+						g_quark_to_string(process->brand));
 				break;
 			case 'u':
 				g_string_append_printf(string_buffer, "%u", cpu);
@@ -267,7 +283,6 @@ void lttv_event_to_string(LttEvent *e, GString *string_buffer, gboolean mandator
 						if (field != marker_get_field(info, 0)) {
 							g_string_append(string_buffer, ", ");
 						}
-
 						lttv_print_field(e, field, string_buffer, field_names, tfs);
 					}
 				}
@@ -322,6 +337,12 @@ static void init()
 			"",
 			LTTV_OPT_NONE, &a_strace, NULL, NULL);
 
+	a_meta = FALSE;
+		lttv_option_add("metadata", 'M',
+				"add metadata informations",
+				"",
+				LTTV_OPT_NONE, &a_meta, NULL, NULL);
+
 	a_format = NULL;
 	lttv_option_add("format", 'F',
 			"output the desired format\n"
@@ -376,6 +397,8 @@ static void destroy()
 
 	lttv_option_remove("strace");
 
+	lttv_option_remove("metadata");
+
 	g_string_free(a_string, TRUE);
 
 	lttv_hooks_remove_data(event_hook, write_event_content, NULL);
-- 
1.7.0.4





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

* [ltt-dev] [PATCH] Adding filtering 'metadata' channel to formattedDump
  2011-02-01 18:21 [ltt-dev] [PATCH] Adding filtering 'metadata' channel to formattedDump Vincent Attard
@ 2011-02-01 19:42 ` Mathieu Desnoyers
  0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Desnoyers @ 2011-02-01 19:42 UTC (permalink / raw)


* Vincent Attard (vincent.attard at polymtl.ca) wrote:
> User can still have them with -M option.
> Small changes for optimization: Parse options only one time at the init until everytime.


Please review indentation.

Mathieu

> ---
>  lttv/modules/text/formattedDump.c |   83 +++++++++++++++++++++++-------------
>  1 files changed, 53 insertions(+), 30 deletions(-)
> 
> diff --git a/lttv/modules/text/formattedDump.c b/lttv/modules/text/formattedDump.c
> index 8fc2fbf..4d08f7e 100644
> --- a/lttv/modules/text/formattedDump.c
> +++ b/lttv/modules/text/formattedDump.c
> @@ -51,7 +51,7 @@ static gboolean a_no_field_names;
>  static gboolean a_state;
>  static gboolean a_text;
>  static gboolean a_strace;
> -
> +static gboolean a_meta;
>  static char *a_file_name;
>  static char *a_format;
>  
> @@ -59,18 +59,40 @@ static LttvHooks *before_traceset;
>  static LttvHooks *event_hook;
>  
>  static const char default_format[] =
> -		"channel:%c event:%e timestamp:%t elapsed:%l cpu:%u pid:%d ppid:%i "
> -		"tgpid:%g process:%p brand:%b state:%a payload:{ %m }";
> +		"channel:%c event:%e timestamp:%t elapsed:%l cpu:%u pid:%d "
> +		"ppid:%i tgpid:%g process:%p brand:%b state:%a payload:{ %m }";
>  static const char textDump_format[] =
>  		"%c.%e: %s.%n (%r/%c_%u), %d, %g, %p, %b, %i, %y, %a { %m }";
>  static const char strace_format[] = "%e(%m) %s.%n";
> +static const char *fmt;
>  
>  static FILE *a_file;
>  
>  static GString *a_string;
>  
> +static int output_format_len;
> +
>  static gboolean open_output_file(void *hook_data, void *call_data)
>  {
> +	if (a_text) {
> +		/* textDump format (used with -T command option) */
> +		fmt = textDump_format;
> +	} else if (a_strace) {
> +		/* strace-like format (used with -S command option) */
> +		fmt = strace_format;
> +	} else if (!a_format) {
> +		/* Default format (used if no option) */
> +		fmt = default_format;
> +	} else {
> +		/*
> +		 * formattedDump format
> +		 * (used with -F command option following by the desired format)
> +		 */
> +		fmt = a_format;
> +	}
> +
> +	output_format_len = strlen(fmt);
> +
>  	g_info("Open the output file");
>  	if (a_file_name == NULL) {
>  		a_file = stdout;
> @@ -118,6 +140,20 @@ static int write_event_content(void *hook_data, void *call_data)
>  		}
>  	}
>  
> +	/*
> +	 * By default, metadata's channel won't be display: it goes directly
> +	 * to the next event. You can have metadata's informations with -M
> +	 * switch (a_meta option).
> +	 */
> +	if (!a_meta && ltt_tracefile_name(tfs->parent.tf) ==
> +			g_quark_from_string("metadata")) {
> +		return FALSE;
> +		/*
> +		 * TODO:
> +		 * Investigate the use of filter to do it.
> +		 */
> +	}
> +
>  	lttv_event_to_string(e, a_string, TRUE, !a_no_field_names, tfs);
>  
>  	if (a_state) {
> @@ -126,7 +162,6 @@ static int write_event_content(void *hook_data, void *call_data)
>  	}
>  
>  	g_string_append_printf(a_string, "\n");
> -
>  	fputs(a_string->str, a_file);
>  	return FALSE;
>  }
> @@ -136,18 +171,17 @@ void lttv_event_to_string(LttEvent *e, GString *string_buffer, gboolean mandator
>  {
>  	struct marker_field *field;
>  	struct marker_info *info;
> -	LttTime time;
>  
> +	LttTime time;
> +	LttTime elapse;
>  	static LttTime time_prev = {0, 0};
>  	/*
>  	 * TODO:
>  	 * Added this static value into state.c and reset each time you do a
>  	 * seek for using it in the GUI.
>  	 */
> -	LttTime elapse;
> -	const char *fmt;
> +
>  	int i;
> -	int len;
>  	guint cpu = tfs->cpu;
>  	LttvTraceState *ts = (LttvTraceState *)tfs->parent.t_context;
>  	LttvProcessState *process = ts->running_process[cpu];
> @@ -171,30 +205,12 @@ void lttv_event_to_string(LttEvent *e, GString *string_buffer, gboolean mandator
>  			time_prev = time;
>  		}
>  	}
> -	if (a_text) {
> -		/* textDump format (used with -T command option) */
> -		fmt = textDump_format;
> -	} else if (a_strace) {
> -		/* strace-like format (used with -S command option) */
> -		fmt = strace_format;
> -	} else if (!a_format) {
> -		/* Default format (used if no option) */
> -		fmt = default_format;
> -	} else {
> -		/*
> -		 * formattedDump format
> -		 * (used with -F command option following by the desired format)
> -		 */
> -		fmt = a_format;
> -	}
> -
>  	g_string_set_size(string_buffer, 0);
>  	/*
>  	 * Switch case:
>  	 * all '%-' are replaced by the desired value in 'string_buffer'
>  	 */
> -	len = strlen(fmt);
> -	for (i = 0; i < len; i++) {
> +	for (i = 0; i < output_format_len; i++) {
>  		if (fmt[i] == '%') {
>  			switch (fmt[++i]) {
>  			case 't':
> @@ -238,8 +254,8 @@ void lttv_event_to_string(LttEvent *e, GString *string_buffer, gboolean mandator
>  						g_quark_to_string(process->name));
>  				break;
>  			case 'b':
> -				g_string_append_printf(string_buffer, "%u",
> -						process->brand);
> +				g_string_append(string_buffer,
> +						g_quark_to_string(process->brand));
>  				break;
>  			case 'u':
>  				g_string_append_printf(string_buffer, "%u", cpu);
> @@ -267,7 +283,6 @@ void lttv_event_to_string(LttEvent *e, GString *string_buffer, gboolean mandator
>  						if (field != marker_get_field(info, 0)) {
>  							g_string_append(string_buffer, ", ");
>  						}
> -
>  						lttv_print_field(e, field, string_buffer, field_names, tfs);
>  					}
>  				}
> @@ -322,6 +337,12 @@ static void init()
>  			"",
>  			LTTV_OPT_NONE, &a_strace, NULL, NULL);
>  
> +	a_meta = FALSE;
> +		lttv_option_add("metadata", 'M',
> +				"add metadata informations",
> +				"",
> +				LTTV_OPT_NONE, &a_meta, NULL, NULL);
> +
>  	a_format = NULL;
>  	lttv_option_add("format", 'F',
>  			"output the desired format\n"
> @@ -376,6 +397,8 @@ static void destroy()
>  
>  	lttv_option_remove("strace");
>  
> +	lttv_option_remove("metadata");
> +
>  	g_string_free(a_string, TRUE);
>  
>  	lttv_hooks_remove_data(event_hook, write_event_content, NULL);
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




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

end of thread, other threads:[~2011-02-01 19:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-01 18:21 [ltt-dev] [PATCH] Adding filtering 'metadata' channel to formattedDump Vincent Attard
2011-02-01 19:42 ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox