New public API for lttng control
[lttng-tools.git] / include / lttng / lttng.h
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 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.
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 */
53 enum 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
61 struct 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 */
72 enum lttng_event_type {
73 LTTNG_EVENT_TRACEPOINT,
74 LTTNG_EVENT_PROBE,
75 LTTNG_EVENT_FUNCTION,
76 };
77
78 /*
79 * LTTng consumer mode
80 */
81 enum lttng_event_output {
82 LTTNG_EVENT_SPLICE = 0,
83 LTTNG_EVENT_MMAP = 1,
84 };
85
86 /* Event context possible type */
87 enum 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,
98 };
99
100 /* Perf counter attributes */
101 struct lttng_event_perf_counter_ctx {
102 uint32_t type;
103 uint64_t config;
104 char name[LTTNG_SYMBOL_NAME_LEN];
105 };
106
107 /* Event/Channel context */
108 struct lttng_event_context {
109 enum lttng_event_context_type ctx;
110 union {
111 struct lttng_event_perf_counter_ctx perf_counter;
112 } u;
113 };
114
115 /*
116 * Event probe.
117 *
118 * Either addr is used or symbol_name and offset.
119 */
120 struct lttng_event_probe_attr {
121 uint64_t addr;
122
123 uint64_t offset;
124 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
125 };
126
127 /*
128 * Function tracer
129 */
130 struct lttng_event_function_attr {
131 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
132 };
133
134 /*
135 * Generic lttng event
136 */
137 struct lttng_event {
138 char name[LTTNG_SYMBOL_NAME_LEN];
139 enum lttng_event_type type;
140 /* Per event type configuration */
141 union {
142 struct lttng_event_probe_attr probe;
143 struct lttng_event_function_attr ftrace;
144 } attr;
145 };
146
147 /*
148 * Tracer channel attributes. For both kernel and user-space.
149 */
150 struct lttng_channel_attr {
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 */
156 enum lttng_event_output output; /* splice, mmap */
157 };
158
159 /*
160 * Channel information structure. For both kernel and user-space.
161 */
162 struct lttng_channel {
163 char name[NAME_MAX];
164 struct lttng_channel_attr attr;
165 };
166
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 */
174 struct lttng_session {
175 char name[NAME_MAX];
176 /* The path where traces are written */
177 char path[PATH_MAX];
178 };
179
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
193 /*
194 * Session daemon control
195 */
196
197 /*
198 * Create tracing session using a name and a path where trace will be written.
199 */
200 extern int lttng_create_session(char *name, char *path);
201
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 */
208 extern int lttng_destroy_session(char *name);
209
210 /*
211 * List tracing sessions.
212 *
213 * Return the size of the "lttng_session" array. Caller must free(3) the
214 * returned data.
215 */
216 extern int lttng_list_sessions(struct lttng_session **sessions);
217
218 /*
219 * Check if a session daemon is alive.
220 */
221 extern int lttng_session_daemon_alive(void);
222
223 /*
224 * Set tracing group for the *current* flow of execution.
225 */
226 extern int lttng_set_tracing_group(const char *name);
227
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 */
235 extern void lttng_set_session_name(char *name);
236
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 */
242 extern const char *lttng_get_readable_code(int code);
243
244 /*
245 * Start tracing for *all* registered trace (kernel and user-space).
246 */
247 extern int lttng_start_tracing(char *session_name);
248
249 /*
250 * Stop tracing for *all* registered trace (kernel and user-space).
251 */
252 extern int lttng_stop_tracing(char *session_name);
253
254 /*
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.
260 */
261
262 extern int lttng_add_context(struct lttng_domain *domain,
263 struct lttng_event_context *ctx, char *event_name, char *channel_name);
264
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 */
273 extern int lttng_enable_event(struct lttng_domain *domain, struct lttng_event *ev,
274 char *channel_name);
275
276 /*
277 * Create or enable a kernel channel.
278 *
279 * If name is NULL, the default channel is enabled (channel0).
280 */
281 extern int lttng_enable_channel(struct lttng_domain *domain, struct lttng_channel *chan);
282
283 /*
284 * Disable kernel event.
285 *
286 * If channel_name is NULL, the default channel is used (channel0).
287 */
288 extern int lttng_disable_event(struct lttng_domain *domain, char *name,
289 char *channel_name);
290
291 /*
292 * Disable kernel channel.
293 *
294 * If channel_name is NULL, the default channel is disabled (channel0).
295 */
296 extern int lttng_disable_channel(struct lttng_domain *domain, char *name);
297
298 /*
299 * List kernel events.
300 *
301 * Return the size of the allocated event list. Caller must free(3) the data.
302 */
303 extern int lttng_list_events(struct lttng_domain *domain, char **event_list);
304
305 #endif /* _LTTNG_H */
This page took 0.034775 seconds and 4 git commands to generate.