Fix module unload order
[lttng-tools.git] / include / lttng / lttng.h
CommitLineData
826d496d 1/*
b7384347
DG
2 * lttng.h
3 *
4 * Linux Trace Toolkit Control Library Header File
5 *
826d496d 6 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
fac6795d 7 *
82a3637f
DG
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,
fac6795d 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82a3637f
DG
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
fac6795d
DG
21 */
22
b7384347
DG
23#ifndef _LTTNG_H
24#define _LTTNG_H
fac6795d 25
f3ed775e 26#include <asm/types.h>
7d29a247 27#include <sys/types.h>
f3ed775e 28#include <stdint.h>
57167058
DG
29#include <limits.h>
30
b7384347
DG
31/* Default unix group name for tracing. */
32#define LTTNG_DEFAULT_TRACING_GROUP "tracing"
fac6795d 33
b7384347 34/* Environment variable to set session daemon binary path. */
5b8719f5
DG
35#define LTTNG_SESSIOND_PATH_ENV "LTTNG_SESSIOND_PATH"
36
58a97671
DG
37/* Default trace output directory name */
38#define LTTNG_DEFAULT_TRACE_DIR_NAME "lttng-traces"
39
b7384347 40/*
e6ddca71 41 * Event symbol length. Copied from LTTng kernel ABI.
1657e9bb 42 */
f3ed775e
DG
43#define LTTNG_SYMBOL_NAME_LEN 128
44
e6ddca71
DG
45/*
46 * Every lttng_event_* structure both apply to kernel event and user-space
47 * event.
e6ddca71
DG
48 */
49
7d29a247
DG
50/*
51 * Domain type are the different possible tracers.
52 */
53enum lttng_domain_type {
0d0c377a
DG
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,
7d29a247
DG
59};
60
7d29a247
DG
61/*
62 * Instrumentation type of tracing event.
63 */
f3ed775e 64enum lttng_event_type {
e6ddca71 65 LTTNG_EVENT_TRACEPOINT,
7d29a247 66 LTTNG_EVENT_PROBE,
f3ed775e 67 LTTNG_EVENT_FUNCTION,
8f0d098b 68 LTTNG_EVENT_FUNCTION_ENTRY,
1657e9bb
DG
69};
70
e6ddca71
DG
71/*
72 * LTTng consumer mode
73 */
74enum lttng_event_output {
7d29a247
DG
75 LTTNG_EVENT_SPLICE = 0,
76 LTTNG_EVENT_MMAP = 1,
e6ddca71
DG
77};
78
7d29a247
DG
79/* Event context possible type */
80enum 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,
d65106b1
DG
91};
92
9f19cc17
DG
93struct lttng_domain {
94 enum lttng_domain_type type;
95 union {
96 pid_t pid;
97 char exec_name[NAME_MAX];
98 } attr;
99};
100
d65106b1 101/* Perf counter attributes */
7d29a247 102struct lttng_event_perf_counter_ctx {
d65106b1
DG
103 uint32_t type;
104 uint64_t config;
105 char name[LTTNG_SYMBOL_NAME_LEN];
106};
107
108/* Event/Channel context */
7d29a247
DG
109struct lttng_event_context {
110 enum lttng_event_context_type ctx;
d65106b1 111 union {
7d29a247 112 struct lttng_event_perf_counter_ctx perf_counter;
d65106b1
DG
113 } u;
114};
115
b7384347 116/*
7d29a247
DG
117 * Event probe.
118 *
119 * Either addr is used or symbol_name and offset.
57167058 120 */
7d29a247 121struct lttng_event_probe_attr {
f3ed775e
DG
122 uint64_t addr;
123
124 uint64_t offset;
125 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
57167058
DG
126};
127
b7384347 128/*
f3ed775e
DG
129 * Function tracer
130 */
131struct lttng_event_function_attr {
132 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
133};
134
135/*
136 * Generic lttng event
137 */
138struct lttng_event {
139 char name[LTTNG_SYMBOL_NAME_LEN];
140 enum lttng_event_type type;
9f19cc17 141 uint32_t enabled;
f3ed775e
DG
142 /* Per event type configuration */
143 union {
7d29a247 144 struct lttng_event_probe_attr probe;
f3ed775e
DG
145 struct lttng_event_function_attr ftrace;
146 } attr;
147};
148
e6ddca71
DG
149/*
150 * Tracer channel attributes. For both kernel and user-space.
151 */
f3ed775e 152struct lttng_channel_attr {
8ce37aa5
DG
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 */
f05b5f07 158 enum lttng_event_output output; /* splice, mmap */
f3ed775e
DG
159};
160
161/*
e6ddca71 162 * Channel information structure. For both kernel and user-space.
1657e9bb 163 */
e6ddca71 164struct lttng_channel {
1657e9bb 165 char name[NAME_MAX];
9f19cc17 166 uint32_t enabled;
e6ddca71 167 struct lttng_channel_attr attr;
f3ed775e
DG
168};
169
e6ddca71
DG
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 */
177struct lttng_session {
f3ed775e 178 char name[NAME_MAX];
e6ddca71
DG
179 /* The path where traces are written */
180 char path[PATH_MAX];
1657e9bb
DG
181};
182
7d29a247
DG
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
b7384347
DG
196/*
197 * Session daemon control
198 */
7d29a247
DG
199
200/*
201 * Create tracing session using a name and a path where trace will be written.
202 */
38057ed1 203extern int lttng_create_session(const char *name, const char *path);
f3ed775e 204
7d29a247
DG
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 */
38057ed1 211extern int lttng_destroy_session(const char *name);
f3ed775e 212
e6ddca71 213/*
9f19cc17 214 * List all tracing sessions.
7d29a247 215 *
9f19cc17 216 * Return the size of the "lttng_session" array. Caller must free(3).
e6ddca71 217 */
ca95a216 218extern int lttng_list_sessions(struct lttng_session **sessions);
f3ed775e 219
9f19cc17 220/*
2a71efd5 221 * List registered domain(s) of a session.
9f19cc17
DG
222 *
223 * Return the size of the "lttng_domain" array. Caller must free(3).
224 */
225extern 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 */
233extern 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 */
241extern int lttng_list_events(struct lttng_domain *domain,
242 const char *session_name, const char *channel_name,
243 struct lttng_event **events);
244
245/*
2a71efd5 246 * List available tracepoints of domain.
9f19cc17
DG
247 *
248 * Return the size of the "lttng_event" array. Caller must free(3).
249 */
2a71efd5
DG
250extern int lttng_list_tracepoints(struct lttng_domain *domain,
251 struct lttng_event **events);
9f19cc17 252
7d29a247
DG
253/*
254 * Check if a session daemon is alive.
255 */
947308c4 256extern int lttng_session_daemon_alive(void);
f3ed775e 257
7d29a247
DG
258/*
259 * Set tracing group for the *current* flow of execution.
260 */
b7384347 261extern int lttng_set_tracing_group(const char *name);
f3ed775e 262
7d29a247
DG
263/*
264 * Set the session name of the *current* flow of execution.
265 *
266 * This is a VERY important things to do before doing any tracing actions. If
267 * it's not done, you'll get an error saying that the session is not found.
268 * It avoids the use of a session name on every API call.
269 */
38057ed1 270extern void lttng_set_session_name(const char *name);
f3ed775e 271
7d29a247
DG
272/*
273 * Return a human readable error message of a lttng-tools error code.
274 *
275 * Parameter MUST be a negative value or else you'll get a generic message.
276 */
b7384347
DG
277extern const char *lttng_get_readable_code(int code);
278
7d29a247
DG
279/*
280 * Start tracing for *all* registered trace (kernel and user-space).
281 */
38057ed1 282extern int lttng_start_tracing(const char *session_name);
f3ed775e 283
7d29a247
DG
284/*
285 * Stop tracing for *all* registered trace (kernel and user-space).
286 */
38057ed1 287extern int lttng_stop_tracing(const char *session_name);
f3ed775e 288
b7384347 289/*
7d29a247
DG
290 * Add context to event for a specific channel.
291 *
292 * If event_name is NULL, the context is applied to all event of the channel.
293 * If channel_name is NULL, a lookup of the event's channel is done.
294 * If both are NULL, the context is applied on all events of all channels.
b7384347 295 */
f3ed775e 296
7d29a247 297extern int lttng_add_context(struct lttng_domain *domain,
38057ed1
DG
298 struct lttng_event_context *ctx, const char *event_name,
299 const char *channel_name);
f3ed775e 300
7d29a247
DG
301/*
302 * Create or enable a kernel event.
303 *
304 * If the event you are trying to enable does not exist, it will be created,
305 * else it is enabled.
306 *
307 * If channel_name is NULL, the default channel is used (channel0).
308 */
309extern int lttng_enable_event(struct lttng_domain *domain, struct lttng_event *ev,
38057ed1 310 const char *channel_name);
f3ed775e 311
7d29a247
DG
312/*
313 * Create or enable a kernel channel.
314 *
315 * If name is NULL, the default channel is enabled (channel0).
316 */
38057ed1
DG
317extern int lttng_enable_channel(struct lttng_domain *domain,
318 struct lttng_channel *chan);
f3ed775e 319
7d29a247
DG
320/*
321 * Disable kernel event.
322 *
323 * If channel_name is NULL, the default channel is used (channel0).
324 */
38057ed1
DG
325extern int lttng_disable_event(struct lttng_domain *domain, const char *name,
326 const char *channel_name);
fac6795d 327
1df4dedd 328/*
7d29a247
DG
329 * Disable kernel channel.
330 *
331 * If channel_name is NULL, the default channel is disabled (channel0).
1df4dedd 332 */
38057ed1
DG
333extern int lttng_disable_channel(struct lttng_domain *domain,
334 const char *name);
1df4dedd 335
b7384347 336#endif /* _LTTNG_H */
This page took 0.062533 seconds and 4 git commands to generate.