Fix uninitialized variable
[lttng-tools.git] / include / lttng / lttng.h
1 /*
2 * lttng.h
3 *
4 * Linux Trace Toolkit Control Library Header File
5 *
6 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef _LTTNG_H
24 #define _LTTNG_H
25
26 #include <asm/types.h>
27 #include <sys/types.h>
28 #include <stdint.h>
29 #include <limits.h>
30
31 /* Default unix group name for tracing. */
32 #define LTTNG_DEFAULT_TRACING_GROUP "tracing"
33
34 /* Environment variable to set session daemon binary path. */
35 #define LTTNG_SESSIOND_PATH_ENV "LTTNG_SESSIOND_PATH"
36
37 /* Default trace output directory name */
38 #define LTTNG_DEFAULT_TRACE_DIR_NAME "lttng-traces"
39
40 /*
41 * Event symbol length. Copied from LTTng kernel ABI.
42 */
43 #define LTTNG_SYMBOL_NAME_LEN 128
44
45 /*
46 * Every lttng_event_* structure both apply to kernel event and user-space
47 * event.
48 */
49
50 /*
51 * Domain type are the different possible tracers.
52 */
53 enum lttng_domain_type {
54 LTTNG_DOMAIN_KERNEL,
55 LTTNG_DOMAIN_UST,
56 LTTNG_DOMAIN_UST_EXEC_NAME,
57 LTTNG_DOMAIN_UST_PID,
58 LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN,
59 };
60
61 /*
62 * Instrumentation type of tracing event.
63 */
64 enum lttng_event_type {
65 LTTNG_EVENT_TRACEPOINT,
66 LTTNG_EVENT_PROBE,
67 LTTNG_EVENT_FUNCTION,
68 LTTNG_EVENT_FUNCTION_ENTRY,
69 };
70
71 /*
72 * LTTng consumer mode
73 */
74 enum lttng_event_output {
75 LTTNG_EVENT_SPLICE = 0,
76 LTTNG_EVENT_MMAP = 1,
77 };
78
79 /* Event context possible type */
80 enum lttng_event_context_type {
81 LTTNG_EVENT_CONTEXT_PID = 0,
82 LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1,
83 LTTNG_EVENT_CONTEXT_COMM = 2,
84 LTTNG_EVENT_CONTEXT_PRIO = 3,
85 LTTNG_EVENT_CONTEXT_NICE = 4,
86 LTTNG_EVENT_CONTEXT_VPID = 5,
87 LTTNG_EVENT_CONTEXT_TID = 6,
88 LTTNG_EVENT_CONTEXT_VTID = 7,
89 LTTNG_EVENT_CONTEXT_PPID = 8,
90 LTTNG_EVENT_CONTEXT_VPPID = 9,
91 };
92
93 struct lttng_domain {
94 enum lttng_domain_type type;
95 union {
96 pid_t pid;
97 char exec_name[NAME_MAX];
98 } attr;
99 };
100
101 /* Perf counter attributes */
102 struct lttng_event_perf_counter_ctx {
103 uint32_t type;
104 uint64_t config;
105 char name[LTTNG_SYMBOL_NAME_LEN];
106 };
107
108 /* Event/Channel context */
109 struct lttng_event_context {
110 enum lttng_event_context_type ctx;
111 union {
112 struct lttng_event_perf_counter_ctx perf_counter;
113 } u;
114 };
115
116 /*
117 * Event probe.
118 *
119 * Either addr is used or symbol_name and offset.
120 */
121 struct lttng_event_probe_attr {
122 uint64_t addr;
123
124 uint64_t offset;
125 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
126 };
127
128 /*
129 * Function tracer
130 */
131 struct lttng_event_function_attr {
132 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
133 };
134
135 /*
136 * Generic lttng event
137 */
138 struct lttng_event {
139 char name[LTTNG_SYMBOL_NAME_LEN];
140 enum lttng_event_type type;
141 uint32_t enabled;
142 /* Per event type configuration */
143 union {
144 struct lttng_event_probe_attr probe;
145 struct lttng_event_function_attr ftrace;
146 } attr;
147 };
148
149 /*
150 * Tracer channel attributes. For both kernel and user-space.
151 */
152 struct lttng_channel_attr {
153 int overwrite; /* 1: overwrite, 0: discard */
154 uint64_t subbuf_size; /* bytes */
155 uint64_t num_subbuf; /* power of 2 */
156 unsigned int switch_timer_interval; /* usec */
157 unsigned int read_timer_interval; /* usec */
158 enum lttng_event_output output; /* splice, mmap */
159 };
160
161 /*
162 * Channel information structure. For both kernel and user-space.
163 */
164 struct lttng_channel {
165 char name[NAME_MAX];
166 uint32_t enabled;
167 struct lttng_channel_attr attr;
168 };
169
170 /*
171 * Basic session information.
172 *
173 * This is an 'output data' meaning that it only comes *from* the session
174 * daemon *to* the lttng client. It's basically a 'human' representation of
175 * tracing entities (here a session).
176 */
177 struct lttng_session {
178 char name[NAME_MAX];
179 /* The path where traces are written */
180 char path[PATH_MAX];
181 };
182
183 /*
184 * Public LTTng control API
185 *
186 * For functions having a lttng domain type as parameter, if a bad value is
187 * given, NO default is applied and an error is returned.
188 *
189 * On success, all functions of the API return 0 or the size of the allocated
190 * array.
191 *
192 * On error, a negative value is returned being a specific lttng-tools error
193 * code which can be humanly interpreted with lttng_get_readable_code(err).
194 */
195
196 /*
197 * Session daemon control
198 */
199
200 /*
201 * Create tracing session using a name and a path where trace will be written.
202 */
203 extern int lttng_create_session(const char *name, const char *path);
204
205 /*
206 * Destroy tracing session.
207 *
208 * The session will not be useable anymore, tracing will stopped for all
209 * registered trace and tracing buffers will be flushed.
210 */
211 extern int lttng_destroy_session(const char *name);
212
213 /*
214 * List all tracing sessions.
215 *
216 * Return the size of the "lttng_session" array. Caller must free(3).
217 */
218 extern int lttng_list_sessions(struct lttng_session **sessions);
219
220 /*
221 * List registered domain(s) of the session.
222 *
223 * Return the size of the "lttng_domain" array. Caller must free(3).
224 */
225 extern int lttng_list_domains(const char *session_name,
226 struct lttng_domain **domains);
227
228 /*
229 * List channel(s) of a session.
230 *
231 * Return the size of the "lttng_channel" array. Caller must free(3).
232 */
233 extern int lttng_list_channels(struct lttng_domain *domain,
234 const char *session_name, struct lttng_channel **channels);
235
236 /*
237 * List event(s) of a session channel.
238 *
239 * Return the size of the "lttng_event" array. Caller must free(3).
240 */
241 extern int lttng_list_events(struct lttng_domain *domain,
242 const char *session_name, const char *channel_name,
243 struct lttng_event **events);
244
245 /*
246 * List available kernel tracing events
247 *
248 * Return the size of the "lttng_event" array. Caller must free(3).
249 */
250 extern int lttng_list_kernel_events(struct lttng_event **events);
251
252 /*
253 * Check if a session daemon is alive.
254 */
255 extern int lttng_session_daemon_alive(void);
256
257 /*
258 * Set tracing group for the *current* flow of execution.
259 */
260 extern int lttng_set_tracing_group(const char *name);
261
262 /*
263 * Set the session name of the *current* flow of execution.
264 *
265 * This is a VERY important things to do before doing any tracing actions. If
266 * it's not done, you'll get an error saying that the session is not found.
267 * It avoids the use of a session name on every API call.
268 */
269 extern void lttng_set_session_name(const char *name);
270
271 /*
272 * Return a human readable error message of a lttng-tools error code.
273 *
274 * Parameter MUST be a negative value or else you'll get a generic message.
275 */
276 extern const char *lttng_get_readable_code(int code);
277
278 /*
279 * Start tracing for *all* registered trace (kernel and user-space).
280 */
281 extern int lttng_start_tracing(const char *session_name);
282
283 /*
284 * Stop tracing for *all* registered trace (kernel and user-space).
285 */
286 extern int lttng_stop_tracing(const char *session_name);
287
288 /*
289 * Add context to event for a specific channel.
290 *
291 * If event_name is NULL, the context is applied to all event of the channel.
292 * If channel_name is NULL, a lookup of the event's channel is done.
293 * If both are NULL, the context is applied on all events of all channels.
294 */
295
296 extern int lttng_add_context(struct lttng_domain *domain,
297 struct lttng_event_context *ctx, const char *event_name,
298 const char *channel_name);
299
300 /*
301 * Create or enable a kernel event.
302 *
303 * If the event you are trying to enable does not exist, it will be created,
304 * else it is enabled.
305 *
306 * If channel_name is NULL, the default channel is used (channel0).
307 */
308 extern int lttng_enable_event(struct lttng_domain *domain, struct lttng_event *ev,
309 const char *channel_name);
310
311 /*
312 * Create or enable a kernel channel.
313 *
314 * If name is NULL, the default channel is enabled (channel0).
315 */
316 extern int lttng_enable_channel(struct lttng_domain *domain,
317 struct lttng_channel *chan);
318
319 /*
320 * Disable kernel event.
321 *
322 * If channel_name is NULL, the default channel is used (channel0).
323 */
324 extern int lttng_disable_event(struct lttng_domain *domain, const char *name,
325 const char *channel_name);
326
327 /*
328 * Disable kernel channel.
329 *
330 * If channel_name is NULL, the default channel is disabled (channel0).
331 */
332 extern int lttng_disable_channel(struct lttng_domain *domain,
333 const char *name);
334
335 /*
336 * List kernel events.
337 *
338 * Return the size of the allocated event list. Caller must free(3) the data.
339 */
340 //extern int lttng_list_events(struct lttng_domain *domain, char **event_list);
341
342 #endif /* _LTTNG_H */
This page took 0.035983 seconds and 5 git commands to generate.