[lttng-dev] [Patch LTTng-tools 4/4] Dump a named metadata only once per session

Geneviève Bastien gbastien+lttng at versatic.net
Fri Jan 24 15:07:25 EST 2014


Named metadata can be used more than once in a single tracepoint, or many
tracepoints can use it. It must be statedumped only once in a given session.

Signed-off-by: Geneviève Bastien <gbastien+lttng at versatic.net>
---
 src/bin/lttng-sessiond/ust-metadata.c | 39 +++++++++++++++++++++++++++++++++++
 src/bin/lttng-sessiond/ust-registry.c | 11 ++++++++++
 src/bin/lttng-sessiond/ust-registry.h |  8 +++++++
 3 files changed, 58 insertions(+)

diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c
index 87d21fc..8b904a8 100644
--- a/src/bin/lttng-sessiond/ust-metadata.c
+++ b/src/bin/lttng-sessiond/ust-metadata.c
@@ -316,6 +316,27 @@ int _lttng_one_metadata_statedump(struct ust_registry_session *session,
 {
 	int ret = 0, i;
 
+	/* Check if the metadata was already dumped */
+	if (session->dumped_named_metadata != 0) {
+		struct ust_dumped_metadata *dumped = session->dumped_named_metadata;
+		char *metadata_name;
+		switch (metadata->mtype) {
+		case ustctl_mtype_enum:
+			metadata_name = metadata->u.ctf_enum.name;
+			break;
+		default:
+			return -EINVAL;
+		}
+		do {
+			if (dumped->mtype == metadata->mtype) {
+				if (strcmp(dumped->name, metadata_name) == 0) {
+					return 0;
+				}
+			}
+			dumped = dumped->next;
+		} while (dumped);
+	}
+
 	switch (metadata->mtype) {
 	case ustctl_mtype_enum:
 	{
@@ -362,6 +383,24 @@ int _lttng_one_metadata_statedump(struct ust_registry_session *session,
 		return -EINVAL;
 	}
 
+	/* Flag this metadata as dumped */
+	struct ust_dumped_metadata *dumped;
+	dumped = zmalloc(sizeof(*dumped));
+	if (!dumped) {
+		ret = -ENOMEM;
+		return ret;
+	}
+	dumped->mtype = metadata->mtype;
+	switch (metadata->mtype) {
+	case ustctl_mtype_enum:
+		strncpy(dumped->name, metadata->u.ctf_enum.name, LTTNG_UST_SYM_NAME_LEN);
+		break;
+	default:
+		return -EINVAL;
+	}
+	dumped->next = session->dumped_named_metadata;
+	session->dumped_named_metadata = dumped;
+
 	return ret;
 }
 
diff --git a/src/bin/lttng-sessiond/ust-registry.c b/src/bin/lttng-sessiond/ust-registry.c
index 00e1c26..25cd31d 100644
--- a/src/bin/lttng-sessiond/ust-registry.c
+++ b/src/bin/lttng-sessiond/ust-registry.c
@@ -568,6 +568,7 @@ int ust_registry_session_init(struct ust_registry_session **sessionp,
 	session->uint64_t_alignment = uint64_t_alignment;
 	session->long_alignment = long_alignment;
 	session->byte_order = byte_order;
+	session->dumped_named_metadata = 0;
 
 	session->channels = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
 	if (!session->channels) {
@@ -630,4 +631,14 @@ void ust_registry_session_destroy(struct ust_registry_session *reg)
 	}
 
 	free(reg->metadata);
+
+	/* Free all dumped metadata */
+	if (reg->dumped_named_metadata) {
+		struct ust_dumped_metadata *dumped;
+		do {
+			dumped = reg->dumped_named_metadata;
+			reg->dumped_named_metadata = dumped->next;
+			free(dumped);
+		} while (reg->dumped_named_metadata);
+	}
 }
diff --git a/src/bin/lttng-sessiond/ust-registry.h b/src/bin/lttng-sessiond/ust-registry.h
index 183db0f..a6c7e6e 100644
--- a/src/bin/lttng-sessiond/ust-registry.h
+++ b/src/bin/lttng-sessiond/ust-registry.h
@@ -31,6 +31,12 @@
 
 struct ust_app;
 
+struct ust_dumped_metadata {
+	enum ustctl_metadata_types mtype;
+	char name[LTTNG_UST_SYM_NAME_LEN];
+	struct ust_dumped_metadata *next;
+};
+
 struct ust_registry_session {
 	/*
 	 * With multiple writers and readers, use this lock to access the registry.
@@ -75,6 +81,8 @@ struct ust_registry_session {
 	 * deletes its sessions.
 	 */
 	unsigned int metadata_closed;
+	/* The list of named metadata already dumped */
+	struct ust_dumped_metadata *dumped_named_metadata;
 };
 
 struct ust_registry_channel {
-- 
1.8.5.3




More information about the lttng-dev mailing list