Tests: Add runner script for tests
[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);
317%rename("destroy") lttng_destroy_session(const char *name);
318%rename("_lttng_create_handle") lttng_create_handle(const char *session_name, struct lttng_domain *domain);
319%rename("_lttng_destroy_handle") lttng_destroy_handle(struct lttng_handle *handle);
320%rename("_lttng_list_sessions") lttng_list_sessions(struct lttng_session **sessions);
321%rename("_lttng_list_domains") lttng_list_domains(const char *session_name, struct lttng_domain **domains);
322%rename("_lttng_list_channels") lttng_list_channels(struct lttng_handle *handle,struct lttng_channel **channels);
323%rename("_lttng_list_events") lttng_list_events(struct lttng_handle *handle, const char *channel_name, struct lttng_event **events);
324%rename("_lttng_list_tracepoints") lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events);
325%rename("session_daemon_alive") lttng_session_daemon_alive(void);
326%rename("set_tracing_group") lttng_set_tracing_group(const char *name);
327%rename("strerror") lttng_strerror(int code);
328%rename("_lttng_register_consumer") lttng_register_consumer(struct lttng_handle *handle, const char *socket_path);
329%rename("start") lttng_start_tracing(const char *session_name);
330%rename("stop") lttng_stop_tracing(const char *session_name);
331%rename("_lttng_add_context") lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx, const char *event_name, const char *channel_name);
332%rename("_lttng_enable_event") lttng_enable_event(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name);
333%rename("_lttng_enable_channel") lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan);
334%rename("_lttng_disable_event") lttng_disable_event(struct lttng_handle *handle, const char *name, const char *channel_name);
335%rename("_lttng_disable_channel") lttng_disable_channel(struct lttng_handle *handle, const char *name);
336%rename("_lttng_calibrate") lttng_calibrate(struct lttng_handle *handle, struct lttng_calibrate *calibrate);
337%rename("channel_set_default_attr") lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr);
338
339//Redefined functions
340struct lttng_handle *lttng_create_handle(const char *session_name,
341 struct lttng_domain *domain);
342void lttng_destroy_handle(struct lttng_handle *handle);
343int lttng_list_channels(struct lttng_handle *handle,struct lttng_channel **channels);
344int lttng_list_events(struct lttng_handle *handle,
345 const char *channel_name, struct lttng_event **events);
346int lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events);
347int lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx,
348 const char *event_name, const char *channel_name);
349int lttng_enable_event(struct lttng_handle *handle,
350 struct lttng_event *ev, const char *channel_name);
351int lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan);
352int lttng_disable_event(struct lttng_handle *handle,
353 const char *name, const char *channel_name);
354int lttng_disable_channel(struct lttng_handle *handle, const char *name);
355int lttng_calibrate(struct lttng_handle *handle, struct lttng_calibrate *calibrate);
356int lttng_register_consumer(struct lttng_handle *handle, const char *socket_path);
357int lttng_list_sessions(struct lttng_session **sessions);
358int lttng_list_domains(const char *session_name, struct lttng_domain **domains);
359
360//Functions not needing redefinition
361%feature("docstring")"create(str name, str path) -> int
362
363Create a new tracing session using name and path.
364Returns size of returned session payload data or a negative error code."
365int lttng_create_session(const char *name, const char *path);
366
367
368%feature("docstring")"destroy(str name) -> int
369
370Tear down tracing session using name.
371Returns size of returned session payload data or a negative error code."
372int lttng_destroy_session(const char *name);
373
374
375%feature("docstring")"session_daemon_alive() -> int
376
377Check if session daemon is alive.
378Return 1 if alive or 0 if not.
379On error returns a negative value."
380int lttng_session_daemon_alive(void);
381
382
383%feature("docstring")"set_tracing_group(str name) -> int
384
385Sets the tracing_group variable with name.
386This function allocates memory pointed to by tracing_group.
387On success, returns 0, on error, returns -1 (null name) or -ENOMEM."
388int lttng_set_tracing_group(const char *name);
389
390
391%feature("docstring")"strerror(int code) -> char
392
393Returns a human readable string describing
394the error code (a negative value)."
395const char *lttng_strerror(int code);
396
397
398%feature("docstring")"start(str session_name) -> int
399
400Start tracing for all traces of the session.
401Returns size of returned session payload data or a negative error code."
402int lttng_start_tracing(const char *session_name);
403
404
405%feature("docstring")"stop(str session_name) -> int
406
407Stop tracing for all traces of the session.
408Returns size of returned session payload data or a negative error code."
409int lttng_stop_tracing(const char *session_name);
410
411
412%feature("docstring")"channel_set_default_attr(Domain domain, ChannelAttr attr)
413
414Set default channel attributes.
415If either or both of the arguments are null, attr content is zeroe'd."
416void lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr);
417
418
419// =============================================
420// Python redefinition of some functions
421// (List and Handle-related)
422// =============================================
423
424%feature("docstring")""
425%pythoncode %{
426
427def list_sessions():
428 """
429 list_sessions() -> dict
430
431 Ask the session daemon for all available sessions.
432 Returns a dict of Session instances, the key is the name;
433 on error, returns a negative value.
434 """
435
436 ses_list = _lttng_list_sessions()
437 if type(ses_list) is int:
438 return ses_list
439
440 sessions = {}
441
442 for ses_elements in ses_list:
443 ses = Session()
444 ses.name = ses_elements[0]
445 ses.path = ses_elements[1]
446 ses.enabled = ses_elements[2]
447 ses.padding = ses_elements[3]
448
449 sessions[ses.name] = ses
450
451 return sessions
452
453
454def list_domains(session_name):
455 """
456 list_domains(str session_name) -> list
457
458 Ask the session daemon for all available domains of a session.
459 Returns a list of Domain instances;
460 on error, returns a negative value.
461 """
462
463 dom_list = _lttng_list_domains(session_name)
464 if type(dom_list) is int:
465 return dom_list
466
467 domains = []
468
469 for dom_elements in dom_list:
470 dom = Domain()
471 dom.type = dom_elements[0]
472 dom.paddinf = dom_elements[1]
473 dom.attr.pid = dom_elements[2]
474 dom.attr.exec_name = dom_elements[3]
475 dom.attr.padding = dom_elements[4]
476
477 domains.append(dom)
478
479 return domains
480
481
482def list_channels(handle):
483 """
484 list_channels(Handle handle) -> dict
485
486 Ask the session daemon for all available channels of a session.
487 Returns a dict of Channel instances, the key is the name;
488 on error, returns a negative value.
489 """
490
491 try:
492 chan_list = _lttng_list_channels(handle._h)
493 except AttributeError:
494 raise TypeError("in method 'list_channels', argument 1 must be a Handle instance")
495
496 if type(chan_list) is int:
497 return chan_list
498
499 channels = {}
500
501 for channel_elements in chan_list:
502 chan = Channel()
503 chan.name = channel_elements[0]
504 chan.enabled = channel_elements[1]
505 chan.padding = channel_elements[2]
506 chan.attr.overwrite = channel_elements[3][0]
507 chan.attr.subbuf_size = channel_elements[3][1]
508 chan.attr.num_subbuf = channel_elements[3][2]
509 chan.attr.switch_timer_interval = channel_elements[3][3]
510 chan.attr.read_timer_interval = channel_elements[3][4]
511 chan.attr.output = channel_elements[3][5]
512 chan.attr.padding = channel_elements[3][6]
513
514 channels[chan.name] = chan
515
516 return channels
517
518
519def list_events(handle, channel_name):
520 """
521 list_events(Handle handle, str channel_name) -> dict
522
523 Ask the session daemon for all available events of a session channel.
524 Returns a dict of Event instances, the key is the name;
525 on error, returns a negative value.
526 """
527
528 try:
529 ev_list = _lttng_list_events(handle._h, channel_name)
530 except AttributeError:
531 raise TypeError("in method 'list_events', argument 1 must be a Handle instance")
532
533 if type(ev_list) is int:
534 return ev_list
535
536 events = {}
537
538 for ev_elements in ev_list:
539 ev = Event()
540 ev.name = ev_elements[0]
541 ev.type = ev_elements[1]
542 ev.loglevel_type = ev_elements[2]
543 ev.loglevel = ev_elements[3]
544 ev.enabled = ev_elements[4]
545 ev.pid = ev_elements[5]
546 ev.attr.padding = ev_elements[6]
547 ev.attr.probe.addr = ev_elements[7][0]
548 ev.attr.probe.offset = ev_elements[7][1]
549 ev.attr.probe.symbol_name = ev_elements[7][2]
550 ev.attr.probe.padding = ev_elements[7][3]
551 ev.attr.ftrace.symbol_name = ev_elements[8][0]
552 ev.attr.ftrace.padding = ev_elements[8][1]
553 ev.attr.padding = ev_elements[9]
554
555 events[ev.name] = ev
556
557 return events
558
559
560def list_tracepoints(handle):
561 """
562 list_tracepoints(Handle handle) -> dict
563
564 Returns a dict of Event instances, the key is the name;
565 on error, returns a negative value.
566 """
567
568 try:
569 ev_list = _lttng_list_tracepoints(handle._h)
570 except AttributeError:
571 raise TypeError("in method 'list_tracepoints', argument 1 must be a Handle instance")
572
573 if type(ev_list) is int:
574 return ev_list
575
576 events = {}
577
578 for ev_elements in ev_list:
579 ev = Event()
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]
594
595 events[ev.name] = ev
596
597 return events
598
599
600def register_consumer(handle, socket_path):
601 """
602 register_consumer(Handle handle, str socket_path) -> int
603
604 Register an outside consumer.
605 Returns size of returned session payload data or a negative error code.
606 """
607
608 try:
609 return _lttng_register_consumer(handle._h, socket_path)
610 except AttributeError:
611 raise TypeError("in method 'register_consumer', argument 1 must be a Handle instance")
612
613
614def add_context(handle, event_context, event_name, channel_name):
615 """
616 add_context(Handle handle, EventContext ctx,
617 str event_name, str channel_name) -> int
618
619 Add context to event and/or channel.
620 If event_name is None, the context is applied to all events of the channel.
621 If channel_name is None, a lookup of the event's channel is done.
622 If both are None, the context is applied to all events of all channels.
623 Returns the size of the returned payload data or a negative error code.
624 """
625
626 try:
627 return _lttng_add_context(handle._h, event_context, event_name, channel_name)
628 except AttributeError:
629 raise TypeError("in method 'add_context', argument 1 must be a Handle instance")
630
631
632def enable_event(handle, event, channel_name):
633 """
634 enable_event(Handle handle, Event event,
635 str channel_name) -> int
636
637 Enable event(s) for a channel.
638 If no event name is specified, all events are enabled.
639 If no channel name is specified, the default 'channel0' is used.
640 Returns size of returned session payload data or a negative error code.
641 """
642
643 try:
644 return _lttng_enable_event(handle._h, event, channel_name)
645 except AttributeError:
646 raise TypeError("in method 'enable_event', argument 1 must be a Handle instance")
647
648
649def enable_channel(handle, channel):
650 """
651 enable_channel(Handle handle, Channel channel -> int
652
653 Enable channel per domain
654 Returns size of returned session payload data or a negative error code.
655 """
656
657 try:
658 return _lttng_enable_channel(handle._h, channel)
659 except AttributeError:
660 raise TypeError("in method 'enable_channel', argument 1 must be a Handle instance")
661
662
663def disable_event(handle, name, channel_name):
664 """
665 disable_event(Handle handle, str name, str channel_name) -> int
666
667 Disable event(s) of a channel and domain.
668 If no event name is specified, all events are disabled.
669 If no channel name is specified, the default 'channel0' is used.
670 Returns size of returned session payload data or a negative error code
671 """
672
673 try:
674 return _lttng_disable_event(handle._h, name, channel_name)
675 except AttributeError:
676 raise TypeError("in method 'disable_event', argument 1 must be a Handle instance")
677
678
679def disable_channel(handle, name):
680 """
681 disable_channel(Handle handle, str name) -> int
682
683 All tracing will be stopped for registered events of the channel.
684 Returns size of returned session payload data or a negative error code.
685 """
686
687 try:
688 return _lttng_disable_channel(handle._h, name)
689 except AttributeError:
690 raise TypeError("in method 'disable_channel', argument 1 must be a Handle instance")
691
692
693def calibrate(handle, calibrate):
694 """
695 calibrate(Handle handle, Calibrate calibrate) -> int
696
697 Quantify LTTng overhead.
698 Returns size of returned session payload data or a negative error code.
699 """
700
701 try:
702 return _lttng_calibrate(handle._h, calibrate)
703 except AttributeError:
704 raise TypeError("in method 'calibrate', argument 1 must be a Handle instance")
705%}
706
707
708// =============================================
709// Handle class
710// Used to prevent freeing unallocated memory
711// =============================================
712
713%feature("docstring")""
714%feature("autodoc", "1");
715
716%pythoncode %{
717class Handle:
9c2fd06d 718 """
36907cb5
DS
719 Manages a handle.
720 Takes two arguments: (str session_name, Domain domain)
721 """
722
723 __frozen = False
724
725 def __init__(self, session_name, domain):
726 if type(session_name) is not str:
727 raise TypeError("in method '__init__', argument 2 of type 'str'")
728 if type(domain) is not Domain and domain is not None:
729 raise TypeError("in method '__init__', argument 3 of type 'lttng.Domain'")
730
731 self._sname = session_name
732 if domain is None:
733 self._domtype = None
734 else:
735 self._domtype = domain.type
736 self._h = _lttng_create_handle(session_name, domain)
737 self.__frozen = True
738
739 def __del__(self):
740 _lttng_destroy_handle(self._h)
741
742 def __repr__(self):
743 if self._domtype == 1:
744 domstr = "DOMAIN_KERNEL"
745 elif self._domtype == 2:
746 domstr = "DOMAIN_UST"
747 else:
748 domstr = self._domtype
749
750 return "lttng.Handle; session('{}'), domain.type({})".format(
751 self._sname, domstr)
752
753 def __setattr__(self, attr, val):
754 if self.__frozen:
755 raise NotImplementedError("cannot modify attributes")
756 else:
757 self.__dict__[attr] = val
758%}
759
760
761// =============================================
762// STRUCTURES
763// These are directly taken from lttng.h.
764// Any change to these structures must also be
765// made here.
766// =============================================
767
768%rename("Domain") lttng_domain;
769%rename("EventContext") lttng_event_context;
770%rename("Event") lttng_event;
771%rename("Calibrate") lttng_calibrate;
772%rename("ChannelAttr") lttng_channel_attr;
773%rename("Channel") lttng_channel;
774%rename("Session") lttng_session;
775
776struct lttng_domain{
777 enum lttng_domain_type type;
778 char padding[LTTNG_DOMAIN_PADDING1];
779
780 union {
781 pid_t pid;
782 char exec_name[NAME_MAX];
783 char padding[LTTNG_DOMAIN_PADDING2];
784 } attr;
785
786 %extend {
787 char *__repr__() {
788 static char temp[256];
789 switch ( $self->type ) {
790 case 1:
791 sprintf(temp, "lttng.Domain; type(DOMAIN_KERNEL)");
792 break;
793 case 2:
794 sprintf(temp, "lttng.Domain; type(DOMAIN_UST)");
795 break;
796 default:
797 sprintf(temp, "lttng.Domain; type(%i)", $self->type);
798 break;
799 }
800 return &temp[0];
801 }
802 }
803};
804
805struct lttng_event_context {
806 enum lttng_event_context_type ctx;
807 char padding[LTTNG_EVENT_CONTEXT_PADDING1];
808
809 union {
810 struct lttng_event_perf_counter_ctx perf_counter;
811 char padding[LTTNG_EVENT_CONTEXT_PADDING2];
812 } u;
813
814 %extend {
815 char *__repr__() {
816 static char temp[256];
817 switch ( $self->ctx ) {
818 case 0:
819 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PID)");
820 break;
821 case 1:
822 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PERF_COUNTER)");
823 break;
824 case 2:
825 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PROCNAME)");
826 break;
827 case 3:
828 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PRIO)");
829 break;
830 case 4:
831 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_NICE)");
832 break;
833 case 5:
834 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VPID)");
835 break;
836 case 6:
837 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_TID)");
838 break;
839 case 7:
840 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VTID)");
841 break;
842 case 8:
843 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PPID)");
844 break;
845 case 9:
846 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VPPID)");
847 break;
848 case 10:
849 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PTHREAD_ID)");
850 break;
851 default:
852 sprintf(temp, "lttng.EventContext; type(%i)", $self->ctx);
853 break;
854 }
855 return &temp[0];
856 }
857 }
858};
859
860struct lttng_event_probe_attr {
861 uint64_t addr;
862 uint64_t offset;
863 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
864 char padding[LTTNG_EVENT_PROBE_PADDING1];
865};
866
867struct lttng_event_function_attr {
868 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
869 char padding[LTTNG_EVENT_FUNCTION_PADDING1];
870};
871
872struct lttng_event {
873 enum lttng_event_type type;
874 char name[LTTNG_SYMBOL_NAME_LEN];
875
876 enum lttng_loglevel_type loglevel_type;
877 int loglevel;
878
879 int32_t enabled;
880 pid_t pid;
881
882 char padding[LTTNG_EVENT_PADDING1];
883
884 union {
885 struct lttng_event_probe_attr probe;
886 struct lttng_event_function_attr ftrace;
887
888 char padding[LTTNG_EVENT_PADDING2];
889 } attr;
890
891 %extend {
892 char *__repr__() {
893 static char temp[512];
894 char evtype[50];
895 char logtype[50];
896
897 switch ( $self->type ) {
898 case -1:
899 sprintf(evtype, "EVENT_ALL");
900 break;
901 case 0:
902 sprintf(evtype, "EVENT_TRACEPOINT");
903 break;
904 case 1:
905 sprintf(evtype, "EVENT_PROBE");
906 break;
907 case 2:
908 sprintf(evtype, "EVENT_FUNCTION");
909 break;
910 case 3:
911 sprintf(evtype, "EVENT_FUNCTION_ENTRY");
912 break;
913 case 4:
914 sprintf(evtype, "EVENT_NOOP");
915 break;
916 case 5:
917 sprintf(evtype, "EVENT_SYSCALL");
918 break;
919 default:
920 sprintf(evtype, "%i", $self->type);
921 break;
922 }
923
924 switch ( $self->loglevel_type ) {
925 case 0:
926 sprintf(logtype, "EVENT_LOGLEVEL_ALL");
927 break;
928 case 1:
929 sprintf(logtype, "EVENT_LOGLEVEL_RANGE");
930 break;
931 case 2:
932 sprintf(logtype, "EVENT_LOGLEVEL_SINGLE");
933 break;
934 default:
935 sprintf(logtype, "%i", $self->loglevel_type);
936 break;
937 }
938
939 sprintf(temp, "lttng.Event; name('%s'), type(%s), "
940 "loglevel_type(%s), loglevel(%i), "
941 "enabled(%s), pid(%i)",
942 $self->name, evtype, logtype, $self->loglevel,
943 $self->enabled ? "True" : "False", $self->pid);
944 return &temp[0];
945 }
946 }
947};
948
949struct lttng_calibrate {
950 enum lttng_calibrate_type type;
951 char padding[LTTNG_CALIBRATE_PADDING1];
952
953 %extend {
954 char *__repr__() {
955 static char temp[256];
956 switch ( $self->type ) {
957 case 0:
958 sprintf(temp, "lttng.Calibrate; type(CALIBRATE_FUNCTION)");
959 break;
960 default:
961 sprintf(temp, "lttng.Calibrate; type(%i)", $self->type);
962 break;
963 }
964 return &temp[0];
965 }
966 }
967};
968
969struct lttng_channel_attr {
970 int overwrite;
971 uint64_t subbuf_size;
972 uint64_t num_subbuf;
973 unsigned int switch_timer_interval;
974 unsigned int read_timer_interval;
975 enum lttng_event_output output;
976
977 char padding[LTTNG_CHANNEL_ATTR_PADDING1];
978
979 %extend {
980 char *__repr__() {
981 static char temp[256];
982 char evout[25];
983
984 switch ( $self->output ) {
985 case 0:
986 sprintf(evout, "EVENT_SPLICE");
987 break;
988 case 1:
989 sprintf(evout, "EVENT_MMAP");
990 break;
991 default:
992 sprintf(evout, "%i", $self->output);
993 break;
994 }
995 sprintf(temp, "lttng.ChannelAttr; overwrite(%i), subbuf_size(%lu), "
996 "num_subbuf(%lu), switch_timer_interval(%u), "
997 "read_timer_interval(%u), output(%s)",
998 $self->overwrite, $self->subbuf_size, $self->num_subbuf,
999 $self->switch_timer_interval, $self->read_timer_interval,
1000 evout);
1001 return &temp[0];
1002 }
1003 }
1004};
1005
1006struct lttng_channel {
1007 char name[LTTNG_SYMBOL_NAME_LEN];
1008 uint32_t enabled;
1009 struct lttng_channel_attr attr;
1010 char padding[LTTNG_CHANNEL_PADDING1];
1011
1012 %extend {
1013 char *__repr__() {
1014 static char temp[512];
1015 sprintf(temp, "lttng.Channel; name('%s'), enabled(%s)",
1016 $self->name, $self->enabled ? "True" : "False");
1017 return &temp[0];
1018 }
1019 }
1020};
1021
1022struct lttng_session {
1023 char name[NAME_MAX];
1024 char path[PATH_MAX];
1025 uint32_t enabled;
1026 char padding[LTTNG_SESSION_PADDING1];
1027
1028 %extend {
1029 char *__repr__() {
1030 static char temp[512];
1031 sprintf(temp, "lttng.Session; name('%s'), path('%s'), enabled(%s)",
1032 $self->name, $self->path,
1033 $self->enabled ? "True" : "False");
1034 return &temp[0];
1035 }
1036 }
1037};
This page took 0.060005 seconds and 4 git commands to generate.