| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License, version 2 only, |
| 6 | * as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | |
| 18 | #ifndef _LTT_TRACE_UST_H |
| 19 | #define _LTT_TRACE_UST_H |
| 20 | |
| 21 | #include <config.h> |
| 22 | #include <limits.h> |
| 23 | #include <urcu/list.h> |
| 24 | |
| 25 | #include <lttng/lttng.h> |
| 26 | #include <common/hashtable/hashtable.h> |
| 27 | #include <common/defaults.h> |
| 28 | |
| 29 | #include "consumer.h" |
| 30 | #include "ust-ctl.h" |
| 31 | |
| 32 | struct ltt_ust_ht_key { |
| 33 | const char *name; |
| 34 | const struct lttng_filter_bytecode *filter; |
| 35 | enum lttng_ust_loglevel_type loglevel; |
| 36 | }; |
| 37 | |
| 38 | /* Context hash table nodes */ |
| 39 | struct ltt_ust_context { |
| 40 | struct lttng_ust_context ctx; |
| 41 | struct lttng_ht_node_ulong node; |
| 42 | }; |
| 43 | |
| 44 | /* UST event */ |
| 45 | struct ltt_ust_event { |
| 46 | unsigned int enabled; |
| 47 | struct lttng_ust_event attr; |
| 48 | struct lttng_ht_node_str node; |
| 49 | struct lttng_ust_filter_bytecode *filter; |
| 50 | }; |
| 51 | |
| 52 | /* UST channel */ |
| 53 | struct ltt_ust_channel { |
| 54 | unsigned int enabled; |
| 55 | char name[LTTNG_UST_SYM_NAME_LEN]; |
| 56 | char pathname[PATH_MAX]; |
| 57 | struct lttng_ust_channel attr; |
| 58 | struct lttng_ht *ctx; |
| 59 | struct lttng_ht *events; |
| 60 | struct lttng_ht_node_str node; |
| 61 | }; |
| 62 | |
| 63 | /* UST Metadata */ |
| 64 | struct ltt_ust_metadata { |
| 65 | int handle; |
| 66 | struct lttng_ust_object_data *obj; |
| 67 | char pathname[PATH_MAX]; /* Trace file path name */ |
| 68 | struct lttng_ust_channel attr; |
| 69 | struct lttng_ust_object_data *stream_obj; |
| 70 | }; |
| 71 | |
| 72 | /* UST domain global (LTTNG_DOMAIN_UST) */ |
| 73 | struct ltt_ust_domain_global { |
| 74 | struct lttng_ht *channels; |
| 75 | }; |
| 76 | |
| 77 | /* UST domain pid (LTTNG_DOMAIN_UST_PID) */ |
| 78 | struct ltt_ust_domain_pid { |
| 79 | pid_t pid; |
| 80 | struct lttng_ht *channels; |
| 81 | struct lttng_ht_node_ulong node; |
| 82 | }; |
| 83 | |
| 84 | /* UST domain exec name (LTTNG_DOMAIN_UST_EXEC_NAME) */ |
| 85 | struct ltt_ust_domain_exec { |
| 86 | char exec_name[LTTNG_UST_SYM_NAME_LEN]; |
| 87 | struct lttng_ht *channels; |
| 88 | struct lttng_ht_node_str node; |
| 89 | }; |
| 90 | |
| 91 | /* UST session */ |
| 92 | struct ltt_ust_session { |
| 93 | int id; /* Unique identifier of session */ |
| 94 | int start_trace; |
| 95 | char pathname[PATH_MAX]; |
| 96 | struct ltt_ust_domain_global domain_global; |
| 97 | /* |
| 98 | * Those two hash tables contains data for a specific UST domain and each |
| 99 | * contains a HT of channels. See ltt_ust_domain_exec and |
| 100 | * ltt_ust_domain_pid data structures. |
| 101 | */ |
| 102 | struct lttng_ht *domain_pid; |
| 103 | struct lttng_ht *domain_exec; |
| 104 | /* UID/GID of the user owning the session */ |
| 105 | uid_t uid; |
| 106 | gid_t gid; |
| 107 | /* |
| 108 | * Two consumer_output object are needed where one is for the current |
| 109 | * output object and the second one is the temporary object used to store |
| 110 | * URI being set by the lttng_set_consumer_uri call. Once |
| 111 | * lttng_enable_consumer is called, the two pointers are swapped. |
| 112 | */ |
| 113 | struct consumer_output *consumer; |
| 114 | struct consumer_output *tmp_consumer; |
| 115 | /* Sequence number for filters so the tracer knows the ordering. */ |
| 116 | uint64_t filter_seq_num; |
| 117 | }; |
| 118 | |
| 119 | #ifdef HAVE_LIBLTTNG_UST_CTL |
| 120 | |
| 121 | int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key); |
| 122 | int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, |
| 123 | const void *_key); |
| 124 | |
| 125 | /* |
| 126 | * Lookup functions. NULL is returned if not found. |
| 127 | */ |
| 128 | struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, |
| 129 | char *name, struct lttng_filter_bytecode *filter, int loglevel); |
| 130 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
| 131 | char *name); |
| 132 | |
| 133 | /* |
| 134 | * Create functions malloc() the data structure. |
| 135 | */ |
| 136 | struct ltt_ust_session *trace_ust_create_session(char *path, |
| 137 | unsigned int session_id, struct lttng_domain *domain); |
| 138 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
| 139 | char *path); |
| 140 | struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev, |
| 141 | struct lttng_filter_bytecode *filter); |
| 142 | struct ltt_ust_metadata *trace_ust_create_metadata(char *path); |
| 143 | struct ltt_ust_context *trace_ust_create_context( |
| 144 | struct lttng_event_context *ctx); |
| 145 | |
| 146 | /* |
| 147 | * Destroy functions free() the data structure and remove from linked list if |
| 148 | * it's applies. |
| 149 | */ |
| 150 | void trace_ust_destroy_session(struct ltt_ust_session *session); |
| 151 | void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata); |
| 152 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel); |
| 153 | void trace_ust_destroy_event(struct ltt_ust_event *event); |
| 154 | |
| 155 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
| 156 | |
| 157 | static inline int trace_ust_ht_match_event(struct cds_lfht_node *node, |
| 158 | const void *_key) |
| 159 | { |
| 160 | return 0; |
| 161 | } |
| 162 | static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, |
| 163 | const void *_key) |
| 164 | { |
| 165 | return 0; |
| 166 | } |
| 167 | static inline |
| 168 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
| 169 | char *name) |
| 170 | { |
| 171 | return NULL; |
| 172 | } |
| 173 | |
| 174 | static inline |
| 175 | struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid, |
| 176 | struct lttng_domain *domain) |
| 177 | { |
| 178 | return NULL; |
| 179 | } |
| 180 | static inline |
| 181 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
| 182 | char *path) |
| 183 | { |
| 184 | return NULL; |
| 185 | } |
| 186 | static inline |
| 187 | struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev, |
| 188 | struct lttng_filter_bytecode *filter) |
| 189 | { |
| 190 | return NULL; |
| 191 | } |
| 192 | static inline |
| 193 | struct ltt_ust_metadata *trace_ust_create_metadata(char *path) |
| 194 | { |
| 195 | return NULL; |
| 196 | } |
| 197 | |
| 198 | static inline |
| 199 | void trace_ust_destroy_session(struct ltt_ust_session *session) |
| 200 | { |
| 201 | } |
| 202 | |
| 203 | static inline |
| 204 | void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata) |
| 205 | { |
| 206 | } |
| 207 | |
| 208 | static inline |
| 209 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel) |
| 210 | { |
| 211 | } |
| 212 | |
| 213 | static inline |
| 214 | void trace_ust_destroy_event(struct ltt_ust_event *event) |
| 215 | { |
| 216 | } |
| 217 | static inline |
| 218 | struct ltt_ust_context *trace_ust_create_context( |
| 219 | struct lttng_event_context *ctx) |
| 220 | { |
| 221 | return NULL; |
| 222 | } |
| 223 | static inline struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, |
| 224 | char *name, struct lttng_filter_bytecode *filter, int loglevel) |
| 225 | { |
| 226 | return NULL; |
| 227 | } |
| 228 | |
| 229 | #endif /* HAVE_LIBLTTNG_UST_CTL */ |
| 230 | |
| 231 | #endif /* _LTT_TRACE_UST_H */ |