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