[lttng-dev] [PATCH lttng-tools 2/4] Allow channel mode override in snapshot sessions

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Wed Apr 20 15:19:58 UTC 2016


Allow the lttng cmd line and liblttng-ctl users to override the channel
mode in snapshot sessions.

Note that liblttng-ctl users expecting that an "overwrite" mode
explicitly set at the value "0" (discard) for a snapshot session will
now create a channel in discard mode.

The DEFAULT_CHANNEL_OVERWRITE used by liblttng-ctl
lttng_channel_set_default_attr() is changed to "-1".

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
 include/lttng/channel.h          |  2 +-
 src/bin/lttng-sessiond/channel.c | 30 ++++++++++++++++++++++++++----
 src/bin/lttng/commands/create.c  |  2 +-
 src/common/defaults.h            |  2 +-
 4 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/include/lttng/channel.h b/include/lttng/channel.h
index 622ce85..732074c 100644
--- a/include/lttng/channel.h
+++ b/include/lttng/channel.h
@@ -33,7 +33,7 @@ extern "C" {
  */
 #define LTTNG_CHANNEL_ATTR_PADDING1        LTTNG_SYMBOL_NAME_LEN + 12
 struct lttng_channel_attr {
-	int overwrite;                      /* 1: overwrite, 0: discard */
+	int overwrite;                      /* -1: session default, 1: overwrite, 0: discard */
 	uint64_t subbuf_size;               /* bytes, power of 2 */
 	uint64_t num_subbuf;                /* power of 2 */
 	unsigned int switch_timer_interval; /* usec */
diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c
index 0119abf..7bb0ff7 100644
--- a/src/bin/lttng-sessiond/channel.c
+++ b/src/bin/lttng-sessiond/channel.c
@@ -214,9 +214,20 @@ int channel_kernel_create(struct ltt_kernel_session *ksession,
 		attr = defattr;
 	}
 
+	/*
+	 * Set the overwrite mode for this channel based on the session
+	 * type unless the client explicitly overrides the channel mode.
+	 */
+	if (attr->attr.overwrite == DEFAULT_CHANNEL_OVERWRITE) {
+		if (ksession->snapshot_mode) {
+			attr->attr.overwrite = 1;
+		} else {
+			attr->attr.overwrite = 0;
+		}
+	}
+
+	/* Enforce mmap output for snapshot sessions. */
 	if (ksession->snapshot_mode) {
-		/* Force channel attribute for snapshot mode. */
-		attr->attr.overwrite = 1;
 		attr->attr.output = LTTNG_EVENT_MMAP;
 	}
 
@@ -318,9 +329,20 @@ int channel_ust_create(struct ltt_ust_session *usess,
 		}
 	}
 
+	/*
+	 * Set the overwrite mode for this channel based on the session
+	 * type unless the client explicitly overrides the channel mode.
+	 */
+	if (attr->attr.overwrite == DEFAULT_CHANNEL_OVERWRITE) {
+		if (usess->snapshot_mode) {
+			attr->attr.overwrite = 1;
+		} else {
+			attr->attr.overwrite = 0;
+		}
+	}
+
+	/* Enforce mmap output for snapshot sessions. */
 	if (usess->snapshot_mode) {
-		/* Force channel attribute for snapshot mode. */
-		attr->attr.overwrite = 1;
 		attr->attr.output = LTTNG_EVENT_MMAP;
 	}
 
diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c
index 525464a..d8e4da4 100644
--- a/src/bin/lttng/commands/create.c
+++ b/src/bin/lttng/commands/create.c
@@ -442,7 +442,7 @@ static int create_session(void)
 			MSG("Default snapshot output set to: %s", print_str_url);
 		}
 		MSG("Snapshot mode set. Every channel enabled for that session will "
-				"be set in overwrite mode and mmap output.");
+				"be set to mmap output, and default to overwrite mode.");
 	}
 	if (opt_shm_path) {
 		MSG("Session %s set to shm_path: %s.", session_name,
diff --git a/src/common/defaults.h b/src/common/defaults.h
index 6e343b5..fc48ff9 100644
--- a/src/common/defaults.h
+++ b/src/common/defaults.h
@@ -188,7 +188,7 @@
 #define DEFAULT_PYTHON_EVENT_COMPONENT    "lttng_python"
 #define DEFAULT_PYTHON_EVENT_NAME         DEFAULT_PYTHON_EVENT_COMPONENT ":*"
 
-#define DEFAULT_CHANNEL_OVERWRITE       0
+#define DEFAULT_CHANNEL_OVERWRITE       -1
 #define DEFAULT_CHANNEL_TRACEFILE_SIZE  0
 #define DEFAULT_CHANNEL_TRACEFILE_COUNT 0
 
-- 
2.1.4



More information about the lttng-dev mailing list