This patch fixes a bug with the initial state in the control flow viewer. When
a process was started before starting the trace, in some situation all the
states of this process was wrong, because of a unknown initial state.

The patch adds string tables that matches the enums sequence in lttng-modules,
to convert enum value in the state dump to quark.
---
 lttv/lttv/state.c |   21 +++++++--------------
 lttv/lttv/state.h |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 14 deletions(-)

>From 10201a29635aeb69f8554f020e786ebc13b96b62 Mon Sep 17 00:00:00 2001
From: Francis Giraldeau <[email protected]>
Date: Thu, 25 Nov 2010 10:20:30 -0500
Subject: [PATCH] Fix initial state bug

This patch fixes a bug with the initial state in the control flow viewer. When
a process was started before starting the trace, in some situation all the
states of this process was wrong, because of a unknown initial state.

The patch adds string tables that matches the enums sequence in lttng-modules,
to convert enum value in the state dump to quark.
---
 lttv/lttv/state.c |   21 +++++++--------------
 lttv/lttv/state.h |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/lttv/lttv/state.c b/lttv/lttv/state.c
index bd3f64d..1d3a2e5 100644
--- a/lttv/lttv/state.c
+++ b/lttv/lttv/state.c
@@ -46,6 +46,9 @@
 
 #define PREALLOCATED_EXECUTION_STACK 10
 
+/* get a given quark from lttng module enum value */
+#define enum_quark(e, f, names) (g_quark_from_string(names[ltt_event_get_unsigned(e, f)]))
+
 /* Channel Quarks */
 
 GQuark
@@ -3440,21 +3443,19 @@ static gboolean enum_process_state(void *hook_data, void *call_data)
 
 	/* type */
 	f = lttv_trace_get_hook_field(th, 3);
-	type = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f));
-
-	//FIXME: type is rarely used, enum must match possible types.
+	type = enum_quark(e, f, lttng_thread_type_names);
 
 	/* mode */
 	f = lttv_trace_get_hook_field(th, 4);
-	mode = ltt_enum_string_get(f,ltt_event_get_unsigned(e, f));
+	mode = enum_quark(e, f, lttng_execution_mode_names);
 
 	/* submode */
 	f = lttv_trace_get_hook_field(th, 5);
-	submode = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f));
+	submode = enum_quark(e, f, lttng_execution_submode_names);
 
 	/* status */
 	f = lttv_trace_get_hook_field(th, 6);
-	status = ltt_enum_string_get(f, ltt_event_get_unsigned(e, f));
+	status = enum_quark(e, f, lttng_process_status_names);
 
 	/* TGID */
 	f = lttv_trace_get_hook_field(th, 7);
@@ -3503,11 +3504,9 @@ static gboolean enum_process_state(void *hook_data, void *call_data)
 				es->t = LTTV_STATE_MODE_UNKNOWN;
 				es->s = LTTV_STATE_UNNAMED;
 				es->n = LTTV_STATE_SUBMODE_UNKNOWN;
-#if 0
 				es->t = LTTV_STATE_SYSCALL;
 				es->s = status;
 				es->n = submode;
-#endif //0
 			} else {
 				/* User space process :
 				 * bottom : user mode
@@ -3528,13 +3527,10 @@ static gboolean enum_process_state(void *hook_data, void *call_data)
 				es->t = LTTV_STATE_MODE_UNKNOWN;
 				es->s = LTTV_STATE_UNNAMED;
 				es->n = LTTV_STATE_SUBMODE_UNKNOWN;
-	#if 0
 				es->t = LTTV_STATE_USER_MODE;
 				es->s = status;
 				es->n = submode;
-	#endif //0
 			}
-	#if 0
 			/* UNKNOWN STATE */
 			{
 				es = process->state = &g_array_index(process->execution_stack,
@@ -3543,7 +3539,6 @@ static gboolean enum_process_state(void *hook_data, void *call_data)
 				es->s = LTTV_STATE_UNNAMED;
 				es->n = LTTV_STATE_SUBMODE_UNKNOWN;
 			}
-	#endif //0
 		} else {
 			/* The process has already been created :
 			 * Probably was forked while dumping the process state or
@@ -3554,14 +3549,12 @@ static gboolean enum_process_state(void *hook_data, void *call_data)
 			process->name = g_quark_from_string(command);
 			process->type = type;
 			es = &g_array_index(process->execution_stack, LttvExecutionState, 0);
-#if 0
 			if(es->t == LTTV_STATE_MODE_UNKNOWN) {
 				if(type == LTTV_STATE_KERNEL_THREAD)
 					es->t = LTTV_STATE_SYSCALL;
 				else
 					es->t = LTTV_STATE_USER_MODE;
 			}
-#endif //0
 			/* Don't mess around with the stack, it will eventually become
 			 * ok after the end of state dump. */
 		}
diff --git a/lttv/lttv/state.h b/lttv/lttv/state.h
index 0ae7e5c..03fa0d4 100644
--- a/lttv/lttv/state.h
+++ b/lttv/lttv/state.h
@@ -53,6 +53,40 @@
 
 #define LTTV_STATE_SAVE_INTERVAL 50000
 
+/*
+ * Quark strings that matches lttng module enums found in statedump
+ * Matching enums are from lttng-modules/ltt-statedump.c
+ */
+static const char *const lttng_thread_type_names[] = {
+        "USER_THREAD",     // LTTNG_USER_THREAD
+        "KERNEL_THREAD"    // LTTNG_KERNEL_THREAD
+};
+
+static const char *const lttng_execution_mode_names[] = {
+        "USER_MODE",       // LTTNG_USER_MODE
+        "SYSCALL",         // LTTNG_SYSCALL
+        "TRAP",            // LTTNG_TRAP
+        "IRQ",             // LTTNG_IRQ
+        "SOFTIRQ",         // LTTNG_SOFTIRQ
+        "UNKNOWN"          // LTTNG_MODE_UNKNOWN
+};
+
+static const char *const lttng_execution_submode_names[] = {
+        "UNKNOWN",         // LTTNG_NONE
+        "NONE"             // LTTNG_UNKNOWN
+};
+
+static const char *const lttng_process_status_names[] = {
+        "",                 // LTTNG_UNNAMED
+        "WAIT_FORK",        // LTTNG_WAIT_FORK
+        "WAIT_CPU",         // LTTNG_WAIT_CPU
+        "EXIT",             // LTTNG_EXIT
+        "ZOMBIE",           // LTTNG_ZOMBIE
+        "WAIT",             // LTTNG_WAIT
+        "RUN",              // LTTNG_RUN
+        "DEAD"              // LTTNG_DEAD
+};
+
 /* Channel Quarks */
 
 extern GQuark
-- 
1.7.1

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev

Reply via email to