| 1 | /* |
| 2 | * ust-core.c |
| 3 | * |
| 4 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; only |
| 9 | * version 2.1 of the License. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #define _LGPL_SOURCE |
| 22 | #include <stdint.h> |
| 23 | #include <stddef.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <lttng/ust-events.h> |
| 26 | #include <usterr-signal-safe.h> |
| 27 | #include "lttng-tracer-core.h" |
| 28 | #include "jhash.h" |
| 29 | |
| 30 | static CDS_LIST_HEAD(lttng_transport_list); |
| 31 | static CDS_LIST_HEAD(lttng_counter_transport_list); |
| 32 | |
| 33 | struct lttng_transport *lttng_transport_find(const char *name) |
| 34 | { |
| 35 | struct lttng_transport *transport; |
| 36 | |
| 37 | cds_list_for_each_entry(transport, <tng_transport_list, node) { |
| 38 | if (!strcmp(transport->name, name)) |
| 39 | return transport; |
| 40 | } |
| 41 | return NULL; |
| 42 | } |
| 43 | |
| 44 | struct lttng_counter_transport *lttng_counter_transport_find(const char *name) |
| 45 | { |
| 46 | struct lttng_counter_transport *transport; |
| 47 | |
| 48 | cds_list_for_each_entry(transport, <tng_counter_transport_list, node) { |
| 49 | if (!strcmp(transport->name, name)) |
| 50 | return transport; |
| 51 | } |
| 52 | return NULL; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * lttng_transport_register - LTT transport registration |
| 57 | * @transport: transport structure |
| 58 | * |
| 59 | * Registers a transport which can be used as output to extract the data out of |
| 60 | * LTTng. Called with ust_lock held. |
| 61 | */ |
| 62 | void lttng_transport_register(struct lttng_transport *transport) |
| 63 | { |
| 64 | cds_list_add_tail(&transport->node, <tng_transport_list); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * lttng_transport_unregister - LTT transport unregistration |
| 69 | * @transport: transport structure |
| 70 | * Called with ust_lock held. |
| 71 | */ |
| 72 | void lttng_transport_unregister(struct lttng_transport *transport) |
| 73 | { |
| 74 | cds_list_del(&transport->node); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * lttng_counter_transport_register - LTTng counter transport registration |
| 79 | * @transport: transport structure |
| 80 | * |
| 81 | * Registers a counter transport which can be used as output to extract |
| 82 | * the data out of LTTng. Called with ust_lock held. |
| 83 | */ |
| 84 | void lttng_counter_transport_register(struct lttng_counter_transport *transport) |
| 85 | { |
| 86 | cds_list_add_tail(&transport->node, <tng_counter_transport_list); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * lttng_counter_transport_unregister - LTTng counter transport unregistration |
| 91 | * @transport: transport structure |
| 92 | * Called with ust_lock held. |
| 93 | */ |
| 94 | void lttng_counter_transport_unregister(struct lttng_counter_transport *transport) |
| 95 | { |
| 96 | cds_list_del(&transport->node); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Needed by comm layer. |
| 101 | */ |
| 102 | struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session, |
| 103 | const struct lttng_enum_desc *enum_desc) |
| 104 | { |
| 105 | struct lttng_enum *_enum; |
| 106 | struct cds_hlist_head *head; |
| 107 | struct cds_hlist_node *node; |
| 108 | size_t name_len = strlen(enum_desc->name); |
| 109 | uint32_t hash; |
| 110 | |
| 111 | hash = jhash(enum_desc->name, name_len, 0); |
| 112 | head = &session->enums_ht.table[hash & (LTTNG_UST_ENUM_HT_SIZE - 1)]; |
| 113 | cds_hlist_for_each_entry(_enum, node, head, hlist) { |
| 114 | assert(_enum->desc); |
| 115 | if (_enum->desc == enum_desc) |
| 116 | return _enum; |
| 117 | } |
| 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | size_t lttng_ust_dummy_get_size(struct lttng_ctx_field *field, size_t offset) |
| 122 | { |
| 123 | size_t size = 0; |
| 124 | |
| 125 | size += lib_ring_buffer_align(offset, lttng_alignof(char)); |
| 126 | size += sizeof(char); /* tag */ |
| 127 | return size; |
| 128 | } |
| 129 | |
| 130 | void lttng_ust_dummy_record(struct lttng_ctx_field *field, |
| 131 | struct lttng_ust_lib_ring_buffer_ctx *ctx, |
| 132 | struct lttng_channel *chan) |
| 133 | { |
| 134 | char sel_char = (char) LTTNG_UST_DYNAMIC_TYPE_NONE; |
| 135 | |
| 136 | lib_ring_buffer_align_ctx(ctx, lttng_alignof(sel_char)); |
| 137 | chan->ops->event_write(ctx, &sel_char, sizeof(sel_char)); |
| 138 | } |
| 139 | |
| 140 | void lttng_ust_dummy_get_value(struct lttng_ctx_field *field, |
| 141 | struct lttng_ctx_value *value) |
| 142 | { |
| 143 | value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE; |
| 144 | } |
| 145 | |
| 146 | int lttng_context_is_app(const char *name) |
| 147 | { |
| 148 | if (strncmp(name, "$app.", strlen("$app.")) != 0) { |
| 149 | return 0; |
| 150 | } |
| 151 | return 1; |
| 152 | } |