| 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 | /* UST Stream list */ |
| 39 | struct ltt_ust_stream_list { |
| 40 | unsigned int count; |
| 41 | struct cds_list_head head; |
| 42 | }; |
| 43 | |
| 44 | /* Context hash table nodes */ |
| 45 | struct ltt_ust_context { |
| 46 | struct lttng_ust_context ctx; |
| 47 | struct lttng_ht_node_ulong node; |
| 48 | }; |
| 49 | |
| 50 | /* UST event */ |
| 51 | struct ltt_ust_event { |
| 52 | unsigned int enabled; |
| 53 | struct lttng_ust_event attr; |
| 54 | struct lttng_ht_node_str node; |
| 55 | struct lttng_ust_filter_bytecode *filter; |
| 56 | }; |
| 57 | |
| 58 | /* UST stream */ |
| 59 | struct ltt_ust_stream { |
| 60 | int handle; |
| 61 | char pathname[PATH_MAX]; |
| 62 | /* Format is %s_%d respectively channel name and CPU number. */ |
| 63 | char name[DEFAULT_STREAM_NAME_LEN]; |
| 64 | struct lttng_ust_object_data *obj; |
| 65 | /* Using a list of streams to keep order. */ |
| 66 | struct cds_list_head list; |
| 67 | }; |
| 68 | |
| 69 | /* UST channel */ |
| 70 | struct ltt_ust_channel { |
| 71 | unsigned int enabled; |
| 72 | char name[LTTNG_UST_SYM_NAME_LEN]; |
| 73 | char pathname[PATH_MAX]; |
| 74 | struct lttng_ust_channel attr; |
| 75 | struct lttng_ht *ctx; |
| 76 | struct lttng_ht *events; |
| 77 | struct lttng_ht_node_str node; |
| 78 | }; |
| 79 | |
| 80 | /* UST Metadata */ |
| 81 | struct ltt_ust_metadata { |
| 82 | int handle; |
| 83 | struct lttng_ust_object_data *obj; |
| 84 | char pathname[PATH_MAX]; /* Trace file path name */ |
| 85 | struct lttng_ust_channel attr; |
| 86 | struct lttng_ust_object_data *stream_obj; |
| 87 | }; |
| 88 | |
| 89 | /* UST domain global (LTTNG_DOMAIN_UST) */ |
| 90 | struct ltt_ust_domain_global { |
| 91 | struct lttng_ht *channels; |
| 92 | }; |
| 93 | |
| 94 | /* UST domain pid (LTTNG_DOMAIN_UST_PID) */ |
| 95 | struct ltt_ust_domain_pid { |
| 96 | pid_t pid; |
| 97 | struct lttng_ht *channels; |
| 98 | struct lttng_ht_node_ulong node; |
| 99 | }; |
| 100 | |
| 101 | /* UST domain exec name (LTTNG_DOMAIN_UST_EXEC_NAME) */ |
| 102 | struct ltt_ust_domain_exec { |
| 103 | char exec_name[LTTNG_UST_SYM_NAME_LEN]; |
| 104 | struct lttng_ht *channels; |
| 105 | struct lttng_ht_node_str node; |
| 106 | }; |
| 107 | |
| 108 | /* UST session */ |
| 109 | struct ltt_ust_session { |
| 110 | int id; /* Unique identifier of session */ |
| 111 | int start_trace; |
| 112 | char pathname[PATH_MAX]; |
| 113 | struct ltt_ust_domain_global domain_global; |
| 114 | /* |
| 115 | * Those two hash tables contains data for a specific UST domain and each |
| 116 | * contains a HT of channels. See ltt_ust_domain_exec and |
| 117 | * ltt_ust_domain_pid data structures. |
| 118 | */ |
| 119 | struct lttng_ht *domain_pid; |
| 120 | struct lttng_ht *domain_exec; |
| 121 | /* UID/GID of the user owning the session */ |
| 122 | uid_t uid; |
| 123 | gid_t gid; |
| 124 | /* |
| 125 | * Two consumer_output object are needed where one is for the current |
| 126 | * output object and the second one is the temporary object used to store |
| 127 | * URI being set by the lttng_set_consumer_uri call. Once |
| 128 | * lttng_enable_consumer is called, the two pointers are swapped. |
| 129 | */ |
| 130 | struct consumer_output *consumer; |
| 131 | struct consumer_output *tmp_consumer; |
| 132 | /* Sequence number for filters so the tracer knows the ordering. */ |
| 133 | uint64_t filter_seq_num; |
| 134 | }; |
| 135 | |
| 136 | #ifdef HAVE_LIBLTTNG_UST_CTL |
| 137 | |
| 138 | int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key); |
| 139 | int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, |
| 140 | const void *_key); |
| 141 | |
| 142 | /* |
| 143 | * Lookup functions. NULL is returned if not found. |
| 144 | */ |
| 145 | struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, |
| 146 | char *name, struct lttng_filter_bytecode *filter, int loglevel); |
| 147 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
| 148 | char *name); |
| 149 | |
| 150 | /* |
| 151 | * Create functions malloc() the data structure. |
| 152 | */ |
| 153 | struct ltt_ust_session *trace_ust_create_session(char *path, |
| 154 | unsigned int session_id, struct lttng_domain *domain); |
| 155 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
| 156 | char *path); |
| 157 | struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev, |
| 158 | struct lttng_filter_bytecode *filter); |
| 159 | struct ltt_ust_metadata *trace_ust_create_metadata(char *path); |
| 160 | struct ltt_ust_context *trace_ust_create_context( |
| 161 | struct lttng_event_context *ctx); |
| 162 | |
| 163 | /* |
| 164 | * Destroy functions free() the data structure and remove from linked list if |
| 165 | * it's applies. |
| 166 | */ |
| 167 | void trace_ust_destroy_session(struct ltt_ust_session *session); |
| 168 | void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata); |
| 169 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel); |
| 170 | void trace_ust_destroy_event(struct ltt_ust_event *event); |
| 171 | |
| 172 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
| 173 | |
| 174 | static inline int trace_ust_ht_match_event(struct cds_lfht_node *node, |
| 175 | const void *_key) |
| 176 | { |
| 177 | return 0; |
| 178 | } |
| 179 | static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, |
| 180 | const void *_key) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
| 184 | static inline |
| 185 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
| 186 | char *name) |
| 187 | { |
| 188 | return NULL; |
| 189 | } |
| 190 | |
| 191 | static inline |
| 192 | struct ltt_ust_session *trace_ust_create_session(char *path, pid_t pid, |
| 193 | struct lttng_domain *domain) |
| 194 | { |
| 195 | return NULL; |
| 196 | } |
| 197 | static inline |
| 198 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
| 199 | char *path) |
| 200 | { |
| 201 | return NULL; |
| 202 | } |
| 203 | static inline |
| 204 | struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev, |
| 205 | struct lttng_filter_bytecode *filter) |
| 206 | { |
| 207 | return NULL; |
| 208 | } |
| 209 | static inline |
| 210 | struct ltt_ust_metadata *trace_ust_create_metadata(char *path) |
| 211 | { |
| 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | static inline |
| 216 | void trace_ust_destroy_session(struct ltt_ust_session *session) |
| 217 | { |
| 218 | } |
| 219 | |
| 220 | static inline |
| 221 | void trace_ust_destroy_metadata(struct ltt_ust_metadata *metadata) |
| 222 | { |
| 223 | } |
| 224 | |
| 225 | static inline |
| 226 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel) |
| 227 | { |
| 228 | } |
| 229 | |
| 230 | static inline |
| 231 | void trace_ust_destroy_event(struct ltt_ust_event *event) |
| 232 | { |
| 233 | } |
| 234 | static inline |
| 235 | struct ltt_ust_context *trace_ust_create_context( |
| 236 | struct lttng_event_context *ctx) |
| 237 | { |
| 238 | return NULL; |
| 239 | } |
| 240 | static inline struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, |
| 241 | char *name, struct lttng_filter_bytecode *filter, int loglevel) |
| 242 | { |
| 243 | return NULL; |
| 244 | } |
| 245 | |
| 246 | #endif /* HAVE_LIBLTTNG_UST_CTL */ |
| 247 | |
| 248 | #endif /* _LTT_TRACE_UST_H */ |