* [lttng-dev] LTTng-tools: Add support of global types and CTF enumerations
[not found] <1390594045-7556-1-git-send-email-gbastien+lttng@versatic.net>
@ 2014-02-11 21:40 ` Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 1/5] Update data structures to support CTF global type declarations Geneviève Bastien
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Geneviève Bastien @ 2014-02-11 21:40 UTC (permalink / raw)
I made the corrections to the patches and added a regression test for events
with tracepoints using global type declarations.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [Patch LTTng-tools v2 1/5] Update data structures to support CTF global type declarations
2014-02-11 21:40 ` [lttng-dev] LTTng-tools: Add support of global types and CTF enumerations Geneviève Bastien
@ 2014-02-11 21:40 ` Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 2/5] Receive the CTF global enumerations from ust by the session daemon Geneviève Bastien
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Geneviève Bastien @ 2014-02-11 21:40 UTC (permalink / raw)
The structures match the LTTng-UST structure for supporting global type
delcarations in general and CTF enumerations in particular.
Signed-off-by: Genevi?ve Bastien <gbastien+lttng at versatic.net>
---
src/bin/lttng-sessiond/lttng-ust-ctl.h | 36 +++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/src/bin/lttng-sessiond/lttng-ust-ctl.h b/src/bin/lttng-sessiond/lttng-ust-ctl.h
index 7f59b86..41ed6c5 100644
--- a/src/bin/lttng-sessiond/lttng-ust-ctl.h
+++ b/src/bin/lttng-sessiond/lttng-ust-ctl.h
@@ -274,13 +274,23 @@ struct ustctl_float_type {
char padding[USTCTL_UST_FLOAT_TYPE_PADDING];
} LTTNG_PACKED;
-#define USTCTL_UST_BASIC_TYPE_PADDING 296
+#define USTCTL_UST_ENUM_ENTRY_PADDING 296
+struct ustctl_enum_entry {
+ unsigned long long start, end; /* start and end are inclusive */
+ char string[LTTNG_UST_SYM_NAME_LEN];
+ char padding[USTCTL_UST_ENUM_ENTRY_PADDING];
+};
+
+#define USTCTL_UST_BASIC_TYPE_PADDING 40
union _ustctl_basic_type {
struct ustctl_integer_type integer;
struct {
enum ustctl_string_encodings encoding;
} string;
struct ustctl_float_type _float;
+ struct {
+ char name[LTTNG_UST_SYM_NAME_LEN];
+ } enumeration;
char padding[USTCTL_UST_BASIC_TYPE_PADDING];
} LTTNG_PACKED;
@@ -308,6 +318,30 @@ struct ustctl_type {
} u;
} LTTNG_PACKED;
+#define USTCTL_UST_ENUM_TYPE_PADDING 296
+struct ustctl_enum {
+ char name[LTTNG_UST_SYM_NAME_LEN];
+ struct ustctl_integer_type container_type;
+ struct ustctl_enum_entry *entries;
+ unsigned int len;
+ char padding[USTCTL_UST_ENUM_TYPE_PADDING];
+} LTTNG_PACKED;
+
+/* CTF categories for global types declared outside event descriptions */
+enum ustctl_global_type_categories {
+ ustctl_mtype_enum,
+ NR_USTCTL_GLOBAL_TYPES,
+};
+
+#define USTCTL_UST_GLOBAL_TYPE_DECL_PADDING 640
+struct ustctl_global_type_decl {
+ uint32_t mtype;
+ union {
+ struct ustctl_enum ctf_enum;
+ char padding[USTCTL_UST_GLOBAL_TYPE_DECL_PADDING];
+ } u;
+};
+
#define USTCTL_UST_FIELD_PADDING 28
struct ustctl_field {
char name[LTTNG_UST_SYM_NAME_LEN];
--
1.8.5.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [Patch LTTng-tools v2 2/5] Receive the CTF global enumerations from ust by the session daemon
2014-02-11 21:40 ` [lttng-dev] LTTng-tools: Add support of global types and CTF enumerations Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 1/5] Update data structures to support CTF global type declarations Geneviève Bastien
@ 2014-02-11 21:40 ` Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 3/5] Statedump the metadata for CTF global enumerations Geneviève Bastien
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Geneviève Bastien @ 2014-02-11 21:40 UTC (permalink / raw)
The session daemon can receive the global type declarations coming with a
tracepoint. The global type declarations come after the tracepoint description
itself.
Signed-off-by: Genevi?ve Bastien <gbastien+lttng at versatic.net>
---
src/bin/lttng-sessiond/lttng-ust-ctl.h | 4 +++-
src/bin/lttng-sessiond/ust-app.c | 13 +++++++++----
src/bin/lttng-sessiond/ust-registry.c | 10 +++++++---
src/bin/lttng-sessiond/ust-registry.h | 6 +++++-
4 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/bin/lttng-sessiond/lttng-ust-ctl.h b/src/bin/lttng-sessiond/lttng-ust-ctl.h
index 41ed6c5..f52640d 100644
--- a/src/bin/lttng-sessiond/lttng-ust-ctl.h
+++ b/src/bin/lttng-sessiond/lttng-ust-ctl.h
@@ -400,7 +400,9 @@ int ustctl_recv_register_event(int sock,
*/
size_t *nr_fields,
struct ustctl_field **fields,
- char **model_emf_uri);
+ char **model_emf_uri,
+ size_t *nr_global_type_decl, /* global type declarations */
+ struct ustctl_global_type_decl **global_type_decl);
/*
* Returns 0 on success, negative error value on error.
diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c
index 34d4c9b..e8015a1 100644
--- a/src/bin/lttng-sessiond/ust-app.c
+++ b/src/bin/lttng-sessiond/ust-app.c
@@ -4647,7 +4647,8 @@ error_rcu_unlock:
*/
static int add_event_ust_registry(int sock, int sobjd, int cobjd, char *name,
char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel,
- char *model_emf_uri)
+ char *model_emf_uri, size_t nr_global_type_decl,
+ struct ustctl_global_type_decl *global_type_decl)
{
int ret, ret_code;
uint32_t event_id = 0;
@@ -4704,7 +4705,7 @@ static int add_event_ust_registry(int sock, int sobjd, int cobjd, char *name,
ret_code = ust_registry_create_event(registry, chan_reg_key,
sobjd, cobjd, name, sig, nr_fields, fields, loglevel,
model_emf_uri, ua_sess->buffer_type, &event_id,
- app);
+ app, nr_global_type_decl, global_type_decl);
/*
* The return value is returned to ustctl so in case of an error, the
@@ -4764,11 +4765,14 @@ int ust_app_recv_notify(int sock)
char name[LTTNG_UST_SYM_NAME_LEN], *sig, *model_emf_uri;
size_t nr_fields;
struct ustctl_field *fields;
+ size_t nr_global_type_decl;
+ struct ustctl_global_type_decl *global_type_decl;
DBG2("UST app ustctl register event received");
ret = ustctl_recv_register_event(sock, &sobjd, &cobjd, name, &loglevel,
- &sig, &nr_fields, &fields, &model_emf_uri);
+ &sig, &nr_fields, &fields, &model_emf_uri,
+ &nr_global_type_decl, &global_type_decl);
if (ret < 0) {
if (ret != -EPIPE && ret != -LTTNG_UST_ERR_EXITING) {
ERR("UST app recv event failed with ret %d", ret);
@@ -4785,7 +4789,8 @@ int ust_app_recv_notify(int sock)
* to the this function.
*/
ret = add_event_ust_registry(sock, sobjd, cobjd, name, sig, nr_fields,
- fields, loglevel, model_emf_uri);
+ fields, loglevel, model_emf_uri,
+ nr_global_type_decl, global_type_decl);
if (ret < 0) {
goto error;
}
diff --git a/src/bin/lttng-sessiond/ust-registry.c b/src/bin/lttng-sessiond/ust-registry.c
index dc49416..281ea7c 100644
--- a/src/bin/lttng-sessiond/ust-registry.c
+++ b/src/bin/lttng-sessiond/ust-registry.c
@@ -133,7 +133,8 @@ int validate_event_fields(size_t nr_fields, struct ustctl_field *fields,
static struct ust_registry_event *alloc_event(int session_objd,
int channel_objd, char *name, char *sig, size_t nr_fields,
struct ustctl_field *fields, int loglevel, char *model_emf_uri,
- struct ust_app *app)
+ struct ust_app *app, size_t nr_global_type_decl,
+ struct ustctl_global_type_decl *global_type_decl)
{
struct ust_registry_event *event = NULL;
@@ -163,6 +164,8 @@ static struct ust_registry_event *alloc_event(int session_objd,
strncpy(event->name, name, sizeof(event->name));
event->name[sizeof(event->name) - 1] = '\0';
}
+ event->nr_global_type_decl = nr_global_type_decl;
+ event->global_type_decl = global_type_decl;
cds_lfht_node_init(&event->node.node);
error:
@@ -249,7 +252,8 @@ int ust_registry_create_event(struct ust_registry_session *session,
uint64_t chan_key, int session_objd, int channel_objd, char *name,
char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel,
char *model_emf_uri, int buffer_type, uint32_t *event_id_p,
- struct ust_app *app)
+ struct ust_app *app, size_t nr_global_type_decl,
+ struct ustctl_global_type_decl *global_type_decl)
{
int ret;
uint32_t event_id;
@@ -286,7 +290,7 @@ int ust_registry_create_event(struct ust_registry_session *session,
}
event = alloc_event(session_objd, channel_objd, name, sig, nr_fields,
- fields, loglevel, model_emf_uri, app);
+ fields, loglevel, model_emf_uri, app, nr_global_type_decl, global_type_decl);
if (!event) {
ret = -ENOMEM;
goto error_free;
diff --git a/src/bin/lttng-sessiond/ust-registry.h b/src/bin/lttng-sessiond/ust-registry.h
index f195b74..8b41c2a 100644
--- a/src/bin/lttng-sessiond/ust-registry.h
+++ b/src/bin/lttng-sessiond/ust-registry.h
@@ -137,6 +137,9 @@ struct ust_registry_event {
* initialize the node and the event_name/signature for the match function.
*/
struct lttng_ht_node_u64 node;
+ /* Global type declarations needed by the event */
+ struct ustctl_global_type_decl *global_type_decl;
+ size_t nr_global_type_decl;
};
/*
@@ -226,7 +229,8 @@ int ust_registry_create_event(struct ust_registry_session *session,
uint64_t chan_key, int session_objd, int channel_objd, char *name,
char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel,
char *model_emf_uri, int buffer_type, uint32_t *event_id_p,
- struct ust_app *app);
+ struct ust_app *app, size_t nr_global_type_decl,
+ struct ustctl_global_type_decl *global_type_decl);
struct ust_registry_event *ust_registry_find_event(
struct ust_registry_channel *chan, char *name, char *sig);
void ust_registry_destroy_event(struct ust_registry_channel *chan,
--
1.8.5.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [Patch LTTng-tools v2 3/5] Statedump the metadata for CTF global enumerations
2014-02-11 21:40 ` [lttng-dev] LTTng-tools: Add support of global types and CTF enumerations Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 1/5] Update data structures to support CTF global type declarations Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 2/5] Receive the CTF global enumerations from ust by the session daemon Geneviève Bastien
@ 2014-02-11 21:40 ` Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 4/5] Dump a global type only once per session Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 5/5] Regression tests for global type declarations in UST Geneviève Bastien
4 siblings, 0 replies; 6+ messages in thread
From: Geneviève Bastien @ 2014-02-11 21:40 UTC (permalink / raw)
The global type declaration is dumped along with the event description,
before the event itself so that the corresponding 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 | 94 ++++++++++++++++++++++++++++++++++-
1 file changed, 92 insertions(+), 2 deletions(-)
diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c
index f430ae1..743901a 100644
--- a/src/bin/lttng-sessiond/ust-metadata.c
+++ b/src/bin/lttng-sessiond/ust-metadata.c
@@ -187,6 +187,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",
@@ -196,8 +202,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;
@@ -310,6 +314,87 @@ int _lttng_fields_metadata_statedump(struct ust_registry_session *session,
}
/*
+ * Dumps a global type to the metadata file for the session. It should
+ * verify whether this metadata was already dumped by a previous event.
+ */
+static
+int _lttng_one_global_type_statedump(struct ust_registry_session *session,
+ const struct ustctl_global_type_decl *global_type_decl)
+{
+ int ret = 0, i;
+
+ switch (global_type_decl->mtype) {
+ case ustctl_mtype_enum:
+ {
+ const struct ustctl_enum *uenum;
+
+ uenum = &global_type_decl->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 global type declarations used by
+ * the event.
+ */
+static
+int _lttng_global_type_decl_statedump(struct ust_registry_session *session,
+ struct ust_registry_event *event)
+{
+ int ret = 0, i;
+
+ for (i = 0; i < event->nr_global_type_decl; i++) {
+ const struct ustctl_global_type_decl *global_type_decl = &event->global_type_decl[i];
+
+ ret = _lttng_one_global_type_statedump(session, global_type_decl);
+ if (ret)
+ return ret;
+ }
+ return ret;
+}
+
+/*
* Should be called with session registry mutex held.
*/
int ust_metadata_event_statedump(struct ust_registry_session *session,
@@ -322,6 +407,11 @@ int ust_metadata_event_statedump(struct ust_registry_session *session,
if (chan->chan_id == -1U)
return 0;
+ /* Dump the global types needed by this event */
+ ret = _lttng_global_type_decl_statedump(session, event);
+ if (ret)
+ goto end;
+
ret = lttng_metadata_printf(session,
"event {\n"
" name = \"%s\";\n"
--
1.8.5.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [Patch LTTng-tools v2 4/5] Dump a global type only once per session
2014-02-11 21:40 ` [lttng-dev] LTTng-tools: Add support of global types and CTF enumerations Geneviève Bastien
` (2 preceding siblings ...)
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 3/5] Statedump the metadata for CTF global enumerations Geneviève Bastien
@ 2014-02-11 21:40 ` Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 5/5] Regression tests for global type declarations in UST Geneviève Bastien
4 siblings, 0 replies; 6+ messages in thread
From: Geneviève Bastien @ 2014-02-11 21:40 UTC (permalink / raw)
Global type declarations 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 | 46 +++++++++++++++++++++++
src/bin/lttng-sessiond/ust-registry.c | 69 +++++++++++++++++++++++++++++++++++
src/bin/lttng-sessiond/ust-registry.h | 15 ++++++++
3 files changed, 130 insertions(+)
diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c
index 743901a..dc144e1 100644
--- a/src/bin/lttng-sessiond/ust-metadata.c
+++ b/src/bin/lttng-sessiond/ust-metadata.c
@@ -322,6 +322,40 @@ int _lttng_one_global_type_statedump(struct ust_registry_session *session,
const struct ustctl_global_type_decl *global_type_decl)
{
int ret = 0, i;
+ struct ust_registry_global_type_decl *global_type;
+ struct cds_lfht_node *nodep;
+ struct lttng_ht_iter iter;
+ struct lttng_ht_node_str *node;
+
+ /* Check if the global type was already dumped */
+ global_type = zmalloc(sizeof(*global_type));
+ if (!global_type) {
+ PERROR("zmalloc ust registry global type");
+ return -ENOMEM;
+ }
+ global_type->category = global_type_decl->mtype;
+ switch (global_type_decl->mtype) {
+ case ustctl_mtype_enum:
+ strncpy(global_type->name, global_type_decl->u.ctf_enum.name, LTTNG_UST_SYM_NAME_LEN);
+ global_type->name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ rcu_read_lock();
+ cds_lfht_lookup(session->global_types_ht->ht, session->global_types_ht->hash_fct((void *) global_type, lttng_ht_seed),
+ session->global_types_ht->match_fct, global_type, &iter.iter);
+ node = lttng_ht_iter_get_node_str(&iter);
+ if (node != NULL) {
+ DBG("global type %s already in metadata", global_type->name);
+ rcu_read_unlock();
+ free(global_type);
+ return ret;
+ }
+ cds_lfht_node_init(&global_type->node.node);
+ rcu_read_unlock();
+
switch (global_type_decl->mtype) {
case ustctl_mtype_enum:
@@ -371,6 +405,17 @@ int _lttng_one_global_type_statedump(struct ust_registry_session *session,
return -EINVAL;
}
+ /* Flag this global type as dumped */
+ /*
+ * This is an add unique with a custom match function for global types.
+ * The node are matched using the category and global type name.
+ */
+ rcu_read_lock();
+ nodep = cds_lfht_add_unique(session->global_types_ht->ht, session->global_types_ht->hash_fct(global_type, lttng_ht_seed),
+ session->global_types_ht->match_fct, global_type, &global_type->node.node);
+ assert(nodep == &global_type->node.node);
+ rcu_read_unlock();
+
return ret;
}
@@ -388,6 +433,7 @@ int _lttng_global_type_decl_statedump(struct ust_registry_session *session,
const struct ustctl_global_type_decl *global_type_decl = &event->global_type_decl[i];
ret = _lttng_one_global_type_statedump(session, global_type_decl);
+ DBG("_lttng_global_type_decl_statedump %d", ret);
if (ret)
return ret;
}
diff --git a/src/bin/lttng-sessiond/ust-registry.c b/src/bin/lttng-sessiond/ust-registry.c
index 281ea7c..80df17a 100644
--- a/src/bin/lttng-sessiond/ust-registry.c
+++ b/src/bin/lttng-sessiond/ust-registry.c
@@ -73,6 +73,49 @@ static unsigned long ht_hash_event(void *_key, unsigned long seed)
}
/*
+ * Hash table match function for global type declarations in the session.
+ */
+static int ht_match_global_type(struct cds_lfht_node *node, const void *_key)
+{
+ struct ust_registry_global_type_decl *global_type;
+ const struct ust_registry_global_type_decl *key;
+
+ assert(node);
+ assert(_key);
+
+ global_type = caa_container_of(node, struct ust_registry_global_type_decl, node.node);
+ assert(global_type);
+ key = _key;
+
+ /* It has to be a perfect match. */
+ if (global_type->category != key->category) {
+ goto no_match;
+ }
+ if (strncmp(global_type->name, key->name, strlen(global_type->name) != 0)) {
+ goto no_match;
+ }
+
+ /* Match */
+ return 1;
+
+no_match:
+ return 0;
+}
+
+static unsigned long ht_hash_global_type(void *_key, unsigned long seed)
+{
+ uint64_t xored_key;
+ struct ust_registry_global_type_decl *key = _key;
+
+ assert(key);
+
+ xored_key = (uint64_t) (hash_key_ulong((void *)key->category, seed) ^
+ hash_key_str(key->name, seed));
+
+ return hash_key_u64(&xored_key, seed);
+}
+
+/*
* Return negative value on error, 0 if OK.
*
* TODO: we could add stricter verification of more types to catch
@@ -570,6 +613,16 @@ 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->global_types_ht = 0;
+ session->global_types_ht = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
+ if (!session->global_types_ht) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ /* Set custom match function. */
+ session->global_types_ht->match_fct = ht_match_global_type;
+ session->global_types_ht->hash_fct = ht_hash_global_type;
session->channels = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
if (!session->channels) {
@@ -610,6 +663,7 @@ void ust_registry_session_destroy(struct ust_registry_session *reg)
int ret;
struct lttng_ht_iter iter;
struct ust_registry_channel *chan;
+ struct ust_registry_global_type_decl *global_type;
assert(reg);
@@ -632,4 +686,19 @@ void ust_registry_session_destroy(struct ust_registry_session *reg)
}
free(reg->metadata);
+
+ /* Destroy the global type hash table */
+ if (reg->global_types_ht) {
+ rcu_read_lock();
+ /* Destroy all global types associated with this registry. */
+ cds_lfht_for_each_entry(reg->global_types_ht->ht, &iter.iter, global_type,
+ node.node) {
+ /* Delete the node from the ht and free it. */
+ ret = lttng_ht_del(reg->global_types_ht, &iter);
+ assert(!ret);
+ free(global_type);
+ }
+ rcu_read_unlock();
+ ht_cleanup_push(reg->global_types_ht);
+ }
}
diff --git a/src/bin/lttng-sessiond/ust-registry.h b/src/bin/lttng-sessiond/ust-registry.h
index 8b41c2a..29bc120 100644
--- a/src/bin/lttng-sessiond/ust-registry.h
+++ b/src/bin/lttng-sessiond/ust-registry.h
@@ -31,6 +31,16 @@
struct ust_app;
+struct ust_registry_global_type_decl {
+ uint32_t category;
+ char name[LTTNG_UST_SYM_NAME_LEN];
+ /*
+ * Node in the ust-session hash table. The global type name and
+ * category is used to initialize the node and for the match function.
+ */
+ struct lttng_ht_node_u64 node;
+};
+
struct ust_registry_session {
/*
* With multiple writers and readers, use this lock to access the registry.
@@ -75,6 +85,11 @@ struct ust_registry_session {
* deletes its sessions.
*/
unsigned int metadata_closed;
+ /*
+ * Hash table containing global type declarations already dumped into the
+ * metadata. MUST be accessed with a RCU read side lock acquired.
+ */
+ struct lttng_ht *global_types_ht;
};
struct ust_registry_channel {
--
1.8.5.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [lttng-dev] [Patch LTTng-tools v2 5/5] Regression tests for global type declarations in UST
2014-02-11 21:40 ` [lttng-dev] LTTng-tools: Add support of global types and CTF enumerations Geneviève Bastien
` (3 preceding siblings ...)
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 4/5] Dump a global type only once per session Geneviève Bastien
@ 2014-02-11 21:40 ` Geneviève Bastien
4 siblings, 0 replies; 6+ messages in thread
From: Geneviève Bastien @ 2014-02-11 21:40 UTC (permalink / raw)
Signed-off-by: Genevi?ve Bastien <gbastien+lttng at versatic.net>
---
configure.ac | 1 +
tests/fast_regression | 1 +
tests/regression/test_list.py | 6 ++
tests/regression/ust/Makefile.am | 2 +-
.../ust/global-type-declarations/Makefile.am | 29 ++++++
.../regression/ust/global-type-declarations/README | 22 ++++
.../global-type-declarations.c | 37 +++++++
.../test_global_type_declarations | 37 +++++++
.../test_global_type_declarations.py | 114 +++++++++++++++++++++
.../ust/global-type-declarations/ust_tests_gtd.h | 67 ++++++++++++
10 files changed, 315 insertions(+), 1 deletion(-)
create mode 100644 tests/regression/ust/global-type-declarations/Makefile.am
create mode 100644 tests/regression/ust/global-type-declarations/README
create mode 100644 tests/regression/ust/global-type-declarations/global-type-declarations.c
create mode 100755 tests/regression/ust/global-type-declarations/test_global_type_declarations
create mode 100644 tests/regression/ust/global-type-declarations/test_global_type_declarations.py
create mode 100644 tests/regression/ust/global-type-declarations/ust_tests_gtd.h
diff --git a/configure.ac b/configure.ac
index 65503a3..2f720da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -437,6 +437,7 @@ AC_CONFIG_FILES([
tests/regression/ust/fork/Makefile
tests/regression/ust/libc-wrapper/Makefile
tests/regression/ust/java-jul/Makefile
+ tests/regression/ust/global-type-declarations/Makefile
tests/stress/Makefile
tests/unit/Makefile
tests/unit/ini_config/Makefile
diff --git a/tests/fast_regression b/tests/fast_regression
index 40acf5c..0331ace 100644
--- a/tests/fast_regression
+++ b/tests/fast_regression
@@ -19,3 +19,4 @@ regression/ust/overlap/test_overlap
regression/ust/java-jul/test_java_jul
regression/ust/test_event_basic
regression/ust/test_event_wildcard
+regression/ust/global-type-declarations/test_global_type_declarations
diff --git a/tests/regression/test_list.py b/tests/regression/test_list.py
index 21afa1c..ff5b00a 100755
--- a/tests/regression/test_list.py
+++ b/tests/regression/test_list.py
@@ -77,6 +77,12 @@ Tests = \
'desc': "Test tracing with 4 sessions for one application",
'success': 0, 'enabled': True
},
+ {
+ 'bin': "ust/global_type_declarations/run", 'daemon': True, 'kern': False,
+ 'name': "UST tracer - CTF global type declarations",
+ 'desc': "Test tracepoints using CTF global type declarations",
+ 'success': 0, 'enabled': True
+ },
# Tools filtering tests
{
diff --git a/tests/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am
index a4e3455..de71b60 100644
--- a/tests/regression/ust/Makefile.am
+++ b/tests/regression/ust/Makefile.am
@@ -1,7 +1,7 @@
if HAVE_LIBLTTNG_UST_CTL
SUBDIRS = nprocesses high-throughput low-throughput before-after multi-session \
overlap buffers-pid linking daemon exit-fast fork libc-wrapper \
- periodical-metadata-flush java-jul
+ periodical-metadata-flush java-jul global-type-declarations
EXTRA_DIST = test_event_basic test_event_wildcard
diff --git a/tests/regression/ust/global-type-declarations/Makefile.am b/tests/regression/ust/global-type-declarations/Makefile.am
new file mode 100644
index 0000000..7346931
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/Makefile.am
@@ -0,0 +1,29 @@
+AM_CPPFLAGS = -I$(srcdir)
+
+noinst_PROGRAMS = global-type-declarations
+global_type_declarations_SOURCES = global-type-declarations.c ust_tests_gtd.h
+global_type_declarations_LDADD = -llttng-ust
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+global_type_declarations_LDADD += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+global_type_declarations_LDADD += -lc
+endif
+
+noinst_SCRIPTS = test_global_type_declarations test_global_type_declarations.py
+EXTRA_DIST = test_global_type_declarations test_global_type_declarations.py
+
+all-local:
+ @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+ for script in $(EXTRA_DIST); do \
+ cp -f $(srcdir)/$$script $(builddir); \
+ done; \
+ fi
+
+clean-local:
+ @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+ for script in $(EXTRA_DIST); do \
+ rm -f $(builddir)/$$script; \
+ done; \
+ fi
diff --git a/tests/regression/ust/global-type-declarations/README b/tests/regression/ust/global-type-declarations/README
new file mode 100644
index 0000000..4523237
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/README
@@ -0,0 +1,22 @@
+Global type declarations test
+-----------------------------
+
+This test checks if tracepoints using global type declarations work correctly.
+
+DESCRIPTION
+-----------
+
+This test launches a process who generates events with fields using global type
+declarations.
+
+The test makes sure the events are present and the fields have all the
+correct data.
+
+DEPENDENCIES
+------------
+
+To run this test, you will need:
+
+ - lttng-tools (with python bindings)
+ - babeltrace
+ - python 3.0 or better
\ No newline at end of file
diff --git a/tests/regression/ust/global-type-declarations/global-type-declarations.c b/tests/regression/ust/global-type-declarations/global-type-declarations.c
new file mode 100644
index 0000000..edd6fc7
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/global-type-declarations.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2014 Genevi?ve Bastien <gbastien at versatic.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* This test generates a single event and exits.
+ */
+
+#include <unistd.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_tests_gtd.h"
+
+int main(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 0; i < 2; i++) {
+ tracepoint(ust_tests_gtd, tptest, i%2, (i+1)%2);
+ tracepoint(ust_tests_gtd, tptest_bis, i%2);
+ }
+
+ return 0;
+}
diff --git a/tests/regression/ust/global-type-declarations/test_global_type_declarations b/tests/regression/ust/global-type-declarations/test_global_type_declarations
new file mode 100755
index 0000000..cf22d0f
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/test_global_type_declarations
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Copyright (C) - 2014 Genevi?ve Bastien <gbastien at versatic.net>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+TEST_DESC="UST tracer - Test tracepoints using ctf global type declarations"
+
+
+# Check for a running sessiond
+`pidof lt-lttng-sessiond`
+STOP_SESSIOND=$?
+
+CURDIR=$(dirname $0)
+TESTDIR=${CURDIR}/../../..
+
+# Try to launch a sessiond before invoking the python test script
+if [ $STOP_SESSIOND -ne 0 ]; then
+ DIR=$(readlink -f ${TESTDIR})
+ ${DIR}/../src/bin/lttng-sessiond/lttng-sessiond --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
+fi
+
+python3 ${CURDIR}/test_global_type_declarations.py
+
+if [ $STOP_SESSIOND -ne 0 ]; then
+ kill `pidof lt-lttng-sessiond`
+fi
diff --git a/tests/regression/ust/global-type-declarations/test_global_type_declarations.py b/tests/regression/ust/global-type-declarations/test_global_type_declarations.py
new file mode 100644
index 0000000..e7a7c22
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/test_global_type_declarations.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) - 2014 Genevi?ve Bastien <gbastien at versatic.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import os
+import subprocess
+import re
+import shutil
+import sys
+
+test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
+test_utils_path = test_path
+for i in range(4):
+ test_utils_path = os.path.dirname(test_utils_path)
+test_utils_path = test_utils_path + "/utils"
+sys.path.append(test_utils_path)
+from test_utils import *
+
+NR_TESTS = 9
+current_test = 1
+print("1..{0}".format(NR_TESTS))
+
+# Check if a sessiond is running... bail out if none found.
+if session_daemon_alive() == 0:
+ bail("No sessiond running. Please make sure you are running this test with the \"run\" shell script and verify that the lttng tools are properly installed.")
+
+session_info = create_session()
+enable_ust_tracepoint_event(session_info, "ust_tests_gtd*")
+start_session(session_info)
+
+test_env = os.environ.copy()
+test_env["LTTNG_UST_REGISTER_TIMEOUT"] = "-1"
+
+gtd_process = subprocess.Popen(test_path + "global-type-declarations", stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=test_env)
+
+if sys.version_info >= (3, 3):
+ try:
+ gtd_process.wait(5)
+ except TimeoutExpired:
+ gtd_process.kill()
+ bail("Failed to run global-type-declarations test application.")
+else:
+ gtd_process.wait()
+
+print_test_result(gtd_process.returncode == 0, current_test, "Test application exited normally")
+current_test += 1
+
+stop_session(session_info)
+
+# Check event fields using global type declarations are present
+try:
+ babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+except FileNotFoundError:
+ bail("Could not open babeltrace. Please make sure it is installed.")
+
+event_lines = []
+for event_line in babeltrace_process.stdout:
+ event_line = event_line.decode('utf-8').replace("\n", "")
+ event_lines.append(event_line)
+babeltrace_process.wait()
+
+print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
+current_test += 1
+
+if babeltrace_process.returncode != 0:
+ bail("Unreadable trace; can't proceed with analysis.")
+
+print_test_result(len(event_lines) == 4, current_test, "Correct number of events found in resulting trace")
+current_test += 1
+
+if len(event_lines) != 4:
+ bail("Unexpected number of events found in resulting trace (" + session_info.trace_path + ")." )
+
+match = re.search(r".*ust_tests_gtd:(.*):.*enumfield = \( (.*) :.*enumfield_bis = \( (.*) :.*", event_lines[0])
+print_test_result(match is not None and match.group(1) == "tptest", current_test,\
+ "First tracepoint is present")
+current_test += 1
+
+print_test_result(match is not None and match.group(2) == "zero", current_test,\
+ "First tracepoint's enum value maps to zero")
+current_test += 1
+
+print_test_result(match is not None and match.group(3) == "one", current_test,\
+ "First tracepoint's second enum value maps to one")
+current_test += 1
+
+match = re.search(r".*ust_tests_gtd:(.*):.*enumfield = \( (.*) :.*", event_lines[1])
+print_test_result(match is not None and match.group(1) == "tptest_bis", current_test,\
+ "Second tracepoint is present")
+current_test += 1
+
+print_test_result(match is not None and match.group(2) == "zero", current_test,\
+ "Second tracepoint's enum value maps to zero")
+current_test += 1
+
+match = re.search(r".*ust_tests_gtd:(.*):.*enumfield = \( (.*) :.*enumfield_bis = \( (.*) .*", event_lines[2])
+
+print_test_result(match is not None and match.group(2) == "one", current_test,\
+ "Third tracepoint's enum value maps to one")
+
+shutil.rmtree(session_info.tmp_directory)
diff --git a/tests/regression/ust/global-type-declarations/ust_tests_gtd.h b/tests/regression/ust/global-type-declarations/ust_tests_gtd.h
new file mode 100644
index 0000000..186ffe9
--- /dev/null
+++ b/tests/regression/ust/global-type-declarations/ust_tests_gtd.h
@@ -0,0 +1,67 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_tests_gtd
+
+#if !defined(_TRACEPOINT_UST_TESTS_GLOBAL_TYPE_DECLARATIONS_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_TESTS_GLOBAL_TYPE_DECLARATIONS_H
+
+/*
+ * Copyright (C) 2014 Genevi?ve Bastien <gbastien at versatic.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_ENUM(ust_tests_gtd, testenum, int,
+ TP_ENUM_VALUES(
+ ctf_enum_value("zero", 0)
+ ctf_enum_value("one", 1)
+ )
+)
+
+/*
+ * Enumeration field is used twice to make sure the global type declaration
+ * is entered only once in the metadata file.
+ */
+TRACEPOINT_EVENT(ust_tests_gtd, tptest,
+ TP_ARGS(int, enumval, int, enumval2),
+ TP_FIELDS(
+ ctf_enum(ust_tests_gtd, testenum, enumfield, enumval)
+ ctf_enum(ust_tests_gtd, testenum, enumfield_bis, enumval2)
+ )
+)
+
+/*
+ * Another tracepoint using the global types to make sure each global type is
+ * entered only once in the metadata file.
+ */
+TRACEPOINT_EVENT(ust_tests_gtd, tptest_bis,
+ TP_ARGS(int, enumval),
+ TP_FIELDS(
+ ctf_enum(ust_tests_gtd, testenum, enumfield, enumval)
+ )
+)
+
+#endif /* _TRACEPOINT_UST_TESTS_GLOBAL_TYPE_DECLARATIONS_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_tests_gtd.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
--
1.8.5.4
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-02-11 21:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1390594045-7556-1-git-send-email-gbastien+lttng@versatic.net>
2014-02-11 21:40 ` [lttng-dev] LTTng-tools: Add support of global types and CTF enumerations Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 1/5] Update data structures to support CTF global type declarations Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 2/5] Receive the CTF global enumerations from ust by the session daemon Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 3/5] Statedump the metadata for CTF global enumerations Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 4/5] Dump a global type only once per session Geneviève Bastien
2014-02-11 21:40 ` [lttng-dev] [Patch LTTng-tools v2 5/5] Regression tests for global type declarations in UST Geneviève Bastien
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox