New public API for lttng control
[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
DG
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program 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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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,
1657e9bb
DG
76};
77
e6ddca71
DG
78/*
79 * LTTng consumer mode
80 */
81enum lttng_event_output {
7d29a247
DG
82 LTTNG_EVENT_SPLICE = 0,
83 LTTNG_EVENT_MMAP = 1,
e6ddca71
DG
84};
85
7d29a247
DG
86/* Event context possible type */
87enum lttng_event_context_type {
88 LTTNG_EVENT_CONTEXT_PID = 0,
89 LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1,
90 LTTNG_EVENT_CONTEXT_COMM = 2,
91 LTTNG_EVENT_CONTEXT_PRIO = 3,
92 LTTNG_EVENT_CONTEXT_NICE = 4,
93 LTTNG_EVENT_CONTEXT_VPID = 5,
94 LTTNG_EVENT_CONTEXT_TID = 6,
95 LTTNG_EVENT_CONTEXT_VTID = 7,
96 LTTNG_EVENT_CONTEXT_PPID = 8,
97 LTTNG_EVENT_CONTEXT_VPPID = 9,
d65106b1
DG
98};
99
100/* Perf counter attributes */
7d29a247 101struct lttng_event_perf_counter_ctx {
d65106b1
DG
102 uint32_t type;
103 uint64_t config;
104 char name[LTTNG_SYMBOL_NAME_LEN];
105};
106
107/* Event/Channel context */
7d29a247
DG
108struct lttng_event_context {
109 enum lttng_event_context_type ctx;
d65106b1 110 union {
7d29a247 111 struct lttng_event_perf_counter_ctx perf_counter;
d65106b1
DG
112 } u;
113};
114
b7384347 115/*
7d29a247
DG
116 * Event probe.
117 *
118 * Either addr is used or symbol_name and offset.
57167058 119 */
7d29a247 120struct lttng_event_probe_attr {
f3ed775e
DG
121 uint64_t addr;
122
123 uint64_t offset;
124 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
57167058
DG
125};
126
b7384347 127/*
f3ed775e
DG
128 * Function tracer
129 */
130struct lttng_event_function_attr {
131 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
132};
133
134/*
135 * Generic lttng event
136 */
137struct lttng_event {
138 char name[LTTNG_SYMBOL_NAME_LEN];
139 enum lttng_event_type type;
140 /* Per event type configuration */
141 union {
7d29a247 142 struct lttng_event_probe_attr probe;
f3ed775e
DG
143 struct lttng_event_function_attr ftrace;
144 } attr;
145};
146
e6ddca71
DG
147/*
148 * Tracer channel attributes. For both kernel and user-space.
149 */
f3ed775e 150struct lttng_channel_attr {
8ce37aa5
DG
151 int overwrite; /* 1: overwrite, 0: discard */
152 uint64_t subbuf_size; /* bytes */
153 uint64_t num_subbuf; /* power of 2 */
154 unsigned int switch_timer_interval; /* usec */
155 unsigned int read_timer_interval; /* usec */
f05b5f07 156 enum lttng_event_output output; /* splice, mmap */
f3ed775e
DG
157};
158
159/*
e6ddca71 160 * Channel information structure. For both kernel and user-space.
1657e9bb 161 */
e6ddca71 162struct lttng_channel {
1657e9bb 163 char name[NAME_MAX];
e6ddca71 164 struct lttng_channel_attr attr;
f3ed775e
DG
165};
166
e6ddca71
DG
167/*
168 * Basic session information.
169 *
170 * This is an 'output data' meaning that it only comes *from* the session
171 * daemon *to* the lttng client. It's basically a 'human' representation of
172 * tracing entities (here a session).
173 */
174struct lttng_session {
f3ed775e 175 char name[NAME_MAX];
e6ddca71
DG
176 /* The path where traces are written */
177 char path[PATH_MAX];
1657e9bb
DG
178};
179
7d29a247
DG
180/*
181 * Public LTTng control API
182 *
183 * For functions having a lttng domain type as parameter, if a bad value is
184 * given, NO default is applied and an error is returned.
185 *
186 * On success, all functions of the API return 0 or the size of the allocated
187 * array.
188 *
189 * On error, a negative value is returned being a specific lttng-tools error
190 * code which can be humanly interpreted with lttng_get_readable_code(err).
191 */
192
b7384347
DG
193/*
194 * Session daemon control
195 */
7d29a247
DG
196
197/*
198 * Create tracing session using a name and a path where trace will be written.
199 */
f3ed775e
DG
200extern int lttng_create_session(char *name, char *path);
201
7d29a247
DG
202/*
203 * Destroy tracing session.
204 *
205 * The session will not be useable anymore, tracing will stopped for all
206 * registered trace and tracing buffers will be flushed.
207 */
f3ed775e
DG
208extern int lttng_destroy_session(char *name);
209
e6ddca71 210/*
7d29a247
DG
211 * List tracing sessions.
212 *
213 * Return the size of the "lttng_session" array. Caller must free(3) the
214 * returned data.
e6ddca71 215 */
ca95a216 216extern int lttng_list_sessions(struct lttng_session **sessions);
f3ed775e 217
7d29a247
DG
218/*
219 * Check if a session daemon is alive.
220 */
947308c4 221extern int lttng_session_daemon_alive(void);
f3ed775e 222
7d29a247
DG
223/*
224 * Set tracing group for the *current* flow of execution.
225 */
b7384347 226extern int lttng_set_tracing_group(const char *name);
f3ed775e 227
7d29a247
DG
228/*
229 * Set the session name of the *current* flow of execution.
230 *
231 * This is a VERY important things to do before doing any tracing actions. If
232 * it's not done, you'll get an error saying that the session is not found.
233 * It avoids the use of a session name on every API call.
234 */
f3ed775e
DG
235extern void lttng_set_session_name(char *name);
236
7d29a247
DG
237/*
238 * Return a human readable error message of a lttng-tools error code.
239 *
240 * Parameter MUST be a negative value or else you'll get a generic message.
241 */
b7384347
DG
242extern const char *lttng_get_readable_code(int code);
243
7d29a247
DG
244/*
245 * Start tracing for *all* registered trace (kernel and user-space).
246 */
f3ed775e
DG
247extern int lttng_start_tracing(char *session_name);
248
7d29a247
DG
249/*
250 * Stop tracing for *all* registered trace (kernel and user-space).
251 */
f3ed775e
DG
252extern int lttng_stop_tracing(char *session_name);
253
b7384347 254/*
7d29a247
DG
255 * Add context to event for a specific channel.
256 *
257 * If event_name is NULL, the context is applied to all event of the channel.
258 * If channel_name is NULL, a lookup of the event's channel is done.
259 * If both are NULL, the context is applied on all events of all channels.
b7384347 260 */
f3ed775e 261
7d29a247
DG
262extern int lttng_add_context(struct lttng_domain *domain,
263 struct lttng_event_context *ctx, char *event_name, char *channel_name);
f3ed775e 264
7d29a247
DG
265/*
266 * Create or enable a kernel event.
267 *
268 * If the event you are trying to enable does not exist, it will be created,
269 * else it is enabled.
270 *
271 * If channel_name is NULL, the default channel is used (channel0).
272 */
273extern int lttng_enable_event(struct lttng_domain *domain, struct lttng_event *ev,
274 char *channel_name);
f3ed775e 275
7d29a247
DG
276/*
277 * Create or enable a kernel channel.
278 *
279 * If name is NULL, the default channel is enabled (channel0).
280 */
281extern int lttng_enable_channel(struct lttng_domain *domain, struct lttng_channel *chan);
f3ed775e 282
7d29a247
DG
283/*
284 * Disable kernel event.
285 *
286 * If channel_name is NULL, the default channel is used (channel0).
287 */
288extern int lttng_disable_event(struct lttng_domain *domain, char *name,
289 char *channel_name);
fac6795d 290
1df4dedd 291/*
7d29a247
DG
292 * Disable kernel channel.
293 *
294 * If channel_name is NULL, the default channel is disabled (channel0).
1df4dedd 295 */
7d29a247 296extern int lttng_disable_channel(struct lttng_domain *domain, char *name);
1df4dedd 297
7d29a247
DG
298/*
299 * List kernel events.
300 *
301 * Return the size of the allocated event list. Caller must free(3) the data.
302 */
303extern int lttng_list_events(struct lttng_domain *domain, char **event_list);
e6ddca71 304
b7384347 305#endif /* _LTTNG_H */
This page took 0.054561 seconds and 4 git commands to generate.