Update quickstart
[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 {
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
61struct lttng_domain {
62 enum lttng_domain_type type;
63 union {
64 pid_t pid;
65 char exec_name[NAME_MAX];
66 } attr;
67};
68
69/*
70 * Instrumentation type of tracing event.
71 */
f3ed775e 72enum lttng_event_type {
e6ddca71 73 LTTNG_EVENT_TRACEPOINT,
7d29a247 74 LTTNG_EVENT_PROBE,
f3ed775e 75 LTTNG_EVENT_FUNCTION,
8f0d098b 76 LTTNG_EVENT_FUNCTION_ENTRY,
1657e9bb
DG
77};
78
e6ddca71
DG
79/*
80 * LTTng consumer mode
81 */
82enum lttng_event_output {
7d29a247
DG
83 LTTNG_EVENT_SPLICE = 0,
84 LTTNG_EVENT_MMAP = 1,
e6ddca71
DG
85};
86
7d29a247
DG
87/* Event context possible type */
88enum lttng_event_context_type {
89 LTTNG_EVENT_CONTEXT_PID = 0,
90 LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1,
91 LTTNG_EVENT_CONTEXT_COMM = 2,
92 LTTNG_EVENT_CONTEXT_PRIO = 3,
93 LTTNG_EVENT_CONTEXT_NICE = 4,
94 LTTNG_EVENT_CONTEXT_VPID = 5,
95 LTTNG_EVENT_CONTEXT_TID = 6,
96 LTTNG_EVENT_CONTEXT_VTID = 7,
97 LTTNG_EVENT_CONTEXT_PPID = 8,
98 LTTNG_EVENT_CONTEXT_VPPID = 9,
d65106b1
DG
99};
100
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;
141 /* Per event type configuration */
142 union {
7d29a247 143 struct lttng_event_probe_attr probe;
f3ed775e
DG
144 struct lttng_event_function_attr ftrace;
145 } attr;
146};
147
e6ddca71
DG
148/*
149 * Tracer channel attributes. For both kernel and user-space.
150 */
f3ed775e 151struct lttng_channel_attr {
8ce37aa5
DG
152 int overwrite; /* 1: overwrite, 0: discard */
153 uint64_t subbuf_size; /* bytes */
154 uint64_t num_subbuf; /* power of 2 */
155 unsigned int switch_timer_interval; /* usec */
156 unsigned int read_timer_interval; /* usec */
f05b5f07 157 enum lttng_event_output output; /* splice, mmap */
f3ed775e
DG
158};
159
160/*
e6ddca71 161 * Channel information structure. For both kernel and user-space.
1657e9bb 162 */
e6ddca71 163struct lttng_channel {
1657e9bb 164 char name[NAME_MAX];
e6ddca71 165 struct lttng_channel_attr attr;
f3ed775e
DG
166};
167
e6ddca71
DG
168/*
169 * Basic session information.
170 *
171 * This is an 'output data' meaning that it only comes *from* the session
172 * daemon *to* the lttng client. It's basically a 'human' representation of
173 * tracing entities (here a session).
174 */
175struct lttng_session {
f3ed775e 176 char name[NAME_MAX];
e6ddca71
DG
177 /* The path where traces are written */
178 char path[PATH_MAX];
1657e9bb
DG
179};
180
7d29a247
DG
181/*
182 * Public LTTng control API
183 *
184 * For functions having a lttng domain type as parameter, if a bad value is
185 * given, NO default is applied and an error is returned.
186 *
187 * On success, all functions of the API return 0 or the size of the allocated
188 * array.
189 *
190 * On error, a negative value is returned being a specific lttng-tools error
191 * code which can be humanly interpreted with lttng_get_readable_code(err).
192 */
193
b7384347
DG
194/*
195 * Session daemon control
196 */
7d29a247
DG
197
198/*
199 * Create tracing session using a name and a path where trace will be written.
200 */
38057ed1 201extern int lttng_create_session(const char *name, const char *path);
f3ed775e 202
7d29a247
DG
203/*
204 * Destroy tracing session.
205 *
206 * The session will not be useable anymore, tracing will stopped for all
207 * registered trace and tracing buffers will be flushed.
208 */
38057ed1 209extern int lttng_destroy_session(const char *name);
f3ed775e 210
e6ddca71 211/*
7d29a247
DG
212 * List tracing sessions.
213 *
214 * Return the size of the "lttng_session" array. Caller must free(3) the
215 * returned data.
e6ddca71 216 */
ca95a216 217extern int lttng_list_sessions(struct lttng_session **sessions);
f3ed775e 218
7d29a247
DG
219/*
220 * Check if a session daemon is alive.
221 */
947308c4 222extern int lttng_session_daemon_alive(void);
f3ed775e 223
7d29a247
DG
224/*
225 * Set tracing group for the *current* flow of execution.
226 */
b7384347 227extern int lttng_set_tracing_group(const char *name);
f3ed775e 228
7d29a247
DG
229/*
230 * Set the session name of the *current* flow of execution.
231 *
232 * This is a VERY important things to do before doing any tracing actions. If
233 * it's not done, you'll get an error saying that the session is not found.
234 * It avoids the use of a session name on every API call.
235 */
38057ed1 236extern void lttng_set_session_name(const char *name);
f3ed775e 237
7d29a247
DG
238/*
239 * Return a human readable error message of a lttng-tools error code.
240 *
241 * Parameter MUST be a negative value or else you'll get a generic message.
242 */
b7384347
DG
243extern const char *lttng_get_readable_code(int code);
244
7d29a247
DG
245/*
246 * Start tracing for *all* registered trace (kernel and user-space).
247 */
38057ed1 248extern int lttng_start_tracing(const char *session_name);
f3ed775e 249
7d29a247
DG
250/*
251 * Stop tracing for *all* registered trace (kernel and user-space).
252 */
38057ed1 253extern int lttng_stop_tracing(const char *session_name);
f3ed775e 254
b7384347 255/*
7d29a247
DG
256 * Add context to event for a specific channel.
257 *
258 * If event_name is NULL, the context is applied to all event of the channel.
259 * If channel_name is NULL, a lookup of the event's channel is done.
260 * If both are NULL, the context is applied on all events of all channels.
b7384347 261 */
f3ed775e 262
7d29a247 263extern int lttng_add_context(struct lttng_domain *domain,
38057ed1
DG
264 struct lttng_event_context *ctx, const char *event_name,
265 const char *channel_name);
f3ed775e 266
7d29a247
DG
267/*
268 * Create or enable a kernel event.
269 *
270 * If the event you are trying to enable does not exist, it will be created,
271 * else it is enabled.
272 *
273 * If channel_name is NULL, the default channel is used (channel0).
274 */
275extern int lttng_enable_event(struct lttng_domain *domain, struct lttng_event *ev,
38057ed1 276 const char *channel_name);
f3ed775e 277
7d29a247
DG
278/*
279 * Create or enable a kernel channel.
280 *
281 * If name is NULL, the default channel is enabled (channel0).
282 */
38057ed1
DG
283extern int lttng_enable_channel(struct lttng_domain *domain,
284 struct lttng_channel *chan);
f3ed775e 285
7d29a247
DG
286/*
287 * Disable kernel event.
288 *
289 * If channel_name is NULL, the default channel is used (channel0).
290 */
38057ed1
DG
291extern int lttng_disable_event(struct lttng_domain *domain, const char *name,
292 const char *channel_name);
fac6795d 293
1df4dedd 294/*
7d29a247
DG
295 * Disable kernel channel.
296 *
297 * If channel_name is NULL, the default channel is disabled (channel0).
1df4dedd 298 */
38057ed1
DG
299extern int lttng_disable_channel(struct lttng_domain *domain,
300 const char *name);
1df4dedd 301
7d29a247
DG
302/*
303 * List kernel events.
304 *
305 * Return the size of the allocated event list. Caller must free(3) the data.
306 */
307extern int lttng_list_events(struct lttng_domain *domain, char **event_list);
e6ddca71 308
b7384347 309#endif /* _LTTNG_H */
This page took 0.037061 seconds and 4 git commands to generate.