Change licensing
[lttng-tools.git] / include / lttng / lttng.h
... / ...
CommitLineData
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 * 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,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
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
26 */
27
28#ifndef _LTTNG_H
29#define _LTTNG_H
30
31#include <asm/types.h>
32#include <sys/types.h>
33#include <stdint.h>
34#include <limits.h>
35
36/* Default unix group name for tracing. */
37#define LTTNG_DEFAULT_TRACING_GROUP "tracing"
38
39/* Environment variable to set session daemon binary path. */
40#define LTTNG_SESSIOND_PATH_ENV "LTTNG_SESSIOND_PATH"
41
42/* Default trace output directory name */
43#define LTTNG_DEFAULT_TRACE_DIR_NAME "lttng-traces"
44
45/*
46 * Event symbol length. Copied from LTTng kernel ABI.
47 */
48#define LTTNG_SYMBOL_NAME_LEN 128
49
50/*
51 * Every lttng_event_* structure both apply to kernel event and user-space
52 * event.
53 */
54
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 */
77enum lttng_event_type {
78 LTTNG_EVENT_TRACEPOINT,
79 LTTNG_EVENT_PROBE,
80 LTTNG_EVENT_FUNCTION,
81};
82
83/*
84 * LTTng consumer mode
85 */
86enum lttng_event_output {
87 LTTNG_EVENT_SPLICE = 0,
88 LTTNG_EVENT_MMAP = 1,
89};
90
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,
103};
104
105/* Perf counter attributes */
106struct 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 */
113struct 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 */
125struct 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 */
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 {
147 struct lttng_event_probe_attr probe;
148 struct lttng_event_function_attr ftrace;
149 } attr;
150};
151
152/*
153 * Tracer channel attributes. For both kernel and user-space.
154 */
155struct lttng_channel_attr {
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 */
161 enum lttng_event_output output; /* splice, mmap */
162};
163
164/*
165 * Channel information structure. For both kernel and user-space.
166 */
167struct lttng_channel {
168 char name[NAME_MAX];
169 struct lttng_channel_attr attr;
170};
171
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 {
180 char name[NAME_MAX];
181 /* The path where traces are written */
182 char path[PATH_MAX];
183};
184
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
198/*
199 * Session daemon control
200 */
201
202/*
203 * Create tracing session using a name and a path where trace will be written.
204 */
205extern int lttng_create_session(const char *name, const char *path);
206
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 */
213extern int lttng_destroy_session(const char *name);
214
215/*
216 * List tracing sessions.
217 *
218 * Return the size of the "lttng_session" array. Caller must free(3) the
219 * returned data.
220 */
221extern int lttng_list_sessions(struct lttng_session **sessions);
222
223/*
224 * Check if a session daemon is alive.
225 */
226extern int lttng_session_daemon_alive(void);
227
228/*
229 * Set tracing group for the *current* flow of execution.
230 */
231extern int lttng_set_tracing_group(const char *name);
232
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 */
240extern void lttng_set_session_name(const char *name);
241
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 */
247extern const char *lttng_get_readable_code(int code);
248
249/*
250 * Start tracing for *all* registered trace (kernel and user-space).
251 */
252extern int lttng_start_tracing(const char *session_name);
253
254/*
255 * Stop tracing for *all* registered trace (kernel and user-space).
256 */
257extern int lttng_stop_tracing(const char *session_name);
258
259/*
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.
265 */
266
267extern int lttng_add_context(struct lttng_domain *domain,
268 struct lttng_event_context *ctx, const char *event_name,
269 const char *channel_name);
270
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,
280 const char *channel_name);
281
282/*
283 * Create or enable a kernel channel.
284 *
285 * If name is NULL, the default channel is enabled (channel0).
286 */
287extern int lttng_enable_channel(struct lttng_domain *domain,
288 struct lttng_channel *chan);
289
290/*
291 * Disable kernel event.
292 *
293 * If channel_name is NULL, the default channel is used (channel0).
294 */
295extern int lttng_disable_event(struct lttng_domain *domain, const char *name,
296 const char *channel_name);
297
298/*
299 * Disable kernel channel.
300 *
301 * If channel_name is NULL, the default channel is disabled (channel0).
302 */
303extern int lttng_disable_channel(struct lttng_domain *domain,
304 const char *name);
305
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);
312
313#endif /* _LTTNG_H */
This page took 0.024746 seconds and 5 git commands to generate.