From: Mathieu Desnoyers Date: Wed, 16 Nov 2011 00:15:18 +0000 (-0500) Subject: lttng-sessiond: keep enabled/active state for sessions, cleanup enabled state for... X-Git-Tag: v2.0-pre15~109 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=464dd62d5617322366e321877b440951e00a0152;p=lttng-tools.git lttng-sessiond: keep enabled/active state for sessions, cleanup enabled state for events/channels allows lttng list Available tracing sessions: 1) test1 (/root/lttng-traces/test1-20111115-191312) [inactive] 2) test2 (/root/lttng-traces/test2-20111115-191310) [active] and root@thinkos:~# lttng list test2 Tracing session test2: [active] Trace path: /root/lttng-traces/test2-20111115-191502 When events/channels/sessions enabled state is set to -1, show an empty string instead of the meaningless "[enabled: -1]". Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/lttng.h b/include/lttng/lttng.h index ee749c1f6..280075037 100644 --- a/include/lttng/lttng.h +++ b/include/lttng/lttng.h @@ -189,6 +189,7 @@ struct lttng_session { char name[NAME_MAX]; /* The path where traces are written */ char path[PATH_MAX]; + uint32_t enabled; /* enabled/started: 1, disabled/stopped: 0 */ }; /* diff --git a/lttng-sessiond/main.c b/lttng-sessiond/main.c index d1cc3fa8f..2e6292d38 100644 --- a/lttng-sessiond/main.c +++ b/lttng-sessiond/main.c @@ -1790,6 +1790,7 @@ static void list_lttng_sessions(struct lttng_session *sessions) sessions[i].path[PATH_MAX - 1] = '\0'; strncpy(sessions[i].name, session->name, NAME_MAX); sessions[i].name[NAME_MAX - 1] = '\0'; + sessions[i].enabled = session->enabled; i++; } } @@ -2512,6 +2513,10 @@ static int cmd_start_trace(struct ltt_session *session) ksession = session->kernel_session; usess = session->ust_session; + if (session->enabled) + return LTTCOMM_UST_START_FAIL; + session->enabled = 1; + /* Kernel tracing */ if (ksession != NULL) { struct ltt_kernel_channel *kchan; @@ -2597,6 +2602,10 @@ static int cmd_stop_trace(struct ltt_session *session) /* Short cut */ ksession = session->kernel_session; + if (!session->enabled) + return LTTCOMM_UST_START_FAIL; + session->enabled = 0; + /* Kernel tracer */ if (ksession != NULL) { DBG("Stop kernel tracing"); diff --git a/lttng-sessiond/session.h b/lttng-sessiond/session.h index f6a9fff4d..2d077a4bc 100644 --- a/lttng-sessiond/session.h +++ b/lttng-sessiond/session.h @@ -67,6 +67,7 @@ struct ltt_session { */ pthread_mutex_t lock; struct cds_list_head list; + int enabled; /* enabled/started flag */ }; /* Prototypes */ diff --git a/lttng/commands/list.c b/lttng/commands/list.c index fcfaa3f23..a3d8868b5 100644 --- a/lttng/commands/list.c +++ b/lttng/commands/list.c @@ -109,6 +109,28 @@ end: return cmdline; } +static +const char *active_string(int value) +{ + switch (value) { + case 0: return " [active]"; + case 1: return " [inactive]"; + case -1: return ""; + default: return NULL; + } +} + +static +const char *enabled_string(int value) +{ + switch (value) { + case 0: return " [enabled]"; + case 1: return " [disabled]"; + case -1: return ""; + default: return NULL; + } +} + /* * Pretty print single event. */ @@ -116,12 +138,12 @@ static void print_events(struct lttng_event *event) { switch (event->type) { case LTTNG_EVENT_TRACEPOINT: - MSG("%s%s (type: tracepoint) [enabled: %d]", indent6, - event->name, event->enabled); + MSG("%s%s (type: tracepoint)%s", indent6, + event->name, enabled_string(event->enabled)); break; case LTTNG_EVENT_PROBE: - MSG("%s%s (type: probe) [enabled: %d]", indent6, - event->name, event->enabled); + MSG("%s%s (type: probe)%s", indent6, + event->name, enabled_string(event->enabled)); if (event->attr.probe.addr != 0) { MSG("%saddr: 0x%" PRIx64, indent8, event->attr.probe.addr); } else { @@ -131,17 +153,17 @@ static void print_events(struct lttng_event *event) break; case LTTNG_EVENT_FUNCTION: case LTTNG_EVENT_FUNCTION_ENTRY: - MSG("%s%s (type: function) [enabled: %d]", indent6, - event->name, event->enabled); + MSG("%s%s (type: function)%s", indent6, + event->name, enabled_string(event->enabled)); MSG("%ssymbol: \"%s\"", indent8, event->attr.ftrace.symbol_name); break; case LTTNG_EVENT_SYSCALL: - MSG("%s (type: syscall) [enabled: %d]", indent6, - event->enabled); + MSG("%s (type: syscall)%s", indent6, + enabled_string(event->enabled)); break; case LTTNG_EVENT_NOOP: - MSG("%s (type: noop) [enabled: %d]", indent6, - event->enabled); + MSG("%s (type: noop)%s", indent6, + enabled_string(event->enabled)); break; case LTTNG_EVENT_ALL: /* We should never have "all" events in list. */ @@ -282,7 +304,7 @@ error: */ static void print_channel(struct lttng_channel *channel) { - MSG("- %s (enabled: %d):\n", channel->name, channel->enabled); + MSG("- %s:%s\n", channel->name, enabled_string(channel->enabled)); MSG("%sAttributes:", indent4); MSG("%soverwrite mode: %d", indent6, channel->attr.overwrite); @@ -385,14 +407,14 @@ static int list_sessions(const char *session_name) if (session_name != NULL) { if (strncmp(sessions[i].name, session_name, NAME_MAX) == 0) { session_found = 1; - MSG("Tracing session %s:", session_name); + MSG("Tracing session %s:%s", session_name, active_string(sessions[i].enabled)); MSG("%sTrace path: %s\n", indent4, sessions[i].path); break; } continue; } - MSG(" %d) %s (%s)", i + 1, sessions[i].name, sessions[i].path); + MSG(" %d) %s (%s)%s", i + 1, sessions[i].name, sessions[i].path, active_string(sessions[i].enabled)); if (session_found) { break;