[lttng-dev] [Patch LTTng-tools 3/4] Statedump the metadata for CTF named enumerations

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


The metadata is dumped along with the event description, before the event
itself so that the metadata precedes it in the metadata file.

Signed-off-by: Geneviève Bastien <gbastien+lttng at versatic.net>
---
 src/bin/lttng-sessiond/ust-metadata.c | 93 ++++++++++++++++++++++++++++++++++-
 1 file changed, 91 insertions(+), 2 deletions(-)

diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c
index b0f83d2..87d21fc 100644
--- a/src/bin/lttng-sessiond/ust-metadata.c
+++ b/src/bin/lttng-sessiond/ust-metadata.c
@@ -180,6 +180,12 @@ int _lttng_field_statedump(struct ust_registry_session *session,
 			field->type.u.basic.integer.reverse_byte_order ? bo_reverse : bo_native,
 			field->name);
 		break;
+	case ustctl_atype_enum:
+		ret = lttng_metadata_printf(session,
+			"		enum __ust_enum__%s _%s;\n",
+			field->type.u.basic.enumeration.name,
+			field->name);
+		break;
 	case ustctl_atype_float:
 		ret = lttng_metadata_printf(session,
 			"		floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n",
@@ -189,8 +195,6 @@ int _lttng_field_statedump(struct ust_registry_session *session,
 			field->type.u.basic.integer.reverse_byte_order ? bo_reverse : bo_native,
 			field->name);
 		break;
-	case ustctl_atype_enum:
-		return -EINVAL;
 	case ustctl_atype_array:
 	{
 		const struct ustctl_basic_type *elem_type;
@@ -303,6 +307,86 @@ int _lttng_fields_metadata_statedump(struct ust_registry_session *session,
 }
 
 /*
+ * Dumps a named metadata to the metadata file for the session. It should
+ * verify whether this metadata was already dumped by a previous event.
+ */
+static
+int _lttng_one_metadata_statedump(struct ust_registry_session *session,
+		const struct ustctl_named_metadata *metadata)
+{
+	int ret = 0, i;
+
+	switch (metadata->mtype) {
+	case ustctl_mtype_enum:
+	{
+		const struct ustctl_enum *uenum;
+		uenum = &metadata->u.ctf_enum;
+		ret = lttng_metadata_printf(session,
+			"enum __ust_enum__%s: integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u; } {\n",
+			uenum->name,
+			uenum->container_type.size,
+			uenum->container_type.alignment,
+			uenum->container_type.signedness,
+			(uenum->container_type.encoding == ustctl_encode_none)
+				? "none"
+				: (uenum->container_type.encoding == ustctl_encode_UTF8)
+					? "UTF8"
+					: "ASCII",
+			uenum->container_type.base);
+		if (ret)
+			return ret;
+		/* Dump the entries */
+		for (i = 0; i < uenum->len; i++) {
+			struct ustctl_enum_entry entry;
+			entry = uenum->entries[i];
+			if (entry.start == entry.end) {
+				ret = lttng_metadata_printf(session,
+						"	%s = %d,\n",
+						entry.string, entry.start);
+				if (ret)
+					return ret;
+			} else {
+				ret = lttng_metadata_printf(session,
+						"	%s = %d ... %d,\n",
+						entry.string, entry.start, entry.end);
+				if (ret)
+					return ret;
+			}
+		}
+		ret = lttng_metadata_printf(session, "};\n\n");
+		if (ret)
+			return ret;
+		break;
+	}
+	default:
+		return -EINVAL;
+	}
+
+	return ret;
+}
+
+/*
+ * This function dumps to the metadata the named metadata used by the
+ * event.
+ */
+static
+int _lttng_named_metadata_statedump(struct ust_registry_session *session,
+		struct ust_registry_event *event)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < event->nr_metadata; i++) {
+		const struct ustctl_named_metadata *metadata = &event->named_metadata[i];
+
+		ret = _lttng_one_metadata_statedump(session, metadata);
+		if (ret)
+			return ret;
+	}
+	return ret;
+}
+
+/*
  * Should be called with session registry mutex held.
  */
 int ust_metadata_event_statedump(struct ust_registry_session *session,
@@ -315,6 +399,11 @@ int ust_metadata_event_statedump(struct ust_registry_session *session,
 	if (chan->chan_id == -1U)
 		return 0;
 
+	/* Dump the named_metadata needed by this event */
+	ret = _lttng_named_metadata_statedump(session, event);
+	if (ret)
+		goto end;
+
 	ret = lttng_metadata_printf(session,
 		"event {\n"
 		"	name = \"%s\";\n"
-- 
1.8.5.3




More information about the lttng-dev mailing list