X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Fltt-events.c;h=ab099e1aba89afedb6a9456c0768509277500a8c;hb=b9d1a0083deb8ae2deb9e24a167590b70aec1b72;hp=4a0981b630f14bc1691a3f943f86d51f139d37c7;hpb=f194f3b00d042154c35f1f9ec262e25f2cd83b8a;p=lttng-ust.git diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index 4a0981b6..ab099e1a 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -1,11 +1,23 @@ /* * ltt-events.c * - * Copyright 2010 (c) - Mathieu Desnoyers - * * Holds LTTng per-session event registry. * - * Dual LGPL v2.1/GPL v2 license. + * Copyright (C) 2010-2012 Mathieu Desnoyers + * + * 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; only + * 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 */ #define _GNU_SOURCE @@ -167,20 +179,20 @@ int add_pending_probe(struct ltt_event *event, const char *name, { struct cds_hlist_head *head; struct ust_pending_probe *e; - size_t name_len = strlen(name); + size_t name_len = strlen(name) + 1; uint32_t hash; - if (name_len > LTTNG_UST_SYM_NAME_LEN - 1) { - WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN - 1); - name_len = LTTNG_UST_SYM_NAME_LEN - 1; + if (name_len > LTTNG_UST_SYM_NAME_LEN) { + WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN); + name_len = LTTNG_UST_SYM_NAME_LEN; } - hash = jhash(name, name_len, 0); + hash = jhash(name, name_len - 1, 0); head = &pending_probe_table[hash & (PENDING_PROBE_HASH_SIZE - 1)]; e = zmalloc(sizeof(struct ust_pending_probe) + name_len); if (!e) return -ENOMEM; - memcpy(&e->name[0], name, name_len + 1); - e->name[name_len] = '\0'; + memcpy(&e->name[0], name, name_len); + e->name[name_len - 1] = '\0'; e->loglevel_type = loglevel_type; e->loglevel = loglevel; cds_hlist_add_head(&e->node, head); @@ -216,7 +228,7 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc) const char *name = desc->name; int ret = 0; struct lttng_ust_event event_param; - size_t name_len = strlen(name); + size_t name_len = strlen(name) + 1; uint32_t hash; /* Wildcard */ @@ -239,23 +251,24 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc) sizeof(event_param.name)); /* create event */ ret = ltt_event_create(sw->chan, - &event_param, NULL, - &ev); + &event_param, &ev); if (ret) { DBG("Error creating event"); continue; } cds_list_add(&ev->wildcard_list, &sw->events); + lttng_filter_event_link_bytecode(ev, + sw->filter_bytecode); } } } - if (name_len > LTTNG_UST_SYM_NAME_LEN - 1) { - WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN - 1); - name_len = LTTNG_UST_SYM_NAME_LEN - 1; + if (name_len > LTTNG_UST_SYM_NAME_LEN) { + WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name, LTTNG_UST_SYM_NAME_LEN); + name_len = LTTNG_UST_SYM_NAME_LEN; } - hash = jhash(name, name_len, 0); + hash = jhash(name, name_len - 1, 0); head = &pending_probe_table[hash & (PENDING_PROBE_HASH_SIZE - 1)]; cds_hlist_for_each_entry_safe(e, node, p, head, node) { struct ltt_event *event; @@ -277,12 +290,14 @@ int pending_probe_fix_events(const struct lttng_event_desc *desc) remove_pending_probe(e); ret |= __tracepoint_probe_register(name, event->desc->probe_callback, - event); + event, event->desc->signature); if (ret) continue; event->id = chan->free_event_id++; ret |= _ltt_event_metadata_statedump(chan->session, chan, event); + lttng_filter_event_link_bytecode(event, + event->filter_bytecode); } return ret; } @@ -455,7 +470,7 @@ struct ltt_channel *ltt_channel_create(struct ltt_session *session, * headers. Therefore the "chan" information used as input * should be already accessible. */ - chan = transport->ops.channel_create("[lttng]", buf_addr, + chan = transport->ops.channel_create(transport_name, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, read_timer_interval, shm_fd, wait_fd, memory_map_size, chan_priv_init); @@ -488,14 +503,13 @@ void _ltt_channel_destroy(struct ltt_channel *chan) */ int ltt_event_create(struct ltt_channel *chan, struct lttng_ust_event *event_param, - void *filter, struct ltt_event **_event) { const struct lttng_event_desc *desc = NULL; /* silence gcc */ struct ltt_event *event; int ret = 0; - if (chan->used_event_id == -1UL) { + if (chan->used_event_id == -1U) { ret = -ENOMEM; goto full; } @@ -536,7 +550,6 @@ int ltt_event_create(struct ltt_channel *chan, goto cache_error; } event->chan = chan; - event->filter = filter; /* * used_event_id counts the maximum number of event IDs that can * register if all probes register. @@ -552,7 +565,7 @@ int ltt_event_create(struct ltt_channel *chan, if (event->desc) { ret = __tracepoint_probe_register(event_param->name, event->desc->probe_callback, - event); + event, event->desc->signature); if (ret) goto register_error; event->id = chan->free_event_id++; @@ -641,6 +654,8 @@ void _ltt_event_destroy(struct ltt_event *event) } cds_list_del(&event->list); lttng_destroy_context(event->ctx); + free(event->filter_bytecode); + free(event->filter_data); free(event); } @@ -711,6 +726,9 @@ int _ltt_field_statedump(struct ltt_session *session, { int ret = 0; + if (field->nowrite) + return 0; + switch (field->type.atype) { case atype_integer: ret = lttng_metadata_printf(session, @@ -1008,7 +1026,7 @@ int _ltt_stream_packet_context_declare(struct ltt_session *session) "struct packet_context {\n" " uint64_clock_monotonic_t timestamp_begin;\n" " uint64_clock_monotonic_t timestamp_end;\n" - " uint32_t events_discarded;\n" + " unsigned long events_discarded;\n" " uint32_t content_size;\n" " uint32_t packet_size;\n" " uint32_t cpu_id;\n" @@ -1078,7 +1096,7 @@ uint64_t measure_clock_offset(void) return 0; monotonic[1] = trace_clock_read64(); offset = (monotonic[0] + monotonic[1]) >> 1; - realtime = rts.tv_sec * 1000000000ULL; + realtime = (uint64_t) rts.tv_sec * 1000000000ULL; realtime += rts.tv_nsec; offset = realtime - offset; return offset; @@ -1097,6 +1115,7 @@ int _ltt_session_metadata_statedump(struct ltt_session *session) struct ltt_event *event; int ret = 0; char procname[LTTNG_UST_PROCNAME_LEN] = ""; + char hostname[HOST_NAME_MAX]; if (!CMM_ACCESS_ONCE(session->active)) return 0; @@ -1119,6 +1138,7 @@ int _ltt_session_metadata_statedump(struct ltt_session *session) "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n" "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n" "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n" + "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n" "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n" "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n" "\n" @@ -1137,6 +1157,8 @@ int _ltt_session_metadata_statedump(struct ltt_session *session) lttng_alignof(uint16_t) * CHAR_BIT, lttng_alignof(uint32_t) * CHAR_BIT, lttng_alignof(uint64_t) * CHAR_BIT, + sizeof(unsigned long) * CHAR_BIT, + lttng_alignof(unsigned long) * CHAR_BIT, CTF_SPEC_MAJOR, CTF_SPEC_MINOR, uuid_s, @@ -1150,10 +1172,15 @@ int _ltt_session_metadata_statedump(struct ltt_session *session) goto end; /* ignore error, just use empty string if error. */ + hostname[0] = '\0'; + ret = gethostname(hostname, sizeof(hostname)); + if (ret && errno == ENAMETOOLONG) + hostname[HOST_NAME_MAX - 1] = '\0'; lttng_ust_getprocname(procname); procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0'; ret = lttng_metadata_printf(session, "env {\n" + " hostname = \"%s\";\n" " vpid = %d;\n" " procname = \"%s\";\n" " domain = \"ust\";\n" @@ -1162,6 +1189,7 @@ int _ltt_session_metadata_statedump(struct ltt_session *session) " tracer_minor = %u;\n" " tracer_patchlevel = %u;\n" "};\n\n", + hostname, (int) getpid(), procname, LTTNG_UST_MAJOR_VERSION, @@ -1347,6 +1375,8 @@ struct session_wildcard *add_wildcard(struct ltt_channel *chan, if (!e) return ERR_PTR(-ENOMEM); memcpy(&e->name[0], event_param->name, name_len); + e->loglevel_type = event_param->loglevel_type; + e->loglevel = event_param->loglevel; cds_list_add(&e->list, &wildcard_list); CDS_INIT_LIST_HEAD(&e->session_list); } @@ -1400,6 +1430,7 @@ void _remove_wildcard(struct session_wildcard *wildcard) cds_list_del(&wildcard->entry->list); free(wildcard->entry); } + free(wildcard->filter_bytecode); free(wildcard); } @@ -1458,3 +1489,16 @@ int ltt_wildcard_disable(struct session_wildcard *wildcard) wildcard->enabled = 0; return 0; } + +/* + * Take the TLS "fault" in libuuid if dlopen'd, which can take the + * dynamic linker mutex, outside of the UST lock, since the UST lock is + * taken in constructors, which are called with dynamic linker mutex + * held. + */ +void lttng_fixup_event_tls(void) +{ + unsigned char uuid[LTTNG_UST_UUID_STR_LEN]; + + (void) lttng_ust_uuid_generate(uuid); +}