Fix missing file for make dist
[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 = 1,
55 LTTNG_DOMAIN_UST = 2,
56 LTTNG_DOMAIN_UST_EXEC_NAME = 3,
57 LTTNG_DOMAIN_UST_PID = 4,
58 LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN = 5,
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 enum lttng_calibrate_type {
94 LTTNG_CALIBRATE_FUNCTION = 0,
95 };
96
97 struct lttng_domain {
98 enum lttng_domain_type type;
99 union {
100 pid_t pid;
101 char exec_name[NAME_MAX];
102 } attr;
103 };
104
105 /* Perf counter attributes */
106 struct lttng_event_perf_counter_ctx {
107 uint32_t type;
108 uint64_t config;
109 char name[LTTNG_SYMBOL_NAME_LEN];
110 };
111
112 /* Event/Channel context */
113 struct lttng_event_context {
114 enum lttng_event_context_type ctx;
115 union {
116 struct lttng_event_perf_counter_ctx perf_counter;
117 } u;
118 };
119
120 /*
121 * Event probe.
122 *
123 * Either addr is used or symbol_name and offset.
124 */
125 struct lttng_event_probe_attr {
126 uint64_t addr;
127
128 uint64_t offset;
129 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
130 };
131
132 /*
133 * Function tracer
134 */
135 struct lttng_event_function_attr {
136 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
137 };
138
139 /*
140 * Generic lttng event
141 */
142 struct lttng_event {
143 char name[LTTNG_SYMBOL_NAME_LEN];
144 enum lttng_event_type type;
145 uint32_t enabled;
146 /* Per event type configuration */
147 union {
148 struct lttng_event_probe_attr probe;
149 struct lttng_event_function_attr ftrace;
150 } attr;
151 };
152
153 /*
154 * Tracer channel attributes. For both kernel and user-space.
155 */
156 struct lttng_channel_attr {
157 int overwrite; /* 1: overwrite, 0: discard */
158 uint64_t subbuf_size; /* bytes */
159 uint64_t num_subbuf; /* power of 2 */
160 unsigned int switch_timer_interval; /* usec */
161 unsigned int read_timer_interval; /* usec */
162 enum lttng_event_output output; /* splice, mmap */
163 };
164
165 /*
166 * Channel information structure. For both kernel and user-space.
167 */
168 struct lttng_channel {
169 char name[NAME_MAX];
170 uint32_t enabled;
171 struct lttng_channel_attr attr;
172 };
173
174 struct lttng_calibrate {
175 enum lttng_calibrate_type type;
176 };
177
178 /*
179 * Basic session information.
180 *
181 * This is an 'output data' meaning that it only comes *from* the session
182 * daemon *to* the lttng client. It's basically a 'human' representation of
183 * tracing entities (here a session).
184 */
185 struct lttng_session {
186 char name[NAME_MAX];
187 /* The path where traces are written */
188 char path[PATH_MAX];
189 };
190
191 /*
192 * Handle used as a context for commands.
193 */
194 struct lttng_handle {
195 char session_name[NAME_MAX];
196 struct lttng_domain domain;
197 };
198
199 /*
200 * Public LTTng control API
201 *
202 * For functions having a lttng domain type as parameter, if a bad value is
203 * given, NO default is applied and an error is returned.
204 *
205 * On success, all functions of the API return 0 or the size of the allocated
206 * array.
207 *
208 * On error, a negative value is returned being a specific lttng-tools error
209 * code which can be humanly interpreted with lttng_get_readable_code(err).
210 */
211
212 /*
213 * Create an handle used as a context for every request made to the library.
214 *
215 * This handle contains the session name and lttng domain on which the command
216 * will be executed on.
217 */
218 extern struct lttng_handle *lttng_create_handle(const char *session_name,
219 struct lttng_domain *domain);
220
221 /*
222 * Destroy an handle. This will simply free(3) the data pointer returned by
223 * lttng_create_handle() and rendering it unsuable.
224 */
225 extern void lttng_destroy_handle(struct lttng_handle *handle);
226
227 /*
228 * Create tracing session using a name and a path where trace will be written.
229 */
230 extern int lttng_create_session(const char *name, const char *path);
231
232 /*
233 * Destroy tracing session.
234 *
235 * The session will not be useable anymore, tracing will stopped for all
236 * registered trace and tracing buffers will be flushed.
237 */
238 extern int lttng_destroy_session(struct lttng_handle *handle);
239
240 /*
241 * List all tracing sessions.
242 *
243 * Return the size of the "lttng_session" array. Caller must free(3).
244 */
245 extern int lttng_list_sessions(struct lttng_session **sessions);
246
247 /*
248 * List registered domain(s) of a session.
249 *
250 * Return the size of the "lttng_domain" array. Caller must free(3).
251 */
252 extern int lttng_list_domains(struct lttng_handle *handle,
253 struct lttng_domain **domains);
254
255 /*
256 * List channel(s) of a session.
257 *
258 * Return the size of the "lttng_channel" array. Caller must free(3).
259 */
260 extern int lttng_list_channels(struct lttng_handle *handle,
261 struct lttng_channel **channels);
262
263 /*
264 * List event(s) of a session channel.
265 *
266 * Return the size of the "lttng_event" array. Caller must free(3).
267 */
268 extern int lttng_list_events(struct lttng_handle *handle,
269 const char *channel_name, struct lttng_event **events);
270
271 /*
272 * List available tracepoints of a specific lttng domain.
273 *
274 * Return the size of the "lttng_event" array. Caller must free(3).
275 */
276 extern int lttng_list_tracepoints(struct lttng_handle *handle,
277 struct lttng_event **events);
278
279 /*
280 * Check if a session daemon is alive.
281 */
282 extern int lttng_session_daemon_alive(void);
283
284 /*
285 * Set tracing group for the *current* flow of execution.
286 */
287 extern int lttng_set_tracing_group(const char *name);
288
289 /*
290 * Return a human readable error message of a lttng-tools error code.
291 *
292 * Parameter MUST be a negative value or else you'll get a generic message.
293 */
294 extern const char *lttng_get_readable_code(int code);
295
296 /*
297 * Start tracing for *all* registered trace (kernel and user-space).
298 */
299 extern int lttng_start_tracing(struct lttng_handle *handle);
300
301 /*
302 * Stop tracing for *all* registered trace (kernel and user-space).
303 */
304 extern int lttng_stop_tracing(struct lttng_handle *handle);
305
306 /*
307 * Add context to event for a specific channel.
308 *
309 * If event_name is NULL, the context is applied to all event of the channel.
310 * If channel_name is NULL, a lookup of the event's channel is done.
311 * If both are NULL, the context is applied on all events of all channels.
312 */
313 extern int lttng_add_context(struct lttng_handle *handle,
314 struct lttng_event_context *ctx, const char *event_name,
315 const char *channel_name);
316
317 /*
318 * Create or enable a kernel event.
319 *
320 * If the event you are trying to enable does not exist, it will be created,
321 * else it is enabled.
322 *
323 * If channel_name is NULL, the default channel is used (channel0).
324 */
325 extern int lttng_enable_event(struct lttng_handle *handle,
326 struct lttng_event *ev, const char *channel_name);
327
328 /*
329 * Create or enable a kernel channel.
330 *
331 * If name is NULL, the default channel is enabled (channel0).
332 */
333 extern int lttng_enable_channel(struct lttng_handle *handle,
334 struct lttng_channel *chan);
335
336 /*
337 * Disable kernel event.
338 *
339 * If channel_name is NULL, the default channel is used (channel0).
340 */
341 extern int lttng_disable_event(struct lttng_handle *handle,
342 const char *name, const char *channel_name);
343
344 /*
345 * Disable kernel channel.
346 *
347 * If channel_name is NULL, the default channel is disabled (channel0).
348 */
349 extern int lttng_disable_channel(struct lttng_handle *handle,
350 const char *name);
351
352 /*
353 * Calibrate LTTng overhead.
354 */
355 extern int lttng_calibrate(struct lttng_handle *handle,
356 struct lttng_calibrate *calibrate);
357
358 #endif /* _LTTNG_H */
This page took 0.03892 seconds and 5 git commands to generate.