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