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