Commit | Line | Data |
---|---|---|
36907cb5 DS |
1 | %define DOCSTRING |
2 | "LTTNG_VERSION_STR | |
3 | ||
4 | The LTTng project aims at providing highly efficient tracing tools for Linux. | |
5 | It's tracers help tracking down performance issues and debugging problems involving | |
6 | multiple concurrent processes and threads. Tracing across multiple systems is also possible." | |
7 | %enddef | |
8 | ||
9 | %module(docstring=DOCSTRING) lttng | |
10 | ||
11 | %include "typemaps.i" | |
bc3bdada | 12 | %include "stdint.i" |
36907cb5 DS |
13 | %include "pyabc.i" |
14 | %{ | |
15 | #define SWIG_FILE_WITH_INIT | |
16 | #include <lttng/lttng.h> | |
17 | %} | |
18 | ||
6c7ee73e JG |
19 | %{ |
20 | #if PY_MAJOR_VERSION >= 3 | |
21 | // The PyInt and PyLong types were unified as of Python 3 | |
22 | // This makes the typemap code useable with both Python 2 and 3. | |
23 | #define PyInt_AsSsize_t PyLong_AsSsize_t | |
24 | #endif | |
25 | %} | |
26 | ||
36907cb5 DS |
27 | typedef unsigned int uint32_t; |
28 | typedef int int32_t; | |
29 | typedef unsigned long long uint64_t; | |
30 | typedef long pid_t; | |
31 | ||
32 | ||
33 | // ============================================= | |
34 | // ENUMS | |
35 | // These are directly taken from lttng.h. | |
36 | // Any change to these enums must also be | |
37 | // made here. | |
38 | // ============================================= | |
39 | ||
40 | %rename("DOMAIN_KERNEL") LTTNG_DOMAIN_KERNEL; | |
41 | %rename("DOMAIN_UST") LTTNG_DOMAIN_UST; | |
42 | enum lttng_domain_type { | |
43 | LTTNG_DOMAIN_KERNEL = 1, | |
44 | LTTNG_DOMAIN_UST = 2, | |
45 | }; | |
46 | ||
47 | %rename("EVENT_ALL") LTTNG_EVENT_ALL; | |
48 | %rename("EVENT_TRACEPOINT") LTTNG_EVENT_TRACEPOINT; | |
49 | %rename("EVENT_PROBE") LTTNG_EVENT_PROBE; | |
50 | %rename("EVENT_FUNCTION")LTTNG_EVENT_FUNCTION; | |
51 | %rename("EVENT_FUNCTION_ENTRY") LTTNG_EVENT_FUNCTION_ENTRY; | |
52 | %rename("EVENT_NOOP") LTTNG_EVENT_NOOP; | |
53 | %rename("EVENT_SYSCALL") LTTNG_EVENT_SYSCALL; | |
54 | enum lttng_event_type { | |
55 | LTTNG_EVENT_ALL = -1, | |
56 | LTTNG_EVENT_TRACEPOINT = 0, | |
57 | LTTNG_EVENT_PROBE = 1, | |
58 | LTTNG_EVENT_FUNCTION = 2, | |
59 | LTTNG_EVENT_FUNCTION_ENTRY = 3, | |
60 | LTTNG_EVENT_NOOP = 4, | |
61 | LTTNG_EVENT_SYSCALL = 5, | |
62 | }; | |
63 | ||
64 | %rename("EVENT_LOGLEVEL_ALL") LTTNG_EVENT_LOGLEVEL_ALL; | |
65 | %rename("EVENT_LOGLEVEL_RANGE") LTTNG_EVENT_LOGLEVEL_RANGE; | |
66 | %rename("EVENT_LOGLEVEL_SINGLE") LTTNG_EVENT_LOGLEVEL_SINGLE; | |
67 | enum lttng_loglevel_type { | |
68 | LTTNG_EVENT_LOGLEVEL_ALL = 0, | |
69 | LTTNG_EVENT_LOGLEVEL_RANGE = 1, | |
70 | LTTNG_EVENT_LOGLEVEL_SINGLE = 2, | |
71 | }; | |
72 | ||
73 | %rename("LOGLEVEL_EMERG") LTTNG_LOGLEVEL_EMERG; | |
74 | %rename("LOGLEVEL_ALERT") LTTNG_LOGLEVEL_ALERT; | |
75 | %rename("LOGLEVEL_CRIT") LTTNG_LOGLEVEL_CRIT; | |
76 | %rename("LOGLEVEL_ERR") LTTNG_LOGLEVEL_ERR; | |
77 | %rename("LOGLEVEL_WARNING") LTTNG_LOGLEVEL_WARNING; | |
78 | %rename("LOGLEVEL_NOTICE") LTTNG_LOGLEVEL_NOTICE; | |
79 | %rename("LOGLEVEL_INFO") LTTNG_LOGLEVEL_INFO; | |
80 | %rename("LOGLEVEL_DEBUG_SYSTEM") LTTNG_LOGLEVEL_DEBUG_SYSTEM; | |
81 | %rename("LOGLEVEL_DEBUG_PROGRAM") LTTNG_LOGLEVEL_DEBUG_PROGRAM; | |
82 | %rename("LOGLEVEL_DEBUG_PROCESS") LTTNG_LOGLEVEL_DEBUG_PROCESS; | |
83 | %rename("LOGLEVEL_DEBUG_MODULE") LTTNG_LOGLEVEL_DEBUG_MODULE; | |
84 | %rename("LOGLEVEL_DEBUG_UNIT") LTTNG_LOGLEVEL_DEBUG_UNIT; | |
85 | %rename("LOGLEVEL_DEBUG_FUNCTION") LTTNG_LOGLEVEL_DEBUG_FUNCTION; | |
86 | %rename("LOGLEVEL_DEBUG_LINE") LTTNG_LOGLEVEL_DEBUG_LINE; | |
87 | %rename("LOGLEVEL_DEBUG") LTTNG_LOGLEVEL_DEBUG; | |
88 | enum lttng_loglevel { | |
89 | LTTNG_LOGLEVEL_EMERG = 0, | |
90 | LTTNG_LOGLEVEL_ALERT = 1, | |
91 | LTTNG_LOGLEVEL_CRIT = 2, | |
92 | LTTNG_LOGLEVEL_ERR = 3, | |
93 | LTTNG_LOGLEVEL_WARNING = 4, | |
94 | LTTNG_LOGLEVEL_NOTICE = 5, | |
95 | LTTNG_LOGLEVEL_INFO = 6, | |
96 | LTTNG_LOGLEVEL_DEBUG_SYSTEM = 7, | |
97 | LTTNG_LOGLEVEL_DEBUG_PROGRAM = 8, | |
98 | LTTNG_LOGLEVEL_DEBUG_PROCESS = 9, | |
99 | LTTNG_LOGLEVEL_DEBUG_MODULE = 10, | |
100 | LTTNG_LOGLEVEL_DEBUG_UNIT = 11, | |
101 | LTTNG_LOGLEVEL_DEBUG_FUNCTION = 12, | |
102 | LTTNG_LOGLEVEL_DEBUG_LINE = 13, | |
103 | LTTNG_LOGLEVEL_DEBUG = 14, | |
104 | }; | |
105 | ||
106 | %rename("EVENT_SPLICE") LTTNG_EVENT_SPLICE; | |
107 | %rename("EVENT_MMAP") LTTNG_EVENT_MMAP; | |
108 | enum lttng_event_output { | |
109 | LTTNG_EVENT_SPLICE = 0, | |
110 | LTTNG_EVENT_MMAP = 1, | |
111 | }; | |
112 | ||
113 | %rename("EVENT_CONTEXT_PID") LTTNG_EVENT_CONTEXT_PID; | |
114 | %rename("EVENT_CONTEXT_PERF_COUNTER") LTTNG_EVENT_CONTEXT_PERF_COUNTER; | |
115 | %rename("EVENT_CONTEXT_PROCNAME") LTTNG_EVENT_CONTEXT_PROCNAME; | |
116 | %rename("EVENT_CONTEXT_PRIO") LTTNG_EVENT_CONTEXT_PRIO; | |
117 | %rename("EVENT_CONTEXT_NICE") LTTNG_EVENT_CONTEXT_NICE; | |
118 | %rename("EVENT_CONTEXT_VPID") LTTNG_EVENT_CONTEXT_VPID; | |
119 | %rename("EVENT_CONTEXT_TID") LTTNG_EVENT_CONTEXT_TID; | |
120 | %rename("EVENT_CONTEXT_VTID") LTTNG_EVENT_CONTEXT_VTID; | |
121 | %rename("EVENT_CONTEXT_PPID") LTTNG_EVENT_CONTEXT_PPID; | |
122 | %rename("EVENT_CONTEXT_VPPID") LTTNG_EVENT_CONTEXT_VPPID; | |
123 | %rename("EVENT_CONTEXT_PTHREAD_ID") LTTNG_EVENT_CONTEXT_PTHREAD_ID; | |
124 | enum lttng_event_context_type { | |
125 | LTTNG_EVENT_CONTEXT_PID = 0, | |
126 | LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1, | |
127 | LTTNG_EVENT_CONTEXT_PROCNAME = 2, | |
128 | LTTNG_EVENT_CONTEXT_PRIO = 3, | |
129 | LTTNG_EVENT_CONTEXT_NICE = 4, | |
130 | LTTNG_EVENT_CONTEXT_VPID = 5, | |
131 | LTTNG_EVENT_CONTEXT_TID = 6, | |
132 | LTTNG_EVENT_CONTEXT_VTID = 7, | |
133 | LTTNG_EVENT_CONTEXT_PPID = 8, | |
134 | LTTNG_EVENT_CONTEXT_VPPID = 9, | |
135 | LTTNG_EVENT_CONTEXT_PTHREAD_ID = 10, | |
136 | }; | |
137 | ||
36907cb5 DS |
138 | |
139 | ||
140 | ||
141 | // ============================================= | |
142 | // TYPEMAPS | |
143 | // ============================================= | |
144 | ||
145 | //list_sessions | |
146 | %typemap(argout) struct lttng_session **sessions{ | |
147 | ||
148 | int l = PyInt_AsSsize_t($result); | |
149 | if (l >= 0) | |
150 | { | |
151 | PyObject *sessions = PyList_New(0); | |
152 | int i; | |
153 | for(i=0; i<l; i++) | |
154 | { | |
155 | PyObject *tmp = PyTuple_New(4); | |
156 | PyObject *name = PyString_FromString((*$1)[i].name); | |
157 | PyObject *path = PyString_FromString((*$1)[i].path); | |
158 | PyObject *enabled = PyInt_FromSize_t((*$1)[i].enabled); | |
159 | PyObject *padding = PyString_FromString((*$1)[i].padding); | |
160 | ||
161 | PyTuple_SetItem(tmp, 0, name); | |
162 | PyTuple_SetItem(tmp, 1, path); | |
163 | PyTuple_SetItem(tmp, 2, enabled); | |
164 | PyTuple_SetItem(tmp, 3, padding); | |
165 | PyList_Append(sessions, tmp); | |
166 | } | |
167 | $result = sessions; | |
168 | } | |
169 | } | |
170 | %typemap(in,numinputs=0) struct lttng_session **sessions (struct lttng_session *temp){ | |
171 | $1=&temp; | |
172 | } | |
173 | ||
174 | //list_domains | |
175 | %typemap(argout) struct lttng_domain **domains{ | |
176 | ||
177 | int l = PyInt_AsSsize_t($result); | |
178 | if (l >= 0) | |
179 | { | |
180 | PyObject *dom = PyList_New(0); | |
181 | int i; | |
182 | for(i=0; i<l; i++) | |
183 | { | |
184 | PyObject *tmp = PyTuple_New(5); | |
185 | PyObject *type = PyInt_FromSize_t((*$1)[i].type); | |
186 | PyObject *execname = PyString_FromString((*$1)[i].attr.exec_name); | |
187 | PyObject *pid = PyInt_FromSize_t((*$1)[i].attr.pid); | |
188 | PyObject *padding = PyString_FromString((*$1)[i].padding); | |
189 | PyObject *attrpadding = PyString_FromString((*$1)[i].attr.padding); | |
190 | ||
191 | PyTuple_SetItem(tmp, 0, type); | |
192 | PyTuple_SetItem(tmp, 1, padding); | |
193 | PyTuple_SetItem(tmp, 2, pid); | |
194 | PyTuple_SetItem(tmp, 3, execname); | |
195 | PyTuple_SetItem(tmp, 4, attrpadding); | |
196 | PyList_Append(dom, tmp); | |
197 | } | |
198 | $result = dom; | |
199 | } | |
200 | } | |
201 | %typemap(in,numinputs=0) struct lttng_domain **domains (struct lttng_domain *temp){ | |
202 | $1=&temp; | |
203 | } | |
204 | ||
205 | //list_channels | |
206 | %typemap(argout) struct lttng_channel **channels{ | |
207 | ||
208 | int l = PyInt_AsSsize_t($result); | |
209 | if (l >= 0) | |
210 | { | |
211 | PyObject *chan = PyList_New(0); | |
212 | int i; | |
213 | for(i=0; i<l; i++) | |
214 | { | |
215 | PyObject *tmp = PyTuple_New(4); | |
216 | PyObject *name = PyString_FromString((*$1)[i].name); | |
217 | PyObject *enabled = PyInt_FromSize_t((*$1)[i].enabled); | |
218 | PyObject *padding = PyString_FromString((*$1)[i].padding); | |
219 | ||
220 | PyObject *attrtmp = PyTuple_New(7); | |
221 | PyObject *overwrite = PyInt_FromLong((*$1)[i].attr.overwrite); | |
222 | PyObject *subbuf = PyInt_FromSize_t((*$1)[i].attr.subbuf_size); | |
223 | PyObject *num = PyInt_FromSize_t((*$1)[i].attr.num_subbuf); | |
224 | PyObject *switchtimer = PyInt_FromSize_t((*$1)[i].attr.switch_timer_interval); | |
225 | PyObject *readtimer = PyInt_FromSize_t((*$1)[i].attr.read_timer_interval); | |
226 | PyObject *output = PyInt_FromSize_t((*$1)[i].attr.output); | |
227 | PyObject *attrpad = PyString_FromString((*$1)[i].attr.padding); | |
228 | ||
229 | PyTuple_SetItem(attrtmp, 0, overwrite); | |
230 | PyTuple_SetItem(attrtmp, 1, subbuf); | |
231 | PyTuple_SetItem(attrtmp, 2, num); | |
232 | PyTuple_SetItem(attrtmp, 3, switchtimer); | |
233 | PyTuple_SetItem(attrtmp, 4, readtimer); | |
234 | PyTuple_SetItem(attrtmp, 5, output); | |
235 | PyTuple_SetItem(attrtmp, 6, attrpad); | |
236 | ||
237 | PyTuple_SetItem(tmp, 0, name); | |
238 | PyTuple_SetItem(tmp, 1, enabled); | |
239 | PyTuple_SetItem(tmp, 2, padding); | |
240 | PyTuple_SetItem(tmp, 3, attrtmp); | |
241 | PyList_Append(chan, tmp); | |
242 | } | |
243 | $result = chan; | |
244 | } | |
245 | } | |
246 | %typemap(in,numinputs=0) struct lttng_channel **channels (struct lttng_channel *temp){ | |
247 | $1=&temp; | |
248 | } | |
249 | ||
250 | //list_events & list_tracepoints | |
251 | %typemap(argout) struct lttng_event **events{ | |
252 | ||
253 | int l = PyInt_AsSsize_t($result); | |
254 | if (l >= 0) | |
255 | { | |
256 | PyObject *events = PyList_New(0); | |
257 | int i; | |
258 | for(i=0; i<l; i++) | |
259 | { | |
260 | PyObject *tmp = PyTuple_New(10); | |
261 | PyObject *name = PyString_FromString((*$1)[i].name); | |
262 | PyObject *type = PyInt_FromSize_t((*$1)[i].type); | |
263 | PyObject *logleveltype = PyInt_FromSize_t((*$1)[i].loglevel_type); | |
264 | PyObject *loglevel = PyInt_FromLong((*$1)[i].loglevel); | |
265 | PyObject *enabled = PyInt_FromLong((*$1)[i].enabled); | |
266 | PyObject *pid = PyInt_FromSize_t((*$1)[i].pid); | |
267 | PyObject *padding = PyString_FromString((*$1)[i].padding); | |
268 | PyObject *attrpadding = PyString_FromString((*$1)[i].attr.padding); | |
269 | ||
270 | PyObject *probe = PyTuple_New(4); | |
271 | PyObject *addr = PyInt_FromSize_t((*$1)[i].attr.probe.addr); | |
272 | PyObject *offset = PyInt_FromSize_t((*$1)[i].attr.probe.offset); | |
273 | PyObject *symbolname = PyString_FromString((*$1)[i].attr.probe.symbol_name); | |
274 | PyObject *probepad = PyString_FromString((*$1)[i].attr.probe.padding); | |
275 | ||
276 | PyObject *function = PyTuple_New(2); | |
277 | PyObject *f_symbolname = PyString_FromString((*$1)[i].attr.ftrace.symbol_name); | |
278 | PyObject *f_pad = PyString_FromString((*$1)[i].attr.ftrace.padding); | |
279 | ||
280 | PyTuple_SetItem(function, 0, f_symbolname); | |
281 | PyTuple_SetItem(function, 1, f_pad); | |
282 | ||
283 | PyTuple_SetItem(probe, 0, addr); | |
284 | PyTuple_SetItem(probe, 1, offset); | |
285 | PyTuple_SetItem(probe, 2, symbolname); | |
286 | PyTuple_SetItem(probe, 3, probepad); | |
287 | ||
288 | PyTuple_SetItem(tmp, 0, name); | |
289 | PyTuple_SetItem(tmp, 1, type); | |
290 | PyTuple_SetItem(tmp, 2, logleveltype); | |
291 | PyTuple_SetItem(tmp, 3, loglevel); | |
292 | PyTuple_SetItem(tmp, 4, enabled); | |
293 | PyTuple_SetItem(tmp, 5, pid); | |
294 | PyTuple_SetItem(tmp, 6, padding); | |
295 | PyTuple_SetItem(tmp, 7, probe); | |
296 | PyTuple_SetItem(tmp, 8, function); | |
297 | PyTuple_SetItem(tmp, 9, attrpadding); | |
298 | PyList_Append(events, tmp); | |
299 | } | |
300 | $result = events; | |
301 | } | |
302 | } | |
303 | %typemap(in,numinputs=0) struct lttng_event **events (struct lttng_event *temp){ | |
304 | $1=&temp; | |
305 | } | |
306 | ||
307 | ||
308 | ||
309 | // ============================================= | |
310 | // FUNCTIONS | |
311 | // ============================================= | |
312 | ||
313 | %rename("create") lttng_create_session(const char *name, const char *path); | |
9e52b0d8 | 314 | %rename("create_snapshot") lttng_create_session_snapshot(const char *name, const char *snapshot_url); |
36907cb5 DS |
315 | %rename("destroy") lttng_destroy_session(const char *name); |
316 | %rename("_lttng_create_handle") lttng_create_handle(const char *session_name, struct lttng_domain *domain); | |
317 | %rename("_lttng_destroy_handle") lttng_destroy_handle(struct lttng_handle *handle); | |
318 | %rename("_lttng_list_sessions") lttng_list_sessions(struct lttng_session **sessions); | |
319 | %rename("_lttng_list_domains") lttng_list_domains(const char *session_name, struct lttng_domain **domains); | |
320 | %rename("_lttng_list_channels") lttng_list_channels(struct lttng_handle *handle,struct lttng_channel **channels); | |
321 | %rename("_lttng_list_events") lttng_list_events(struct lttng_handle *handle, const char *channel_name, struct lttng_event **events); | |
322 | %rename("_lttng_list_tracepoints") lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events); | |
323 | %rename("session_daemon_alive") lttng_session_daemon_alive(void); | |
324 | %rename("set_tracing_group") lttng_set_tracing_group(const char *name); | |
325 | %rename("strerror") lttng_strerror(int code); | |
326 | %rename("_lttng_register_consumer") lttng_register_consumer(struct lttng_handle *handle, const char *socket_path); | |
327 | %rename("start") lttng_start_tracing(const char *session_name); | |
328 | %rename("stop") lttng_stop_tracing(const char *session_name); | |
329 | %rename("_lttng_add_context") lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx, const char *event_name, const char *channel_name); | |
330 | %rename("_lttng_enable_event") lttng_enable_event(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name); | |
331 | %rename("_lttng_enable_channel") lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan); | |
332 | %rename("_lttng_disable_event") lttng_disable_event(struct lttng_handle *handle, const char *name, const char *channel_name); | |
333 | %rename("_lttng_disable_channel") lttng_disable_channel(struct lttng_handle *handle, const char *name); | |
36907cb5 DS |
334 | %rename("channel_set_default_attr") lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr); |
335 | ||
336 | //Redefined functions | |
337 | struct lttng_handle *lttng_create_handle(const char *session_name, | |
338 | struct lttng_domain *domain); | |
339 | void lttng_destroy_handle(struct lttng_handle *handle); | |
340 | int lttng_list_channels(struct lttng_handle *handle,struct lttng_channel **channels); | |
341 | int lttng_list_events(struct lttng_handle *handle, | |
342 | const char *channel_name, struct lttng_event **events); | |
343 | int lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events); | |
344 | int lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx, | |
345 | const char *event_name, const char *channel_name); | |
346 | int lttng_enable_event(struct lttng_handle *handle, | |
347 | struct lttng_event *ev, const char *channel_name); | |
348 | int lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan); | |
349 | int lttng_disable_event(struct lttng_handle *handle, | |
350 | const char *name, const char *channel_name); | |
351 | int lttng_disable_channel(struct lttng_handle *handle, const char *name); | |
36907cb5 DS |
352 | int lttng_register_consumer(struct lttng_handle *handle, const char *socket_path); |
353 | int lttng_list_sessions(struct lttng_session **sessions); | |
354 | int lttng_list_domains(const char *session_name, struct lttng_domain **domains); | |
355 | ||
356 | //Functions not needing redefinition | |
357 | %feature("docstring")"create(str name, str path) -> int | |
358 | ||
359 | Create a new tracing session using name and path. | |
9e52b0d8 | 360 | Returns 0 on success or a negative error code." |
36907cb5 DS |
361 | int lttng_create_session(const char *name, const char *path); |
362 | ||
9e52b0d8 MD |
363 | %feature("docstring")"create_snapshot(str name, str snapshot_url) -> int |
364 | ||
365 | Create a new tracing session using name and snapshot_url in snapshot | |
366 | mode (flight recorder). | |
367 | Returns 0 on success or a negative error code." | |
368 | int lttng_create_session_snapshot(const char *name, const char *path); | |
36907cb5 DS |
369 | |
370 | %feature("docstring")"destroy(str name) -> int | |
371 | ||
372 | Tear down tracing session using name. | |
9e52b0d8 | 373 | Returns 0 on success or a negative error code." |
36907cb5 DS |
374 | int lttng_destroy_session(const char *name); |
375 | ||
376 | ||
377 | %feature("docstring")"session_daemon_alive() -> int | |
378 | ||
379 | Check if session daemon is alive. | |
380 | Return 1 if alive or 0 if not. | |
381 | On error returns a negative value." | |
382 | int lttng_session_daemon_alive(void); | |
383 | ||
384 | ||
385 | %feature("docstring")"set_tracing_group(str name) -> int | |
386 | ||
387 | Sets the tracing_group variable with name. | |
388 | This function allocates memory pointed to by tracing_group. | |
389 | On success, returns 0, on error, returns -1 (null name) or -ENOMEM." | |
390 | int lttng_set_tracing_group(const char *name); | |
391 | ||
392 | ||
393 | %feature("docstring")"strerror(int code) -> char | |
394 | ||
395 | Returns a human readable string describing | |
396 | the error code (a negative value)." | |
397 | const char *lttng_strerror(int code); | |
398 | ||
399 | ||
400 | %feature("docstring")"start(str session_name) -> int | |
401 | ||
402 | Start tracing for all traces of the session. | |
403 | Returns size of returned session payload data or a negative error code." | |
404 | int lttng_start_tracing(const char *session_name); | |
405 | ||
406 | ||
407 | %feature("docstring")"stop(str session_name) -> int | |
408 | ||
409 | Stop tracing for all traces of the session. | |
410 | Returns size of returned session payload data or a negative error code." | |
411 | int lttng_stop_tracing(const char *session_name); | |
412 | ||
413 | ||
414 | %feature("docstring")"channel_set_default_attr(Domain domain, ChannelAttr attr) | |
415 | ||
416 | Set default channel attributes. | |
417 | If either or both of the arguments are null, attr content is zeroe'd." | |
418 | void lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr); | |
419 | ||
420 | ||
421 | // ============================================= | |
422 | // Python redefinition of some functions | |
423 | // (List and Handle-related) | |
424 | // ============================================= | |
425 | ||
426 | %feature("docstring")"" | |
427 | %pythoncode %{ | |
428 | ||
429 | def list_sessions(): | |
430 | """ | |
431 | list_sessions() -> dict | |
432 | ||
433 | Ask the session daemon for all available sessions. | |
434 | Returns a dict of Session instances, the key is the name; | |
435 | on error, returns a negative value. | |
436 | """ | |
437 | ||
438 | ses_list = _lttng_list_sessions() | |
439 | if type(ses_list) is int: | |
440 | return ses_list | |
441 | ||
442 | sessions = {} | |
443 | ||
444 | for ses_elements in ses_list: | |
445 | ses = Session() | |
446 | ses.name = ses_elements[0] | |
447 | ses.path = ses_elements[1] | |
448 | ses.enabled = ses_elements[2] | |
449 | ses.padding = ses_elements[3] | |
450 | ||
451 | sessions[ses.name] = ses | |
452 | ||
453 | return sessions | |
454 | ||
455 | ||
456 | def list_domains(session_name): | |
457 | """ | |
458 | list_domains(str session_name) -> list | |
459 | ||
460 | Ask the session daemon for all available domains of a session. | |
461 | Returns a list of Domain instances; | |
462 | on error, returns a negative value. | |
463 | """ | |
464 | ||
465 | dom_list = _lttng_list_domains(session_name) | |
466 | if type(dom_list) is int: | |
467 | return dom_list | |
468 | ||
469 | domains = [] | |
470 | ||
471 | for dom_elements in dom_list: | |
472 | dom = Domain() | |
473 | dom.type = dom_elements[0] | |
474 | dom.paddinf = dom_elements[1] | |
475 | dom.attr.pid = dom_elements[2] | |
476 | dom.attr.exec_name = dom_elements[3] | |
477 | dom.attr.padding = dom_elements[4] | |
478 | ||
479 | domains.append(dom) | |
480 | ||
481 | return domains | |
482 | ||
483 | ||
484 | def list_channels(handle): | |
485 | """ | |
486 | list_channels(Handle handle) -> dict | |
487 | ||
488 | Ask the session daemon for all available channels of a session. | |
489 | Returns a dict of Channel instances, the key is the name; | |
490 | on error, returns a negative value. | |
491 | """ | |
492 | ||
493 | try: | |
494 | chan_list = _lttng_list_channels(handle._h) | |
495 | except AttributeError: | |
496 | raise TypeError("in method 'list_channels', argument 1 must be a Handle instance") | |
497 | ||
498 | if type(chan_list) is int: | |
499 | return chan_list | |
500 | ||
501 | channels = {} | |
502 | ||
503 | for channel_elements in chan_list: | |
504 | chan = Channel() | |
505 | chan.name = channel_elements[0] | |
506 | chan.enabled = channel_elements[1] | |
507 | chan.padding = channel_elements[2] | |
508 | chan.attr.overwrite = channel_elements[3][0] | |
509 | chan.attr.subbuf_size = channel_elements[3][1] | |
510 | chan.attr.num_subbuf = channel_elements[3][2] | |
511 | chan.attr.switch_timer_interval = channel_elements[3][3] | |
512 | chan.attr.read_timer_interval = channel_elements[3][4] | |
513 | chan.attr.output = channel_elements[3][5] | |
514 | chan.attr.padding = channel_elements[3][6] | |
515 | ||
516 | channels[chan.name] = chan | |
517 | ||
518 | return channels | |
519 | ||
520 | ||
521 | def list_events(handle, channel_name): | |
522 | """ | |
523 | list_events(Handle handle, str channel_name) -> dict | |
524 | ||
525 | Ask the session daemon for all available events of a session channel. | |
526 | Returns a dict of Event instances, the key is the name; | |
527 | on error, returns a negative value. | |
528 | """ | |
529 | ||
530 | try: | |
531 | ev_list = _lttng_list_events(handle._h, channel_name) | |
532 | except AttributeError: | |
533 | raise TypeError("in method 'list_events', argument 1 must be a Handle instance") | |
534 | ||
535 | if type(ev_list) is int: | |
536 | return ev_list | |
537 | ||
538 | events = {} | |
539 | ||
540 | for ev_elements in ev_list: | |
541 | ev = Event() | |
542 | ev.name = ev_elements[0] | |
543 | ev.type = ev_elements[1] | |
544 | ev.loglevel_type = ev_elements[2] | |
545 | ev.loglevel = ev_elements[3] | |
546 | ev.enabled = ev_elements[4] | |
547 | ev.pid = ev_elements[5] | |
548 | ev.attr.padding = ev_elements[6] | |
549 | ev.attr.probe.addr = ev_elements[7][0] | |
550 | ev.attr.probe.offset = ev_elements[7][1] | |
551 | ev.attr.probe.symbol_name = ev_elements[7][2] | |
552 | ev.attr.probe.padding = ev_elements[7][3] | |
553 | ev.attr.ftrace.symbol_name = ev_elements[8][0] | |
554 | ev.attr.ftrace.padding = ev_elements[8][1] | |
555 | ev.attr.padding = ev_elements[9] | |
556 | ||
557 | events[ev.name] = ev | |
558 | ||
559 | return events | |
560 | ||
561 | ||
562 | def list_tracepoints(handle): | |
563 | """ | |
564 | list_tracepoints(Handle handle) -> dict | |
565 | ||
566 | Returns a dict of Event instances, the key is the name; | |
567 | on error, returns a negative value. | |
568 | """ | |
569 | ||
570 | try: | |
571 | ev_list = _lttng_list_tracepoints(handle._h) | |
572 | except AttributeError: | |
573 | raise TypeError("in method 'list_tracepoints', argument 1 must be a Handle instance") | |
574 | ||
575 | if type(ev_list) is int: | |
576 | return ev_list | |
577 | ||
578 | events = {} | |
579 | ||
580 | for ev_elements in ev_list: | |
581 | ev = Event() | |
582 | ev.name = ev_elements[0] | |
583 | ev.type = ev_elements[1] | |
584 | ev.loglevel_type = ev_elements[2] | |
585 | ev.loglevel = ev_elements[3] | |
586 | ev.enabled = ev_elements[4] | |
587 | ev.pid = ev_elements[5] | |
588 | ev.attr.padding = ev_elements[6] | |
589 | ev.attr.probe.addr = ev_elements[7][0] | |
590 | ev.attr.probe.offset = ev_elements[7][1] | |
591 | ev.attr.probe.symbol_name = ev_elements[7][2] | |
592 | ev.attr.probe.padding = ev_elements[7][3] | |
593 | ev.attr.ftrace.symbol_name = ev_elements[8][0] | |
594 | ev.attr.ftrace.padding = ev_elements[8][1] | |
595 | ev.attr.padding = ev_elements[9] | |
596 | ||
597 | events[ev.name] = ev | |
598 | ||
599 | return events | |
600 | ||
601 | ||
602 | def register_consumer(handle, socket_path): | |
603 | """ | |
604 | register_consumer(Handle handle, str socket_path) -> int | |
605 | ||
606 | Register an outside consumer. | |
607 | Returns size of returned session payload data or a negative error code. | |
608 | """ | |
609 | ||
610 | try: | |
611 | return _lttng_register_consumer(handle._h, socket_path) | |
612 | except AttributeError: | |
613 | raise TypeError("in method 'register_consumer', argument 1 must be a Handle instance") | |
614 | ||
615 | ||
616 | def add_context(handle, event_context, event_name, channel_name): | |
617 | """ | |
618 | add_context(Handle handle, EventContext ctx, | |
619 | str event_name, str channel_name) -> int | |
620 | ||
621 | Add context to event and/or channel. | |
622 | If event_name is None, the context is applied to all events of the channel. | |
623 | If channel_name is None, a lookup of the event's channel is done. | |
624 | If both are None, the context is applied to all events of all channels. | |
625 | Returns the size of the returned payload data or a negative error code. | |
626 | """ | |
627 | ||
628 | try: | |
629 | return _lttng_add_context(handle._h, event_context, event_name, channel_name) | |
630 | except AttributeError: | |
631 | raise TypeError("in method 'add_context', argument 1 must be a Handle instance") | |
632 | ||
633 | ||
634 | def enable_event(handle, event, channel_name): | |
635 | """ | |
636 | enable_event(Handle handle, Event event, | |
637 | str channel_name) -> int | |
638 | ||
639 | Enable event(s) for a channel. | |
640 | If no event name is specified, all events are enabled. | |
641 | If no channel name is specified, the default 'channel0' is used. | |
642 | Returns size of returned session payload data or a negative error code. | |
643 | """ | |
644 | ||
645 | try: | |
646 | return _lttng_enable_event(handle._h, event, channel_name) | |
647 | except AttributeError: | |
648 | raise TypeError("in method 'enable_event', argument 1 must be a Handle instance") | |
649 | ||
650 | ||
651 | def enable_channel(handle, channel): | |
652 | """ | |
653 | enable_channel(Handle handle, Channel channel -> int | |
654 | ||
655 | Enable channel per domain | |
656 | Returns size of returned session payload data or a negative error code. | |
657 | """ | |
658 | ||
659 | try: | |
660 | return _lttng_enable_channel(handle._h, channel) | |
661 | except AttributeError: | |
662 | raise TypeError("in method 'enable_channel', argument 1 must be a Handle instance") | |
663 | ||
664 | ||
665 | def disable_event(handle, name, channel_name): | |
666 | """ | |
667 | disable_event(Handle handle, str name, str channel_name) -> int | |
668 | ||
669 | Disable event(s) of a channel and domain. | |
670 | If no event name is specified, all events are disabled. | |
671 | If no channel name is specified, the default 'channel0' is used. | |
672 | Returns size of returned session payload data or a negative error code | |
673 | """ | |
674 | ||
675 | try: | |
676 | return _lttng_disable_event(handle._h, name, channel_name) | |
677 | except AttributeError: | |
678 | raise TypeError("in method 'disable_event', argument 1 must be a Handle instance") | |
679 | ||
680 | ||
681 | def disable_channel(handle, name): | |
682 | """ | |
683 | disable_channel(Handle handle, str name) -> int | |
684 | ||
685 | All tracing will be stopped for registered events of the channel. | |
686 | Returns size of returned session payload data or a negative error code. | |
687 | """ | |
688 | ||
689 | try: | |
690 | return _lttng_disable_channel(handle._h, name) | |
691 | except AttributeError: | |
692 | raise TypeError("in method 'disable_channel', argument 1 must be a Handle instance") | |
36907cb5 DS |
693 | %} |
694 | ||
695 | ||
696 | // ============================================= | |
697 | // Handle class | |
698 | // Used to prevent freeing unallocated memory | |
699 | // ============================================= | |
700 | ||
701 | %feature("docstring")"" | |
702 | %feature("autodoc", "1"); | |
703 | ||
704 | %pythoncode %{ | |
705 | class Handle: | |
9c2fd06d | 706 | """ |
36907cb5 DS |
707 | Manages a handle. |
708 | Takes two arguments: (str session_name, Domain domain) | |
709 | """ | |
710 | ||
711 | __frozen = False | |
712 | ||
713 | def __init__(self, session_name, domain): | |
714 | if type(session_name) is not str: | |
715 | raise TypeError("in method '__init__', argument 2 of type 'str'") | |
716 | if type(domain) is not Domain and domain is not None: | |
717 | raise TypeError("in method '__init__', argument 3 of type 'lttng.Domain'") | |
718 | ||
719 | self._sname = session_name | |
720 | if domain is None: | |
721 | self._domtype = None | |
722 | else: | |
723 | self._domtype = domain.type | |
724 | self._h = _lttng_create_handle(session_name, domain) | |
725 | self.__frozen = True | |
726 | ||
727 | def __del__(self): | |
728 | _lttng_destroy_handle(self._h) | |
729 | ||
730 | def __repr__(self): | |
731 | if self._domtype == 1: | |
732 | domstr = "DOMAIN_KERNEL" | |
733 | elif self._domtype == 2: | |
734 | domstr = "DOMAIN_UST" | |
735 | else: | |
736 | domstr = self._domtype | |
737 | ||
738 | return "lttng.Handle; session('{}'), domain.type({})".format( | |
739 | self._sname, domstr) | |
740 | ||
741 | def __setattr__(self, attr, val): | |
742 | if self.__frozen: | |
743 | raise NotImplementedError("cannot modify attributes") | |
744 | else: | |
745 | self.__dict__[attr] = val | |
746 | %} | |
747 | ||
748 | ||
749 | // ============================================= | |
750 | // STRUCTURES | |
751 | // These are directly taken from lttng.h. | |
752 | // Any change to these structures must also be | |
753 | // made here. | |
754 | // ============================================= | |
755 | ||
756 | %rename("Domain") lttng_domain; | |
757 | %rename("EventContext") lttng_event_context; | |
758 | %rename("Event") lttng_event; | |
36907cb5 DS |
759 | %rename("ChannelAttr") lttng_channel_attr; |
760 | %rename("Channel") lttng_channel; | |
761 | %rename("Session") lttng_session; | |
762 | ||
763 | struct lttng_domain{ | |
764 | enum lttng_domain_type type; | |
765 | char padding[LTTNG_DOMAIN_PADDING1]; | |
766 | ||
767 | union { | |
768 | pid_t pid; | |
769 | char exec_name[NAME_MAX]; | |
770 | char padding[LTTNG_DOMAIN_PADDING2]; | |
771 | } attr; | |
772 | ||
773 | %extend { | |
774 | char *__repr__() { | |
775 | static char temp[256]; | |
776 | switch ( $self->type ) { | |
777 | case 1: | |
778 | sprintf(temp, "lttng.Domain; type(DOMAIN_KERNEL)"); | |
779 | break; | |
780 | case 2: | |
781 | sprintf(temp, "lttng.Domain; type(DOMAIN_UST)"); | |
782 | break; | |
783 | default: | |
784 | sprintf(temp, "lttng.Domain; type(%i)", $self->type); | |
785 | break; | |
786 | } | |
787 | return &temp[0]; | |
788 | } | |
789 | } | |
790 | }; | |
791 | ||
792 | struct lttng_event_context { | |
793 | enum lttng_event_context_type ctx; | |
794 | char padding[LTTNG_EVENT_CONTEXT_PADDING1]; | |
795 | ||
796 | union { | |
797 | struct lttng_event_perf_counter_ctx perf_counter; | |
798 | char padding[LTTNG_EVENT_CONTEXT_PADDING2]; | |
799 | } u; | |
800 | ||
801 | %extend { | |
802 | char *__repr__() { | |
803 | static char temp[256]; | |
804 | switch ( $self->ctx ) { | |
805 | case 0: | |
806 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PID)"); | |
807 | break; | |
808 | case 1: | |
809 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PERF_COUNTER)"); | |
810 | break; | |
811 | case 2: | |
812 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PROCNAME)"); | |
813 | break; | |
814 | case 3: | |
815 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PRIO)"); | |
816 | break; | |
817 | case 4: | |
818 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_NICE)"); | |
819 | break; | |
820 | case 5: | |
821 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VPID)"); | |
822 | break; | |
823 | case 6: | |
824 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_TID)"); | |
825 | break; | |
826 | case 7: | |
827 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VTID)"); | |
828 | break; | |
829 | case 8: | |
830 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PPID)"); | |
831 | break; | |
832 | case 9: | |
833 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VPPID)"); | |
834 | break; | |
835 | case 10: | |
836 | sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PTHREAD_ID)"); | |
837 | break; | |
838 | default: | |
839 | sprintf(temp, "lttng.EventContext; type(%i)", $self->ctx); | |
840 | break; | |
841 | } | |
842 | return &temp[0]; | |
843 | } | |
844 | } | |
845 | }; | |
846 | ||
b6648478 JG |
847 | struct lttng_event_probe_attr { |
848 | uint64_t addr; | |
849 | uint64_t offset; | |
850 | char symbol_name[LTTNG_SYMBOL_NAME_LEN]; | |
851 | char padding[LTTNG_EVENT_PROBE_PADDING1]; | |
852 | }; | |
36907cb5 | 853 | |
b6648478 JG |
854 | struct lttng_event_function_attr { |
855 | char symbol_name[LTTNG_SYMBOL_NAME_LEN]; | |
856 | char padding[LTTNG_EVENT_FUNCTION_PADDING1]; | |
857 | }; | |
36907cb5 | 858 | |
b6648478 JG |
859 | struct lttng_event { |
860 | enum lttng_event_type type; | |
861 | char name[LTTNG_SYMBOL_NAME_LEN]; | |
36907cb5 | 862 | |
b6648478 JG |
863 | enum lttng_loglevel_type loglevel_type; |
864 | int loglevel; | |
865 | ||
866 | int32_t enabled; | |
867 | pid_t pid; | |
868 | ||
869 | char padding[LTTNG_EVENT_PADDING1]; | |
870 | ||
871 | union { | |
872 | struct lttng_event_probe_attr probe; | |
873 | struct lttng_event_function_attr ftrace; | |
874 | ||
875 | char padding[LTTNG_EVENT_PADDING2]; | |
876 | } attr; | |
877 | ||
878 | %extend { | |
879 | char *__repr__() { | |
880 | static char temp[512]; | |
881 | char evtype[50]; | |
882 | char logtype[50]; | |
883 | ||
884 | switch ( $self->type ) { | |
885 | case -1: | |
886 | sprintf(evtype, "EVENT_ALL"); | |
887 | break; | |
888 | case 0: | |
889 | sprintf(evtype, "EVENT_TRACEPOINT"); | |
890 | break; | |
891 | case 1: | |
892 | sprintf(evtype, "EVENT_PROBE"); | |
893 | break; | |
894 | case 2: | |
895 | sprintf(evtype, "EVENT_FUNCTION"); | |
896 | break; | |
897 | case 3: | |
898 | sprintf(evtype, "EVENT_FUNCTION_ENTRY"); | |
899 | break; | |
900 | case 4: | |
901 | sprintf(evtype, "EVENT_NOOP"); | |
902 | break; | |
903 | case 5: | |
904 | sprintf(evtype, "EVENT_SYSCALL"); | |
905 | break; | |
906 | default: | |
907 | sprintf(evtype, "%i", $self->type); | |
908 | break; | |
909 | } | |
910 | ||
911 | switch ( $self->loglevel_type ) { | |
912 | case 0: | |
913 | sprintf(logtype, "EVENT_LOGLEVEL_ALL"); | |
914 | break; | |
915 | case 1: | |
916 | sprintf(logtype, "EVENT_LOGLEVEL_RANGE"); | |
917 | break; | |
918 | case 2: | |
919 | sprintf(logtype, "EVENT_LOGLEVEL_SINGLE"); | |
920 | break; | |
921 | default: | |
922 | sprintf(logtype, "%i", $self->loglevel_type); | |
923 | break; | |
924 | } | |
925 | ||
926 | sprintf(temp, "lttng.Event; name('%s'), type(%s), " | |
927 | "loglevel_type(%s), loglevel(%i), " | |
928 | "enabled(%s), pid(%i)", | |
929 | $self->name, evtype, logtype, $self->loglevel, | |
930 | $self->enabled ? "True" : "False", $self->pid); | |
931 | return &temp[0]; | |
36907cb5 DS |
932 | } |
933 | } | |
b6648478 JG |
934 | }; |
935 | ||
b6648478 JG |
936 | struct lttng_channel_attr { |
937 | int overwrite; | |
938 | uint64_t subbuf_size; | |
939 | uint64_t num_subbuf; | |
940 | unsigned int switch_timer_interval; | |
941 | unsigned int read_timer_interval; | |
942 | enum lttng_event_output output; | |
943 | ||
944 | char padding[LTTNG_CHANNEL_ATTR_PADDING1]; | |
945 | ||
946 | %extend { | |
947 | char *__repr__() { | |
948 | static char temp[256]; | |
949 | char evout[25]; | |
950 | ||
951 | switch ( $self->output ) { | |
952 | case 0: | |
953 | sprintf(evout, "EVENT_SPLICE"); | |
954 | break; | |
955 | case 1: | |
956 | sprintf(evout, "EVENT_MMAP"); | |
957 | break; | |
958 | default: | |
959 | sprintf(evout, "%i", $self->output); | |
960 | break; | |
961 | } | |
bc3bdada JG |
962 | sprintf(temp, "lttng.ChannelAttr; overwrite(%i), subbuf_size(%"PRIu64"), " |
963 | "num_subbuf(%"PRIu64"), switch_timer_interval(%u), " | |
b6648478 JG |
964 | "read_timer_interval(%u), output(%s)", |
965 | $self->overwrite, $self->subbuf_size, $self->num_subbuf, | |
966 | $self->switch_timer_interval, $self->read_timer_interval, | |
967 | evout); | |
968 | return &temp[0]; | |
969 | } | |
dcac8046 | 970 | } |
b6648478 JG |
971 | }; |
972 | ||
973 | struct lttng_channel { | |
974 | char name[LTTNG_SYMBOL_NAME_LEN]; | |
975 | uint32_t enabled; | |
976 | struct lttng_channel_attr attr; | |
977 | char padding[LTTNG_CHANNEL_PADDING1]; | |
36907cb5 | 978 | |
b6648478 JG |
979 | %extend { |
980 | char *__repr__() { | |
981 | static char temp[512]; | |
25986cde | 982 | snprintf(temp, sizeof(temp), "lttng.Channel; name('%s'), enabled(%s)", |
b6648478 JG |
983 | $self->name, $self->enabled ? "True" : "False"); |
984 | return &temp[0]; | |
985 | } | |
36907cb5 | 986 | } |
b6648478 | 987 | }; |
dcac8046 | 988 | |
b6648478 JG |
989 | struct lttng_session { |
990 | char name[NAME_MAX]; | |
991 | char path[PATH_MAX]; | |
992 | uint32_t enabled; | |
993 | char padding[LTTNG_SESSION_PADDING1]; | |
994 | ||
995 | %extend { | |
996 | char *__repr__() { | |
25986cde JG |
997 | static char temp[PATH_MAX + NAME_MAX + 512]; |
998 | snprintf(temp, sizeof(temp), "lttng.Session; name('%s'), path('%s'), enabled(%s)", | |
b6648478 JG |
999 | $self->name, $self->path, |
1000 | $self->enabled ? "True" : "False"); | |
1001 | return &temp[0]; | |
1002 | } | |
1003 | } | |
1004 | }; |