Update quickstart
[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 * 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
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
21 */
22
23#ifndef _LTTNG_H
24#define _LTTNG_H
25
26#include <asm/types.h>
27#include <sys/types.h>
28#include <stdint.h>
29#include <limits.h>
30
31/* Default unix group name for tracing. */
32#define LTTNG_DEFAULT_TRACING_GROUP "tracing"
33
34/* Environment variable to set session daemon binary path. */
35#define LTTNG_SESSIOND_PATH_ENV "LTTNG_SESSIOND_PATH"
36
37/* Default trace output directory name */
38#define LTTNG_DEFAULT_TRACE_DIR_NAME "lttng-traces"
39
40/*
41 * Event symbol length. Copied from LTTng kernel ABI.
42 */
43#define LTTNG_SYMBOL_NAME_LEN 128
44
45/*
46 * Every lttng_event_* structure both apply to kernel event and user-space
47 * event.
48 */
49
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 */
72enum lttng_event_type {
73 LTTNG_EVENT_TRACEPOINT,
74 LTTNG_EVENT_PROBE,
75 LTTNG_EVENT_FUNCTION,
76 LTTNG_EVENT_FUNCTION_ENTRY,
77};
78
79/*
80 * LTTng consumer mode
81 */
82enum lttng_event_output {
83 LTTNG_EVENT_SPLICE = 0,
84 LTTNG_EVENT_MMAP = 1,
85};
86
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,
99};
100
101/* Perf counter attributes */
102struct lttng_event_perf_counter_ctx {
103 uint32_t type;
104 uint64_t config;
105 char name[LTTNG_SYMBOL_NAME_LEN];
106};
107
108/* Event/Channel context */
109struct lttng_event_context {
110 enum lttng_event_context_type ctx;
111 union {
112 struct lttng_event_perf_counter_ctx perf_counter;
113 } u;
114};
115
116/*
117 * Event probe.
118 *
119 * Either addr is used or symbol_name and offset.
120 */
121struct lttng_event_probe_attr {
122 uint64_t addr;
123
124 uint64_t offset;
125 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
126};
127
128/*
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 {
143 struct lttng_event_probe_attr probe;
144 struct lttng_event_function_attr ftrace;
145 } attr;
146};
147
148/*
149 * Tracer channel attributes. For both kernel and user-space.
150 */
151struct lttng_channel_attr {
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 */
157 enum lttng_event_output output; /* splice, mmap */
158};
159
160/*
161 * Channel information structure. For both kernel and user-space.
162 */
163struct lttng_channel {
164 char name[NAME_MAX];
165 struct lttng_channel_attr attr;
166};
167
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 {
176 char name[NAME_MAX];
177 /* The path where traces are written */
178 char path[PATH_MAX];
179};
180
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
194/*
195 * Session daemon control
196 */
197
198/*
199 * Create tracing session using a name and a path where trace will be written.
200 */
201extern int lttng_create_session(const char *name, const char *path);
202
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 */
209extern int lttng_destroy_session(const char *name);
210
211/*
212 * List tracing sessions.
213 *
214 * Return the size of the "lttng_session" array. Caller must free(3) the
215 * returned data.
216 */
217extern int lttng_list_sessions(struct lttng_session **sessions);
218
219/*
220 * Check if a session daemon is alive.
221 */
222extern int lttng_session_daemon_alive(void);
223
224/*
225 * Set tracing group for the *current* flow of execution.
226 */
227extern int lttng_set_tracing_group(const char *name);
228
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 */
236extern void lttng_set_session_name(const char *name);
237
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 */
243extern const char *lttng_get_readable_code(int code);
244
245/*
246 * Start tracing for *all* registered trace (kernel and user-space).
247 */
248extern int lttng_start_tracing(const char *session_name);
249
250/*
251 * Stop tracing for *all* registered trace (kernel and user-space).
252 */
253extern int lttng_stop_tracing(const char *session_name);
254
255/*
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.
261 */
262
263extern int lttng_add_context(struct lttng_domain *domain,
264 struct lttng_event_context *ctx, const char *event_name,
265 const char *channel_name);
266
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,
276 const char *channel_name);
277
278/*
279 * Create or enable a kernel channel.
280 *
281 * If name is NULL, the default channel is enabled (channel0).
282 */
283extern int lttng_enable_channel(struct lttng_domain *domain,
284 struct lttng_channel *chan);
285
286/*
287 * Disable kernel event.
288 *
289 * If channel_name is NULL, the default channel is used (channel0).
290 */
291extern int lttng_disable_event(struct lttng_domain *domain, const char *name,
292 const char *channel_name);
293
294/*
295 * Disable kernel channel.
296 *
297 * If channel_name is NULL, the default channel is disabled (channel0).
298 */
299extern int lttng_disable_channel(struct lttng_domain *domain,
300 const char *name);
301
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);
308
309#endif /* _LTTNG_H */
This page took 0.023063 seconds and 4 git commands to generate.