2 * Copyright (C) 2012 Danny Serres <danny.serres@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
11 The LTTng project aims at providing highly efficient tracing tools for Linux.
12 It's tracers help tracking down performance issues and debugging problems involving
13 multiple concurrent processes and threads. Tracing across multiple systems is also possible."
16 %module(docstring=DOCSTRING) lttng
22 #define SWIG_FILE_WITH_INIT
23 #include <lttng/lttng.h>
27 #if PY_MAJOR_VERSION >= 3
28 // The PyInt and PyLong types were unified as of Python 3
29 // This makes the typemap code useable with both Python 2 and 3.
30 #define PyInt_AsSsize_t PyLong_AsSsize_t
33 // Avoid -Wmissing-declarations warning.
34 PyObject *SWIG_init(void);
37 typedef unsigned int uint32_t;
39 typedef unsigned long long uint64_t;
43 // =============================================
45 // These are directly taken from lttng.h.
46 // Any change to these enums must also be
48 // =============================================
50 %rename("DOMAIN_KERNEL") LTTNG_DOMAIN_KERNEL;
51 %rename("DOMAIN_UST") LTTNG_DOMAIN_UST;
52 enum lttng_domain_type {
53 LTTNG_DOMAIN_KERNEL = 1,
57 %rename("BUFFER_PER_PID") LTTNG_BUFFER_PER_PID;
58 %rename("BUFFER_PER_UID") LTTNG_BUFFER_PER_UID;
59 %rename("BUFFER_GLOBAL") LTTNG_BUFFER_GLOBAL;
60 enum lttng_buffer_type {
66 %rename("EVENT_ALL") LTTNG_EVENT_ALL;
67 %rename("EVENT_TRACEPOINT") LTTNG_EVENT_TRACEPOINT;
68 %rename("EVENT_PROBE") LTTNG_EVENT_PROBE;
69 %rename("EVENT_FUNCTION")LTTNG_EVENT_FUNCTION;
70 %rename("EVENT_FUNCTION_ENTRY") LTTNG_EVENT_FUNCTION_ENTRY;
71 %rename("EVENT_NOOP") LTTNG_EVENT_NOOP;
72 %rename("EVENT_SYSCALL") LTTNG_EVENT_SYSCALL;
73 enum lttng_event_type {
75 LTTNG_EVENT_TRACEPOINT = 0,
76 LTTNG_EVENT_PROBE = 1,
77 LTTNG_EVENT_FUNCTION = 2,
78 LTTNG_EVENT_FUNCTION_ENTRY = 3,
80 LTTNG_EVENT_SYSCALL = 5,
83 %rename("EVENT_LOGLEVEL_ALL") LTTNG_EVENT_LOGLEVEL_ALL;
84 %rename("EVENT_LOGLEVEL_RANGE") LTTNG_EVENT_LOGLEVEL_RANGE;
85 %rename("EVENT_LOGLEVEL_SINGLE") LTTNG_EVENT_LOGLEVEL_SINGLE;
86 enum lttng_loglevel_type {
87 LTTNG_EVENT_LOGLEVEL_ALL = 0,
88 LTTNG_EVENT_LOGLEVEL_RANGE = 1,
89 LTTNG_EVENT_LOGLEVEL_SINGLE = 2,
92 %rename("LOGLEVEL_EMERG") LTTNG_LOGLEVEL_EMERG;
93 %rename("LOGLEVEL_ALERT") LTTNG_LOGLEVEL_ALERT;
94 %rename("LOGLEVEL_CRIT") LTTNG_LOGLEVEL_CRIT;
95 %rename("LOGLEVEL_ERR") LTTNG_LOGLEVEL_ERR;
96 %rename("LOGLEVEL_WARNING") LTTNG_LOGLEVEL_WARNING;
97 %rename("LOGLEVEL_NOTICE") LTTNG_LOGLEVEL_NOTICE;
98 %rename("LOGLEVEL_INFO") LTTNG_LOGLEVEL_INFO;
99 %rename("LOGLEVEL_DEBUG_SYSTEM") LTTNG_LOGLEVEL_DEBUG_SYSTEM;
100 %rename("LOGLEVEL_DEBUG_PROGRAM") LTTNG_LOGLEVEL_DEBUG_PROGRAM;
101 %rename("LOGLEVEL_DEBUG_PROCESS") LTTNG_LOGLEVEL_DEBUG_PROCESS;
102 %rename("LOGLEVEL_DEBUG_MODULE") LTTNG_LOGLEVEL_DEBUG_MODULE;
103 %rename("LOGLEVEL_DEBUG_UNIT") LTTNG_LOGLEVEL_DEBUG_UNIT;
104 %rename("LOGLEVEL_DEBUG_FUNCTION") LTTNG_LOGLEVEL_DEBUG_FUNCTION;
105 %rename("LOGLEVEL_DEBUG_LINE") LTTNG_LOGLEVEL_DEBUG_LINE;
106 %rename("LOGLEVEL_DEBUG") LTTNG_LOGLEVEL_DEBUG;
107 enum lttng_loglevel {
108 LTTNG_LOGLEVEL_EMERG = 0,
109 LTTNG_LOGLEVEL_ALERT = 1,
110 LTTNG_LOGLEVEL_CRIT = 2,
111 LTTNG_LOGLEVEL_ERR = 3,
112 LTTNG_LOGLEVEL_WARNING = 4,
113 LTTNG_LOGLEVEL_NOTICE = 5,
114 LTTNG_LOGLEVEL_INFO = 6,
115 LTTNG_LOGLEVEL_DEBUG_SYSTEM = 7,
116 LTTNG_LOGLEVEL_DEBUG_PROGRAM = 8,
117 LTTNG_LOGLEVEL_DEBUG_PROCESS = 9,
118 LTTNG_LOGLEVEL_DEBUG_MODULE = 10,
119 LTTNG_LOGLEVEL_DEBUG_UNIT = 11,
120 LTTNG_LOGLEVEL_DEBUG_FUNCTION = 12,
121 LTTNG_LOGLEVEL_DEBUG_LINE = 13,
122 LTTNG_LOGLEVEL_DEBUG = 14,
125 %rename("EVENT_SPLICE") LTTNG_EVENT_SPLICE;
126 %rename("EVENT_MMAP") LTTNG_EVENT_MMAP;
127 enum lttng_event_output {
128 LTTNG_EVENT_SPLICE = 0,
129 LTTNG_EVENT_MMAP = 1,
132 %rename("EVENT_CONTEXT_PID") LTTNG_EVENT_CONTEXT_PID;
133 %rename("EVENT_CONTEXT_PERF_COUNTER") LTTNG_EVENT_CONTEXT_PERF_COUNTER;
134 %rename("EVENT_CONTEXT_PROCNAME") LTTNG_EVENT_CONTEXT_PROCNAME;
135 %rename("EVENT_CONTEXT_PRIO") LTTNG_EVENT_CONTEXT_PRIO;
136 %rename("EVENT_CONTEXT_NICE") LTTNG_EVENT_CONTEXT_NICE;
137 %rename("EVENT_CONTEXT_VPID") LTTNG_EVENT_CONTEXT_VPID;
138 %rename("EVENT_CONTEXT_TID") LTTNG_EVENT_CONTEXT_TID;
139 %rename("EVENT_CONTEXT_VTID") LTTNG_EVENT_CONTEXT_VTID;
140 %rename("EVENT_CONTEXT_PPID") LTTNG_EVENT_CONTEXT_PPID;
141 %rename("EVENT_CONTEXT_VPPID") LTTNG_EVENT_CONTEXT_VPPID;
142 %rename("EVENT_CONTEXT_PTHREAD_ID") LTTNG_EVENT_CONTEXT_PTHREAD_ID;
143 %rename("EVENT_CONTEXT_HOSTNAME") LTTNG_EVENT_CONTEXT_HOSTNAME;
144 %rename("EVENT_CONTEXT_IP") LTTNG_EVENT_CONTEXT_IP;
145 %rename("EVENT_CONTEXT_PERF_CPU_COUNTER") LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER;
146 %rename("EVENT_CONTEXT_PERF_THREAD_COUNTER") LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER;
147 %rename("EVENT_CONTEXT_APP_CONTEXT") LTTNG_EVENT_CONTEXT_APP_CONTEXT;
148 %rename("EVENT_CONTEXT_INTERRUPTIBLE") LTTNG_EVENT_CONTEXT_INTERRUPTIBLE;
149 %rename("EVENT_CONTEXT_PREEMPTIBLE") LTTNG_EVENT_CONTEXT_PREEMPTIBLE;
150 %rename("EVENT_CONTEXT_NEED_RESCHEDULE") LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE;
151 %rename("EVENT_CONTEXT_MIGRATABLE") LTTNG_EVENT_CONTEXT_MIGRATABLE;
152 enum lttng_event_context_type {
153 LTTNG_EVENT_CONTEXT_PID = 0,
154 LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1,
155 LTTNG_EVENT_CONTEXT_PROCNAME = 2,
156 LTTNG_EVENT_CONTEXT_PRIO = 3,
157 LTTNG_EVENT_CONTEXT_NICE = 4,
158 LTTNG_EVENT_CONTEXT_VPID = 5,
159 LTTNG_EVENT_CONTEXT_TID = 6,
160 LTTNG_EVENT_CONTEXT_VTID = 7,
161 LTTNG_EVENT_CONTEXT_PPID = 8,
162 LTTNG_EVENT_CONTEXT_VPPID = 9,
163 LTTNG_EVENT_CONTEXT_PTHREAD_ID = 10,
164 LTTNG_EVENT_CONTEXT_HOSTNAME = 11,
165 LTTNG_EVENT_CONTEXT_IP = 12,
166 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER = 13,
167 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER = 14,
168 LTTNG_EVENT_CONTEXT_APP_CONTEXT = 15,
169 LTTNG_EVENT_CONTEXT_INTERRUPTIBLE = 16,
170 LTTNG_EVENT_CONTEXT_PREEMPTIBLE = 17,
171 LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE = 18,
172 LTTNG_EVENT_CONTEXT_MIGRATABLE = 19,
178 // =============================================
180 // =============================================
183 %typemap(argout) struct lttng_session **sessions{
185 int l = PyInt_AsSsize_t($result);
188 PyObject *sessions = PyList_New(0);
192 PyObject *tmp = PyTuple_New(4);
193 PyObject *name = PyString_FromString((*$1)[i].name);
194 PyObject *path = PyString_FromString((*$1)[i].path);
195 PyObject *enabled = PyInt_FromSize_t((*$1)[i].enabled);
197 PyTuple_SetItem(tmp, 0, name);
198 PyTuple_SetItem(tmp, 1, path);
199 PyTuple_SetItem(tmp, 2, enabled);
200 PyList_Append(sessions, tmp);
205 %typemap(in,numinputs=0) struct lttng_session **sessions (struct lttng_session *temp){
210 %typemap(argout) struct lttng_domain **domains{
212 int l = PyInt_AsSsize_t($result);
215 PyObject *dom = PyList_New(0);
219 PyObject *tmp = PyTuple_New(6);
220 PyObject *type = PyInt_FromSize_t((*$1)[i].type);
221 PyObject *buf_type = PyInt_FromSize_t((*$1)[i].buf_type);
222 PyObject *execname = PyString_FromString((*$1)[i].attr.exec_name);
223 PyObject *pid = PyInt_FromSize_t((*$1)[i].attr.pid);
224 PyObject *padding = PyString_FromString((*$1)[i].padding);
225 PyObject *attrpadding = PyString_FromString((*$1)[i].attr.padding);
227 PyTuple_SetItem(tmp, 0, type);
228 PyTuple_SetItem(tmp, 1, buf_type);
229 PyTuple_SetItem(tmp, 2, padding);
230 PyTuple_SetItem(tmp, 3, pid);
231 PyTuple_SetItem(tmp, 4, execname);
232 PyTuple_SetItem(tmp, 5, attrpadding);
233 PyList_Append(dom, tmp);
238 %typemap(in,numinputs=0) struct lttng_domain **domains (struct lttng_domain *temp){
243 %typemap(argout) struct lttng_channel **channels{
245 int l = PyInt_AsSsize_t($result);
248 PyObject *chan = PyList_New(0);
252 PyObject *tmp = PyTuple_New(4);
253 PyObject *name = PyString_FromString((*$1)[i].name);
254 PyObject *enabled = PyInt_FromSize_t((*$1)[i].enabled);
255 PyObject *padding = PyString_FromString((*$1)[i].padding);
257 PyObject *attrtmp = PyTuple_New(7);
258 PyObject *overwrite = PyInt_FromLong((*$1)[i].attr.overwrite);
259 PyObject *subbuf = PyInt_FromSize_t((*$1)[i].attr.subbuf_size);
260 PyObject *num = PyInt_FromSize_t((*$1)[i].attr.num_subbuf);
261 PyObject *switchtimer = PyInt_FromSize_t((*$1)[i].attr.switch_timer_interval);
262 PyObject *readtimer = PyInt_FromSize_t((*$1)[i].attr.read_timer_interval);
263 PyObject *output = PyInt_FromSize_t((*$1)[i].attr.output);
264 PyObject *attrpad = PyString_FromString((*$1)[i].attr.padding);
266 PyTuple_SetItem(attrtmp, 0, overwrite);
267 PyTuple_SetItem(attrtmp, 1, subbuf);
268 PyTuple_SetItem(attrtmp, 2, num);
269 PyTuple_SetItem(attrtmp, 3, switchtimer);
270 PyTuple_SetItem(attrtmp, 4, readtimer);
271 PyTuple_SetItem(attrtmp, 5, output);
272 PyTuple_SetItem(attrtmp, 6, attrpad);
274 PyTuple_SetItem(tmp, 0, name);
275 PyTuple_SetItem(tmp, 1, enabled);
276 PyTuple_SetItem(tmp, 2, padding);
277 PyTuple_SetItem(tmp, 3, attrtmp);
278 PyList_Append(chan, tmp);
283 %typemap(in,numinputs=0) struct lttng_channel **channels (struct lttng_channel *temp){
287 //list_events & list_tracepoints
288 %typemap(argout) struct lttng_event **events{
290 int l = PyInt_AsSsize_t($result);
293 PyObject *events = PyList_New(0);
297 PyObject *tmp = PyTuple_New(10);
298 PyObject *name = PyString_FromString((*$1)[i].name);
299 PyObject *type = PyInt_FromSize_t((*$1)[i].type);
300 PyObject *logleveltype = PyInt_FromSize_t((*$1)[i].loglevel_type);
301 PyObject *loglevel = PyInt_FromLong((*$1)[i].loglevel);
302 PyObject *enabled = PyInt_FromLong((*$1)[i].enabled);
303 PyObject *pid = PyInt_FromSize_t((*$1)[i].pid);
304 PyObject *padding = PyString_FromString((*$1)[i].padding);
305 PyObject *attrpadding = PyString_FromString((*$1)[i].attr.padding);
307 PyObject *probe = PyTuple_New(4);
308 PyObject *addr = PyInt_FromSize_t((*$1)[i].attr.probe.addr);
309 PyObject *offset = PyInt_FromSize_t((*$1)[i].attr.probe.offset);
310 PyObject *symbolname = PyString_FromString((*$1)[i].attr.probe.symbol_name);
311 PyObject *probepad = PyString_FromString((*$1)[i].attr.probe.padding);
313 PyObject *function = PyTuple_New(2);
314 PyObject *f_symbolname = PyString_FromString((*$1)[i].attr.ftrace.symbol_name);
315 PyObject *f_pad = PyString_FromString((*$1)[i].attr.ftrace.padding);
317 PyTuple_SetItem(function, 0, f_symbolname);
318 PyTuple_SetItem(function, 1, f_pad);
320 PyTuple_SetItem(probe, 0, addr);
321 PyTuple_SetItem(probe, 1, offset);
322 PyTuple_SetItem(probe, 2, symbolname);
323 PyTuple_SetItem(probe, 3, probepad);
325 PyTuple_SetItem(tmp, 0, name);
326 PyTuple_SetItem(tmp, 1, type);
327 PyTuple_SetItem(tmp, 2, logleveltype);
328 PyTuple_SetItem(tmp, 3, loglevel);
329 PyTuple_SetItem(tmp, 4, enabled);
330 PyTuple_SetItem(tmp, 5, pid);
331 PyTuple_SetItem(tmp, 6, padding);
332 PyTuple_SetItem(tmp, 7, probe);
333 PyTuple_SetItem(tmp, 8, function);
334 PyTuple_SetItem(tmp, 9, attrpadding);
335 PyList_Append(events, tmp);
340 %typemap(in,numinputs=0) struct lttng_event **events (struct lttng_event *temp){
346 // =============================================
348 // =============================================
350 %rename("create") lttng_create_session(const char *name, const char *path);
351 %rename("create_snapshot") lttng_create_session_snapshot(const char *name, const char *snapshot_url);
352 %rename("destroy") lttng_destroy_session(const char *name);
353 %rename("_lttng_create_handle") lttng_create_handle(const char *session_name, struct lttng_domain *domain);
354 %rename("_lttng_destroy_handle") lttng_destroy_handle(struct lttng_handle *handle);
355 %rename("_lttng_list_sessions") lttng_list_sessions(struct lttng_session **sessions);
356 %rename("_lttng_list_domains") lttng_list_domains(const char *session_name, struct lttng_domain **domains);
357 %rename("_lttng_list_channels") lttng_list_channels(struct lttng_handle *handle,struct lttng_channel **channels);
358 %rename("_lttng_list_events") lttng_list_events(struct lttng_handle *handle, const char *channel_name, struct lttng_event **events);
359 %rename("_lttng_list_tracepoints") lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events);
360 %rename("session_daemon_alive") lttng_session_daemon_alive(void);
361 %rename("set_tracing_group") lttng_set_tracing_group(const char *name);
362 %rename("strerror") lttng_strerror(int code);
363 %rename("_lttng_register_consumer") lttng_register_consumer(struct lttng_handle *handle, const char *socket_path);
364 %rename("start") lttng_start_tracing(const char *session_name);
365 %rename("stop") lttng_stop_tracing(const char *session_name);
366 %rename("_lttng_add_context") lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx, const char *event_name, const char *channel_name);
367 %rename("_lttng_enable_event") lttng_enable_event(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name);
368 %rename("_lttng_enable_channel") lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan);
369 %rename("_lttng_disable_event") lttng_disable_event(struct lttng_handle *handle, const char *name, const char *channel_name);
370 %rename("_lttng_disable_channel") lttng_disable_channel(struct lttng_handle *handle, const char *name);
371 %rename("channel_set_default_attr") lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr);
373 //Redefined functions
374 struct lttng_handle *lttng_create_handle(const char *session_name,
375 struct lttng_domain *domain);
376 void lttng_destroy_handle(struct lttng_handle *handle);
377 int lttng_list_channels(struct lttng_handle *handle,struct lttng_channel **channels);
378 int lttng_list_events(struct lttng_handle *handle,
379 const char *channel_name, struct lttng_event **events);
380 int lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events);
381 int lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx,
382 const char *event_name, const char *channel_name);
383 int lttng_enable_event(struct lttng_handle *handle,
384 struct lttng_event *ev, const char *channel_name);
385 int lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan);
386 int lttng_disable_event(struct lttng_handle *handle,
387 const char *name, const char *channel_name);
388 int lttng_disable_channel(struct lttng_handle *handle, const char *name);
389 int lttng_register_consumer(struct lttng_handle *handle, const char *socket_path);
390 int lttng_list_sessions(struct lttng_session **sessions);
391 int lttng_list_domains(const char *session_name, struct lttng_domain **domains);
393 //Functions not needing redefinition
394 %feature("docstring")"create(str name, str path) -> int
396 Create a new tracing session using name and path.
397 Returns 0 on success or a negative error code."
398 int lttng_create_session(const char *name, const char *path);
400 %feature("docstring")"create_snapshot(str name, str snapshot_url) -> int
402 Create a new tracing session using name and snapshot_url in snapshot
403 mode (flight recorder).
404 Returns 0 on success or a negative error code."
405 int lttng_create_session_snapshot(const char *name, const char *path);
407 %feature("docstring")"destroy(str name) -> int
409 Tear down tracing session using name.
410 Returns 0 on success or a negative error code."
411 int lttng_destroy_session(const char *name);
414 %feature("docstring")"session_daemon_alive() -> int
416 Check if session daemon is alive.
417 Return 1 if alive or 0 if not.
418 On error returns a negative value."
419 int lttng_session_daemon_alive(void);
422 %feature("docstring")"set_tracing_group(str name) -> int
424 Sets the tracing_group variable with name.
425 This function allocates memory pointed to by tracing_group.
426 On success, returns 0, on error, returns -1 (null name) or -ENOMEM."
427 int lttng_set_tracing_group(const char *name);
430 %feature("docstring")"strerror(int code) -> char
432 Returns a human readable string describing
433 the error code (a negative value)."
434 const char *lttng_strerror(int code);
437 %feature("docstring")"start(str session_name) -> int
439 Start tracing for all traces of the session.
440 Returns size of returned session payload data or a negative error code."
441 int lttng_start_tracing(const char *session_name);
444 %feature("docstring")"stop(str session_name) -> int
446 Stop tracing for all traces of the session.
447 Returns size of returned session payload data or a negative error code."
448 int lttng_stop_tracing(const char *session_name);
451 %feature("docstring")"channel_set_default_attr(Domain domain, ChannelAttr attr)
453 Set default channel attributes.
454 If either or both of the arguments are null, attr content is zeroe'd."
455 void lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr);
458 // =============================================
459 // Python redefinition of some functions
460 // (List and Handle-related)
461 // =============================================
463 %feature("docstring")""
468 list_sessions() -> dict
470 Ask the session daemon for all available sessions.
471 Returns a dict of Session instances, the key is the name;
472 on error, returns a negative value.
475 ses_list = _lttng_list_sessions()
476 if type(ses_list) is int:
481 for ses_elements in ses_list:
483 ses.name = ses_elements[0]
484 ses.path = ses_elements[1]
485 ses.enabled = ses_elements[2]
486 ses.padding = ses_elements[3]
488 sessions[ses.name] = ses
493 def list_domains(session_name):
495 list_domains(str session_name) -> list
497 Ask the session daemon for all available domains of a session.
498 Returns a list of Domain instances;
499 on error, returns a negative value.
502 dom_list = _lttng_list_domains(session_name)
503 if type(dom_list) is int:
508 for dom_elements in dom_list:
510 dom.type = dom_elements[0]
511 dom.buf_type = dom_elements[1]
512 dom.paddinf = dom_elements[2]
513 dom.attr.pid = dom_elements[3]
514 dom.attr.exec_name = dom_elements[4]
515 dom.attr.padding = dom_elements[5]
522 def list_channels(handle):
524 list_channels(Handle handle) -> dict
526 Ask the session daemon for all available channels of a session.
527 Returns a dict of Channel instances, the key is the name;
528 on error, returns a negative value.
532 chan_list = _lttng_list_channels(handle._h)
533 except AttributeError:
534 raise TypeError("in method 'list_channels', argument 1 must be a Handle instance")
536 if type(chan_list) is int:
541 for channel_elements in chan_list:
543 chan.name = channel_elements[0]
544 chan.enabled = channel_elements[1]
545 chan.padding = channel_elements[2]
546 chan.attr.overwrite = channel_elements[3][0]
547 chan.attr.subbuf_size = channel_elements[3][1]
548 chan.attr.num_subbuf = channel_elements[3][2]
549 chan.attr.switch_timer_interval = channel_elements[3][3]
550 chan.attr.read_timer_interval = channel_elements[3][4]
551 chan.attr.output = channel_elements[3][5]
552 chan.attr.padding = channel_elements[3][6]
554 channels[chan.name] = chan
559 def list_events(handle, channel_name):
561 list_events(Handle handle, str channel_name) -> dict
563 Ask the session daemon for all available events of a session channel.
564 Returns a dict of Event instances, the key is the name;
565 on error, returns a negative value.
569 ev_list = _lttng_list_events(handle._h, channel_name)
570 except AttributeError:
571 raise TypeError("in method 'list_events', argument 1 must be a Handle instance")
573 if type(ev_list) is int:
578 for ev_elements in ev_list:
580 ev.name = ev_elements[0]
581 ev.type = ev_elements[1]
582 ev.loglevel_type = ev_elements[2]
583 ev.loglevel = ev_elements[3]
584 ev.enabled = ev_elements[4]
585 ev.pid = ev_elements[5]
586 ev.attr.padding = ev_elements[6]
587 ev.attr.probe.addr = ev_elements[7][0]
588 ev.attr.probe.offset = ev_elements[7][1]
589 ev.attr.probe.symbol_name = ev_elements[7][2]
590 ev.attr.probe.padding = ev_elements[7][3]
591 ev.attr.ftrace.symbol_name = ev_elements[8][0]
592 ev.attr.ftrace.padding = ev_elements[8][1]
593 ev.attr.padding = ev_elements[9]
600 def list_tracepoints(handle):
602 list_tracepoints(Handle handle) -> dict
604 Returns a dict of Event instances, the key is the name;
605 on error, returns a negative value.
609 ev_list = _lttng_list_tracepoints(handle._h)
610 except AttributeError:
611 raise TypeError("in method 'list_tracepoints', argument 1 must be a Handle instance")
613 if type(ev_list) is int:
618 for ev_elements in ev_list:
620 ev.name = ev_elements[0]
621 ev.type = ev_elements[1]
622 ev.loglevel_type = ev_elements[2]
623 ev.loglevel = ev_elements[3]
624 ev.enabled = ev_elements[4]
625 ev.pid = ev_elements[5]
626 ev.attr.padding = ev_elements[6]
627 ev.attr.probe.addr = ev_elements[7][0]
628 ev.attr.probe.offset = ev_elements[7][1]
629 ev.attr.probe.symbol_name = ev_elements[7][2]
630 ev.attr.probe.padding = ev_elements[7][3]
631 ev.attr.ftrace.symbol_name = ev_elements[8][0]
632 ev.attr.ftrace.padding = ev_elements[8][1]
633 ev.attr.padding = ev_elements[9]
640 def register_consumer(handle, socket_path):
642 register_consumer(Handle handle, str socket_path) -> int
644 Register an outside consumer.
645 Returns size of returned session payload data or a negative error code.
649 return _lttng_register_consumer(handle._h, socket_path)
650 except AttributeError:
651 raise TypeError("in method 'register_consumer', argument 1 must be a Handle instance")
654 def add_context(handle, event_context, event_name, channel_name):
656 add_context(Handle handle, EventContext ctx,
657 str event_name, str channel_name) -> int
659 Add context to event and/or channel.
660 If event_name is None, the context is applied to all events of the channel.
661 If channel_name is None, a lookup of the event's channel is done.
662 If both are None, the context is applied to all events of all channels.
663 Returns the size of the returned payload data or a negative error code.
667 return _lttng_add_context(handle._h, event_context, event_name, channel_name)
668 except AttributeError:
669 raise TypeError("in method 'add_context', argument 1 must be a Handle instance")
672 def enable_event(handle, event, channel_name):
674 enable_event(Handle handle, Event event,
675 str channel_name) -> int
677 Enable event(s) for a channel.
678 If no event name is specified, all events are enabled.
679 If no channel name is specified, the default 'channel0' is used.
680 Returns size of returned session payload data or a negative error code.
684 return _lttng_enable_event(handle._h, event, channel_name)
685 except AttributeError:
686 raise TypeError("in method 'enable_event', argument 1 must be a Handle instance")
689 def enable_channel(handle, channel):
691 enable_channel(Handle handle, Channel channel -> int
693 Enable channel per domain
694 Returns size of returned session payload data or a negative error code.
698 return _lttng_enable_channel(handle._h, channel)
699 except AttributeError:
700 raise TypeError("in method 'enable_channel', argument 1 must be a Handle instance")
703 def disable_event(handle, name, channel_name):
705 disable_event(Handle handle, str name, str channel_name) -> int
707 Disable event(s) of a channel and domain.
708 If no event name is specified, all events are disabled.
709 If no channel name is specified, the default 'channel0' is used.
710 Returns size of returned session payload data or a negative error code
714 return _lttng_disable_event(handle._h, name, channel_name)
715 except AttributeError:
716 raise TypeError("in method 'disable_event', argument 1 must be a Handle instance")
719 def disable_channel(handle, name):
721 disable_channel(Handle handle, str name) -> int
723 All tracing will be stopped for registered events of the channel.
724 Returns size of returned session payload data or a negative error code.
728 return _lttng_disable_channel(handle._h, name)
729 except AttributeError:
730 raise TypeError("in method 'disable_channel', argument 1 must be a Handle instance")
734 // =============================================
736 // Used to prevent freeing unallocated memory
737 // =============================================
739 %feature("docstring")""
740 %feature("autodoc", "1");
746 Takes two arguments: (str session_name, Domain domain)
751 def __init__(self, session_name, domain):
752 if type(session_name) is not str:
753 raise TypeError("in method '__init__', argument 2 of type 'str'")
754 if type(domain) is not Domain and domain is not None:
755 raise TypeError("in method '__init__', argument 3 of type 'lttng.Domain'")
757 self._sname = session_name
761 self._domtype = domain.type
762 self._h = _lttng_create_handle(session_name, domain)
766 _lttng_destroy_handle(self._h)
769 if self._domtype == 1:
770 domstr = "DOMAIN_KERNEL"
771 elif self._domtype == 2:
772 domstr = "DOMAIN_UST"
774 domstr = self._domtype
776 return "lttng.Handle; session('{}'), domain.type({})".format(
779 def __setattr__(self, attr, val):
781 raise NotImplementedError("cannot modify attributes")
783 self.__dict__[attr] = val
787 // =============================================
789 // These are directly taken from lttng.h.
790 // Any change to these structures must also be
792 // =============================================
794 %rename("Domain") lttng_domain;
795 %rename("EventContext") lttng_event_context;
796 %rename("Event") lttng_event;
797 %rename("ChannelAttr") lttng_channel_attr;
798 %rename("Channel") lttng_channel;
799 %rename("Session") lttng_session;
802 enum lttng_domain_type type;
803 enum lttng_buffer_type buf_type;
804 char padding[LTTNG_DOMAIN_PADDING1];
808 char exec_name[NAME_MAX];
809 char padding[LTTNG_DOMAIN_PADDING2];
814 static char temp[256];
815 static char domain_type[25];
816 static char buffer_type[25];
817 switch ( $self->type ) {
819 sprintf(domain_type, "type(DOMAIN_KERNEL)");
822 sprintf(domain_type, "type(DOMAIN_UST)");
825 sprintf(domain_type, "type(%i)", $self->type);
829 switch ( $self->buf_type ) {
830 case LTTNG_BUFFER_PER_UID:
831 sprintf(buffer_type, "buf_type(BUFFER_PER_UID)");
833 case LTTNG_BUFFER_PER_PID:
834 sprintf(buffer_type, "buf_type(BUFFER_PER_PID)");
836 case LTTNG_BUFFER_GLOBAL:
837 sprintf(buffer_type, "buf_type(BUFFER_GLOBAL)");
840 sprintf(buffer_type, "buf_type(%i)", $self->buf_type);
844 sprintf(temp, "lttng.Domain; %s, %s",
853 struct lttng_event_context {
854 enum lttng_event_context_type ctx;
855 char padding[LTTNG_EVENT_CONTEXT_PADDING1];
858 struct lttng_event_perf_counter_ctx perf_counter;
859 char padding[LTTNG_EVENT_CONTEXT_PADDING2];
864 static char temp[256];
865 switch ( $self->ctx ) {
867 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PID)");
870 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PERF_COUNTER)");
873 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PROCNAME)");
876 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PRIO)");
879 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_NICE)");
882 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VPID)");
885 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_TID)");
888 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VTID)");
891 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PPID)");
894 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VPPID)");
897 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PTHREAD_ID)");
900 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_HOSTNAME)");
903 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_IP)");
906 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PERF_CPU_COUNTER)");
909 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PERF_THREAD_COUNTER)");
912 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_APP_CONTEXT)");
915 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_INTERRUPTIBLE)");
918 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PREEMPTIBLE)");
921 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_NEED_RESCHEDULE)");
924 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_MIGRATABLE)");
927 sprintf(temp, "lttng.EventContext; type(%i)", $self->ctx);
935 struct lttng_event_probe_attr {
938 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
939 char padding[LTTNG_EVENT_PROBE_PADDING1];
942 struct lttng_event_function_attr {
943 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
944 char padding[LTTNG_EVENT_FUNCTION_PADDING1];
948 enum lttng_event_type type;
949 char name[LTTNG_SYMBOL_NAME_LEN];
951 enum lttng_loglevel_type loglevel_type;
957 char padding[LTTNG_EVENT_PADDING1];
960 struct lttng_event_probe_attr probe;
961 struct lttng_event_function_attr ftrace;
963 char padding[LTTNG_EVENT_PADDING2];
968 static char temp[512];
972 switch ( $self->type ) {
974 sprintf(evtype, "EVENT_ALL");
977 sprintf(evtype, "EVENT_TRACEPOINT");
980 sprintf(evtype, "EVENT_PROBE");
983 sprintf(evtype, "EVENT_FUNCTION");
986 sprintf(evtype, "EVENT_FUNCTION_ENTRY");
989 sprintf(evtype, "EVENT_NOOP");
992 sprintf(evtype, "EVENT_SYSCALL");
995 sprintf(evtype, "%i", $self->type);
999 switch ( $self->loglevel_type ) {
1001 sprintf(logtype, "EVENT_LOGLEVEL_ALL");
1004 sprintf(logtype, "EVENT_LOGLEVEL_RANGE");
1007 sprintf(logtype, "EVENT_LOGLEVEL_SINGLE");
1010 sprintf(logtype, "%i", $self->loglevel_type);
1014 sprintf(temp, "lttng.Event; name('%s'), type(%s), "
1015 "loglevel_type(%s), loglevel(%i), "
1016 "enabled(%s), pid(%i)",
1017 $self->name, evtype, logtype, $self->loglevel,
1018 $self->enabled ? "True" : "False", $self->pid);
1024 struct lttng_channel_attr {
1026 uint64_t subbuf_size;
1027 uint64_t num_subbuf;
1028 unsigned int switch_timer_interval;
1029 unsigned int read_timer_interval;
1030 enum lttng_event_output output;
1032 char padding[LTTNG_CHANNEL_ATTR_PADDING1];
1036 static char temp[256];
1039 switch ( $self->output ) {
1041 sprintf(evout, "EVENT_SPLICE");
1044 sprintf(evout, "EVENT_MMAP");
1047 sprintf(evout, "%i", $self->output);
1050 sprintf(temp, "lttng.ChannelAttr; overwrite(%i), subbuf_size(%"PRIu64"), "
1051 "num_subbuf(%"PRIu64"), switch_timer_interval(%u), "
1052 "read_timer_interval(%u), output(%s)",
1053 $self->overwrite, $self->subbuf_size, $self->num_subbuf,
1054 $self->switch_timer_interval, $self->read_timer_interval,
1061 struct lttng_channel {
1062 char name[LTTNG_SYMBOL_NAME_LEN];
1064 struct lttng_channel_attr attr;
1065 char padding[LTTNG_CHANNEL_PADDING1];
1069 static char temp[512];
1070 snprintf(temp, sizeof(temp), "lttng.Channel; name('%s'), enabled(%s)",
1071 $self->name, $self->enabled ? "True" : "False");
1077 struct lttng_session {
1078 char name[NAME_MAX];
1079 char path[PATH_MAX];
1081 uint32_t snapshot_mode;
1082 unsigned int live_timer_interval;
1084 char padding[LTTNG_SESSION_PADDING1];
1090 static char temp[PATH_MAX + NAME_MAX + 512];
1091 snprintf(temp, sizeof(temp), "lttng.Session; name('%s'), path('%s'), enabled(%s)",
1092 $self->name, $self->path,
1093 $self->enabled ? "True" : "False");