From 06d4f27ebd73d4335d4365468798fc72904b30c6 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 8 May 2012 08:13:02 -0400 Subject: [PATCH] Implement field listing command Signed-off-by: Mathieu Desnoyers --- include/lttng/ust-abi.h | 19 ++++++++ include/lttng/ust-events.h | 14 ++++++ liblttng-ust/ltt-probes.c | 83 +++++++++++++++++++++++++++++++++ liblttng-ust/lttng-ust-abi.c | 90 ++++++++++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+) diff --git a/include/lttng/ust-abi.h b/include/lttng/ust-abi.h index b3af9bf4..898d6cfe 100644 --- a/include/lttng/ust-abi.h +++ b/include/lttng/ust-abi.h @@ -85,6 +85,23 @@ struct lttng_ust_event { } u; }; +enum lttng_ust_field_type { + LTTNG_UST_FIELD_OTHER = 0, + LTTNG_UST_FIELD_INTEGER = 1, + LTTNG_UST_FIELD_ENUM = 2, + LTTNG_UST_FIELD_FLOAT = 3, + LTTNG_UST_FIELD_STRING = 4, +}; + +#define LTTNG_UST_FIELD_ITER_PADDING LTTNG_UST_SYM_NAME_LEN + 32 +struct lttng_ust_field_iter { + char event_name[LTTNG_UST_SYM_NAME_LEN]; + char field_name[LTTNG_UST_SYM_NAME_LEN]; + enum lttng_ust_field_type type; + int loglevel; /* event loglevel */ + char padding[LTTNG_UST_FIELD_ITER_PADDING]; +}; + enum lttng_ust_context_type { LTTNG_UST_CONTEXT_VTID = 0, LTTNG_UST_CONTEXT_VPID = 1, @@ -164,6 +181,7 @@ struct lttng_ust_calibrate { #define LTTNG_UST_TRACEPOINT_LIST _UST_CMD(0x42) #define LTTNG_UST_WAIT_QUIESCENT _UST_CMD(0x43) #define LTTNG_UST_REGISTER_DONE _UST_CMD(0x44) +#define LTTNG_UST_TRACEPOINT_FIELD_LIST _UST_CMD(0x45) /* Session FD commands */ #define LTTNG_UST_METADATA \ @@ -190,6 +208,7 @@ struct lttng_ust_calibrate { /* Tracepoint list commands */ #define LTTNG_UST_TRACEPOINT_LIST_GET _UST_CMD(0x90) +#define LTTNG_UST_TRACEPOINT_FIELD_LIST_GET _UST_CMD(0x91) #define LTTNG_UST_ROOT_HANDLE 0 diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 65f50236..9c015821 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -271,6 +271,16 @@ struct lttng_ust_tracepoint_list { struct cds_list_head head; }; +struct tp_field_list_entry { + struct lttng_ust_field_iter field; + struct cds_list_head head; +}; + +struct lttng_ust_field_list { + struct tp_field_list_entry *iter; + struct cds_list_head head; +}; + struct ust_pending_probe; /* @@ -444,6 +454,10 @@ int ltt_probes_get_event_list(struct lttng_ust_tracepoint_list *list); void ltt_probes_prune_event_list(struct lttng_ust_tracepoint_list *list); struct lttng_ust_tracepoint_iter * lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list); +int ltt_probes_get_field_list(struct lttng_ust_field_list *list); +void ltt_probes_prune_field_list(struct lttng_ust_field_list *list); +struct lttng_ust_field_iter * + lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list); int ltt_wildcard_enable(struct session_wildcard *wildcard); int ltt_wildcard_disable(struct session_wildcard *wildcard); diff --git a/liblttng-ust/ltt-probes.c b/liblttng-ust/ltt-probes.c index 02df21b2..3d6b1414 100644 --- a/liblttng-ust/ltt-probes.c +++ b/liblttng-ust/ltt-probes.c @@ -219,6 +219,89 @@ struct lttng_ust_tracepoint_iter * return &entry->tp; } +void ltt_probes_prune_field_list(struct lttng_ust_field_list *list) +{ + struct tp_field_list_entry *list_entry, *tmp; + + cds_list_for_each_entry_safe(list_entry, tmp, &list->head, head) { + cds_list_del(&list_entry->head); + free(list_entry); + } +} + +/* + * called with UST lock held. + */ +int ltt_probes_get_field_list(struct lttng_ust_field_list *list) +{ + struct lttng_probe_desc *probe_desc; + int i; + + CDS_INIT_LIST_HEAD(&list->head); + cds_list_for_each_entry(probe_desc, &probe_list, head) { + for (i = 0; i < probe_desc->nr_events; i++) { + const struct lttng_event_desc *event_desc = + probe_desc->event_desc[i]; + int j; + + for (j = 0; j < event_desc->nr_fields; j++) { + const struct lttng_event_field *event_field = + &event_desc->fields[j]; + struct tp_field_list_entry *list_entry; + + list_entry = zmalloc(sizeof(*list_entry)); + if (!list_entry) + goto err_nomem; + cds_list_add(&list_entry->head, &list->head); + strncpy(list_entry->field.event_name, + event_desc->name, + LTTNG_UST_SYM_NAME_LEN); + list_entry->field.event_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; + strncpy(list_entry->field.field_name, + event_field->name, + LTTNG_UST_SYM_NAME_LEN); + list_entry->field.field_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; + if (!event_desc->loglevel) { + list_entry->field.loglevel = TRACE_DEFAULT; + } else { + list_entry->field.loglevel = *(*event_desc->loglevel); + } + } + } + } + if (cds_list_empty(&list->head)) + list->iter = NULL; + else + list->iter = + cds_list_first_entry(&list->head, + struct tp_field_list_entry, head); + return 0; + +err_nomem: + ltt_probes_prune_field_list(list); + return -ENOMEM; +} + +/* + * Return current iteration position, advance internal iterator to next. + * Return NULL if end of list. + */ +struct lttng_ust_field_iter * + lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list) +{ + struct tp_field_list_entry *entry; + + if (!list->iter) + return NULL; + entry = list->iter; + if (entry->head.next == &list->head) + list->iter = NULL; + else + list->iter = cds_list_entry(entry->head.next, + struct tp_field_list_entry, head); + return &entry->field; +} + /* * marshall all probes/all events and create those that fit the * wildcard. Add them to the events list as created. diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 435763d7..c16a617c 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -52,6 +52,8 @@ static int lttng_ust_abi_close_in_progress; static int lttng_abi_tracepoint_list(void); +static +int lttng_abi_tracepoint_field_list(void); /* * Object descriptor table. Should be protected from concurrent access @@ -220,6 +222,7 @@ static const struct lttng_ust_objd_ops lttng_event_ops; static const struct lttng_ust_objd_ops lttng_wildcard_ops; static const struct lttng_ust_objd_ops lib_ring_buffer_objd_ops; static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops; +static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops; enum channel_type { PER_CPU_CHANNEL, @@ -303,6 +306,8 @@ long lttng_abi_add_context(int objd, * Returns the LTTng kernel tracer version * LTTNG_UST_TRACEPOINT_LIST * Returns a file descriptor listing available tracepoints + * LTTNG_UST_TRACEPOINT_FIELD_LIST + * Returns a file descriptor listing available tracepoint fields * LTTNG_UST_WAIT_QUIESCENT * Returns after all previously running probes have completed * @@ -320,6 +325,8 @@ long lttng_cmd(int objd, unsigned int cmd, unsigned long arg, (struct lttng_ust_tracer_version *) arg); case LTTNG_UST_TRACEPOINT_LIST: return lttng_abi_tracepoint_list(); + case LTTNG_UST_TRACEPOINT_FIELD_LIST: + return lttng_abi_tracepoint_field_list(); case LTTNG_UST_WAIT_QUIESCENT: synchronize_trace(); return 0; @@ -602,6 +609,89 @@ static const struct lttng_ust_objd_ops lttng_tracepoint_list_ops = { .cmd = lttng_tracepoint_list_cmd, }; +static +long lttng_tracepoint_field_list_cmd(int objd, unsigned int cmd, + unsigned long arg, union ust_args *uargs) +{ + struct lttng_ust_field_list *list = objd_private(objd); + struct lttng_ust_field_iter *tp = + (struct lttng_ust_field_iter *) arg; + struct lttng_ust_field_iter *iter; + + switch (cmd) { + case LTTNG_UST_TRACEPOINT_FIELD_LIST_GET: + { + retry: + iter = lttng_ust_field_list_get_iter_next(list); + if (!iter) + return -ENOENT; + if (!strcmp(iter->event_name, "lttng_ust:metadata")) + goto retry; + memcpy(tp, iter, sizeof(*tp)); + return 0; + } + default: + return -EINVAL; + } +} + +static +int lttng_abi_tracepoint_field_list(void) +{ + int list_objd, ret; + struct lttng_ust_field_list *list; + + list_objd = objd_alloc(NULL, <tng_tracepoint_field_list_ops); + if (list_objd < 0) { + ret = list_objd; + goto objd_error; + } + list = zmalloc(sizeof(*list)); + if (!list) { + ret = -ENOMEM; + goto alloc_error; + } + objd_set_private(list_objd, list); + + /* populate list by walking on all registered probes. */ + ret = ltt_probes_get_field_list(list); + if (ret) { + goto list_error; + } + return list_objd; + +list_error: + free(list); +alloc_error: + { + int err; + + err = lttng_ust_objd_unref(list_objd); + assert(!err); + } +objd_error: + return ret; +} + +static +int lttng_release_tracepoint_field_list(int objd) +{ + struct lttng_ust_field_list *list = objd_private(objd); + + if (list) { + ltt_probes_prune_field_list(list); + free(list); + return 0; + } else { + return -EINVAL; + } +} + +static const struct lttng_ust_objd_ops lttng_tracepoint_field_list_ops = { + .release = lttng_release_tracepoint_field_list, + .cmd = lttng_tracepoint_field_list_cmd, +}; + struct stream_priv_data { struct lttng_ust_lib_ring_buffer *buf; struct ltt_channel *ltt_chan; -- 2.34.1