7418d01d635c24778b55309de35aff4a4716086d
[lttng-tools.git] / extras / bindings / swig / python / lttng.i.in
1 %define DOCSTRING
2 "LTTNG_VERSION_STR
3
4 The LTTng project aims at providing highly efficient tracing tools for Linux.
5 It's tracers help tracking down performance issues and debugging problems involving
6 multiple concurrent processes and threads. Tracing across multiple systems is also possible."
7 %enddef
8
9 %module(docstring=DOCSTRING) lttng
10
11 %include "typemaps.i"
12 %include "stdint.i"
13 %include "pyabc.i"
14 %{
15 #define SWIG_FILE_WITH_INIT
16 #include <lttng/lttng.h>
17 %}
18
19 %{
20 #if PY_MAJOR_VERSION >= 3
21 // The PyInt and PyLong types were unified as of Python 3
22 // This makes the typemap code useable with both Python 2 and 3.
23 #define PyInt_AsSsize_t PyLong_AsSsize_t
24 #endif
25 %}
26
27 typedef unsigned int uint32_t;
28 typedef int int32_t;
29 typedef unsigned long long uint64_t;
30 typedef long pid_t;
31
32
33 // =============================================
34 // ENUMS
35 // These are directly taken from lttng.h.
36 // Any change to these enums must also be
37 // made here.
38 // =============================================
39
40 %rename("DOMAIN_KERNEL") LTTNG_DOMAIN_KERNEL;
41 %rename("DOMAIN_UST") LTTNG_DOMAIN_UST;
42 enum lttng_domain_type {
43 LTTNG_DOMAIN_KERNEL = 1,
44 LTTNG_DOMAIN_UST = 2,
45 };
46
47 %rename("EVENT_ALL") LTTNG_EVENT_ALL;
48 %rename("EVENT_TRACEPOINT") LTTNG_EVENT_TRACEPOINT;
49 %rename("EVENT_PROBE") LTTNG_EVENT_PROBE;
50 %rename("EVENT_FUNCTION")LTTNG_EVENT_FUNCTION;
51 %rename("EVENT_FUNCTION_ENTRY") LTTNG_EVENT_FUNCTION_ENTRY;
52 %rename("EVENT_NOOP") LTTNG_EVENT_NOOP;
53 %rename("EVENT_SYSCALL") LTTNG_EVENT_SYSCALL;
54 enum lttng_event_type {
55 LTTNG_EVENT_ALL = -1,
56 LTTNG_EVENT_TRACEPOINT = 0,
57 LTTNG_EVENT_PROBE = 1,
58 LTTNG_EVENT_FUNCTION = 2,
59 LTTNG_EVENT_FUNCTION_ENTRY = 3,
60 LTTNG_EVENT_NOOP = 4,
61 LTTNG_EVENT_SYSCALL = 5,
62 };
63
64 %rename("EVENT_LOGLEVEL_ALL") LTTNG_EVENT_LOGLEVEL_ALL;
65 %rename("EVENT_LOGLEVEL_RANGE") LTTNG_EVENT_LOGLEVEL_RANGE;
66 %rename("EVENT_LOGLEVEL_SINGLE") LTTNG_EVENT_LOGLEVEL_SINGLE;
67 enum lttng_loglevel_type {
68 LTTNG_EVENT_LOGLEVEL_ALL = 0,
69 LTTNG_EVENT_LOGLEVEL_RANGE = 1,
70 LTTNG_EVENT_LOGLEVEL_SINGLE = 2,
71 };
72
73 %rename("LOGLEVEL_EMERG") LTTNG_LOGLEVEL_EMERG;
74 %rename("LOGLEVEL_ALERT") LTTNG_LOGLEVEL_ALERT;
75 %rename("LOGLEVEL_CRIT") LTTNG_LOGLEVEL_CRIT;
76 %rename("LOGLEVEL_ERR") LTTNG_LOGLEVEL_ERR;
77 %rename("LOGLEVEL_WARNING") LTTNG_LOGLEVEL_WARNING;
78 %rename("LOGLEVEL_NOTICE") LTTNG_LOGLEVEL_NOTICE;
79 %rename("LOGLEVEL_INFO") LTTNG_LOGLEVEL_INFO;
80 %rename("LOGLEVEL_DEBUG_SYSTEM") LTTNG_LOGLEVEL_DEBUG_SYSTEM;
81 %rename("LOGLEVEL_DEBUG_PROGRAM") LTTNG_LOGLEVEL_DEBUG_PROGRAM;
82 %rename("LOGLEVEL_DEBUG_PROCESS") LTTNG_LOGLEVEL_DEBUG_PROCESS;
83 %rename("LOGLEVEL_DEBUG_MODULE") LTTNG_LOGLEVEL_DEBUG_MODULE;
84 %rename("LOGLEVEL_DEBUG_UNIT") LTTNG_LOGLEVEL_DEBUG_UNIT;
85 %rename("LOGLEVEL_DEBUG_FUNCTION") LTTNG_LOGLEVEL_DEBUG_FUNCTION;
86 %rename("LOGLEVEL_DEBUG_LINE") LTTNG_LOGLEVEL_DEBUG_LINE;
87 %rename("LOGLEVEL_DEBUG") LTTNG_LOGLEVEL_DEBUG;
88 enum lttng_loglevel {
89 LTTNG_LOGLEVEL_EMERG = 0,
90 LTTNG_LOGLEVEL_ALERT = 1,
91 LTTNG_LOGLEVEL_CRIT = 2,
92 LTTNG_LOGLEVEL_ERR = 3,
93 LTTNG_LOGLEVEL_WARNING = 4,
94 LTTNG_LOGLEVEL_NOTICE = 5,
95 LTTNG_LOGLEVEL_INFO = 6,
96 LTTNG_LOGLEVEL_DEBUG_SYSTEM = 7,
97 LTTNG_LOGLEVEL_DEBUG_PROGRAM = 8,
98 LTTNG_LOGLEVEL_DEBUG_PROCESS = 9,
99 LTTNG_LOGLEVEL_DEBUG_MODULE = 10,
100 LTTNG_LOGLEVEL_DEBUG_UNIT = 11,
101 LTTNG_LOGLEVEL_DEBUG_FUNCTION = 12,
102 LTTNG_LOGLEVEL_DEBUG_LINE = 13,
103 LTTNG_LOGLEVEL_DEBUG = 14,
104 };
105
106 %rename("EVENT_SPLICE") LTTNG_EVENT_SPLICE;
107 %rename("EVENT_MMAP") LTTNG_EVENT_MMAP;
108 enum lttng_event_output {
109 LTTNG_EVENT_SPLICE = 0,
110 LTTNG_EVENT_MMAP = 1,
111 };
112
113 %rename("EVENT_CONTEXT_PID") LTTNG_EVENT_CONTEXT_PID;
114 %rename("EVENT_CONTEXT_PERF_COUNTER") LTTNG_EVENT_CONTEXT_PERF_COUNTER;
115 %rename("EVENT_CONTEXT_PROCNAME") LTTNG_EVENT_CONTEXT_PROCNAME;
116 %rename("EVENT_CONTEXT_PRIO") LTTNG_EVENT_CONTEXT_PRIO;
117 %rename("EVENT_CONTEXT_NICE") LTTNG_EVENT_CONTEXT_NICE;
118 %rename("EVENT_CONTEXT_VPID") LTTNG_EVENT_CONTEXT_VPID;
119 %rename("EVENT_CONTEXT_TID") LTTNG_EVENT_CONTEXT_TID;
120 %rename("EVENT_CONTEXT_VTID") LTTNG_EVENT_CONTEXT_VTID;
121 %rename("EVENT_CONTEXT_PPID") LTTNG_EVENT_CONTEXT_PPID;
122 %rename("EVENT_CONTEXT_VPPID") LTTNG_EVENT_CONTEXT_VPPID;
123 %rename("EVENT_CONTEXT_PTHREAD_ID") LTTNG_EVENT_CONTEXT_PTHREAD_ID;
124 enum lttng_event_context_type {
125 LTTNG_EVENT_CONTEXT_PID = 0,
126 LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1,
127 LTTNG_EVENT_CONTEXT_PROCNAME = 2,
128 LTTNG_EVENT_CONTEXT_PRIO = 3,
129 LTTNG_EVENT_CONTEXT_NICE = 4,
130 LTTNG_EVENT_CONTEXT_VPID = 5,
131 LTTNG_EVENT_CONTEXT_TID = 6,
132 LTTNG_EVENT_CONTEXT_VTID = 7,
133 LTTNG_EVENT_CONTEXT_PPID = 8,
134 LTTNG_EVENT_CONTEXT_VPPID = 9,
135 LTTNG_EVENT_CONTEXT_PTHREAD_ID = 10,
136 };
137
138
139
140
141 // =============================================
142 // TYPEMAPS
143 // =============================================
144
145 //list_sessions
146 %typemap(argout) struct lttng_session **sessions{
147
148 int l = PyInt_AsSsize_t($result);
149 if (l >= 0)
150 {
151 PyObject *sessions = PyList_New(0);
152 int i;
153 for(i=0; i<l; i++)
154 {
155 PyObject *tmp = PyTuple_New(4);
156 PyObject *name = PyString_FromString((*$1)[i].name);
157 PyObject *path = PyString_FromString((*$1)[i].path);
158 PyObject *enabled = PyInt_FromSize_t((*$1)[i].enabled);
159
160 PyTuple_SetItem(tmp, 0, name);
161 PyTuple_SetItem(tmp, 1, path);
162 PyTuple_SetItem(tmp, 2, enabled);
163 PyList_Append(sessions, tmp);
164 }
165 $result = sessions;
166 }
167 }
168 %typemap(in,numinputs=0) struct lttng_session **sessions (struct lttng_session *temp){
169 $1=&temp;
170 }
171
172 //list_domains
173 %typemap(argout) struct lttng_domain **domains{
174
175 int l = PyInt_AsSsize_t($result);
176 if (l >= 0)
177 {
178 PyObject *dom = PyList_New(0);
179 int i;
180 for(i=0; i<l; i++)
181 {
182 PyObject *tmp = PyTuple_New(5);
183 PyObject *type = PyInt_FromSize_t((*$1)[i].type);
184 PyObject *execname = PyString_FromString((*$1)[i].attr.exec_name);
185 PyObject *pid = PyInt_FromSize_t((*$1)[i].attr.pid);
186 PyObject *padding = PyString_FromString((*$1)[i].padding);
187 PyObject *attrpadding = PyString_FromString((*$1)[i].attr.padding);
188
189 PyTuple_SetItem(tmp, 0, type);
190 PyTuple_SetItem(tmp, 1, padding);
191 PyTuple_SetItem(tmp, 2, pid);
192 PyTuple_SetItem(tmp, 3, execname);
193 PyTuple_SetItem(tmp, 4, attrpadding);
194 PyList_Append(dom, tmp);
195 }
196 $result = dom;
197 }
198 }
199 %typemap(in,numinputs=0) struct lttng_domain **domains (struct lttng_domain *temp){
200 $1=&temp;
201 }
202
203 //list_channels
204 %typemap(argout) struct lttng_channel **channels{
205
206 int l = PyInt_AsSsize_t($result);
207 if (l >= 0)
208 {
209 PyObject *chan = PyList_New(0);
210 int i;
211 for(i=0; i<l; i++)
212 {
213 PyObject *tmp = PyTuple_New(4);
214 PyObject *name = PyString_FromString((*$1)[i].name);
215 PyObject *enabled = PyInt_FromSize_t((*$1)[i].enabled);
216 PyObject *padding = PyString_FromString((*$1)[i].padding);
217
218 PyObject *attrtmp = PyTuple_New(7);
219 PyObject *overwrite = PyInt_FromLong((*$1)[i].attr.overwrite);
220 PyObject *subbuf = PyInt_FromSize_t((*$1)[i].attr.subbuf_size);
221 PyObject *num = PyInt_FromSize_t((*$1)[i].attr.num_subbuf);
222 PyObject *switchtimer = PyInt_FromSize_t((*$1)[i].attr.switch_timer_interval);
223 PyObject *readtimer = PyInt_FromSize_t((*$1)[i].attr.read_timer_interval);
224 PyObject *output = PyInt_FromSize_t((*$1)[i].attr.output);
225 PyObject *attrpad = PyString_FromString((*$1)[i].attr.padding);
226
227 PyTuple_SetItem(attrtmp, 0, overwrite);
228 PyTuple_SetItem(attrtmp, 1, subbuf);
229 PyTuple_SetItem(attrtmp, 2, num);
230 PyTuple_SetItem(attrtmp, 3, switchtimer);
231 PyTuple_SetItem(attrtmp, 4, readtimer);
232 PyTuple_SetItem(attrtmp, 5, output);
233 PyTuple_SetItem(attrtmp, 6, attrpad);
234
235 PyTuple_SetItem(tmp, 0, name);
236 PyTuple_SetItem(tmp, 1, enabled);
237 PyTuple_SetItem(tmp, 2, padding);
238 PyTuple_SetItem(tmp, 3, attrtmp);
239 PyList_Append(chan, tmp);
240 }
241 $result = chan;
242 }
243 }
244 %typemap(in,numinputs=0) struct lttng_channel **channels (struct lttng_channel *temp){
245 $1=&temp;
246 }
247
248 //list_events & list_tracepoints
249 %typemap(argout) struct lttng_event **events{
250
251 int l = PyInt_AsSsize_t($result);
252 if (l >= 0)
253 {
254 PyObject *events = PyList_New(0);
255 int i;
256 for(i=0; i<l; i++)
257 {
258 PyObject *tmp = PyTuple_New(10);
259 PyObject *name = PyString_FromString((*$1)[i].name);
260 PyObject *type = PyInt_FromSize_t((*$1)[i].type);
261 PyObject *logleveltype = PyInt_FromSize_t((*$1)[i].loglevel_type);
262 PyObject *loglevel = PyInt_FromLong((*$1)[i].loglevel);
263 PyObject *enabled = PyInt_FromLong((*$1)[i].enabled);
264 PyObject *pid = PyInt_FromSize_t((*$1)[i].pid);
265 PyObject *padding = PyString_FromString((*$1)[i].padding);
266 PyObject *attrpadding = PyString_FromString((*$1)[i].attr.padding);
267
268 PyObject *probe = PyTuple_New(4);
269 PyObject *addr = PyInt_FromSize_t((*$1)[i].attr.probe.addr);
270 PyObject *offset = PyInt_FromSize_t((*$1)[i].attr.probe.offset);
271 PyObject *symbolname = PyString_FromString((*$1)[i].attr.probe.symbol_name);
272 PyObject *probepad = PyString_FromString((*$1)[i].attr.probe.padding);
273
274 PyObject *function = PyTuple_New(2);
275 PyObject *f_symbolname = PyString_FromString((*$1)[i].attr.ftrace.symbol_name);
276 PyObject *f_pad = PyString_FromString((*$1)[i].attr.ftrace.padding);
277
278 PyTuple_SetItem(function, 0, f_symbolname);
279 PyTuple_SetItem(function, 1, f_pad);
280
281 PyTuple_SetItem(probe, 0, addr);
282 PyTuple_SetItem(probe, 1, offset);
283 PyTuple_SetItem(probe, 2, symbolname);
284 PyTuple_SetItem(probe, 3, probepad);
285
286 PyTuple_SetItem(tmp, 0, name);
287 PyTuple_SetItem(tmp, 1, type);
288 PyTuple_SetItem(tmp, 2, logleveltype);
289 PyTuple_SetItem(tmp, 3, loglevel);
290 PyTuple_SetItem(tmp, 4, enabled);
291 PyTuple_SetItem(tmp, 5, pid);
292 PyTuple_SetItem(tmp, 6, padding);
293 PyTuple_SetItem(tmp, 7, probe);
294 PyTuple_SetItem(tmp, 8, function);
295 PyTuple_SetItem(tmp, 9, attrpadding);
296 PyList_Append(events, tmp);
297 }
298 $result = events;
299 }
300 }
301 %typemap(in,numinputs=0) struct lttng_event **events (struct lttng_event *temp){
302 $1=&temp;
303 }
304
305
306
307 // =============================================
308 // FUNCTIONS
309 // =============================================
310
311 %rename("create") lttng_create_session(const char *name, const char *path);
312 %rename("create_snapshot") lttng_create_session_snapshot(const char *name, const char *snapshot_url);
313 %rename("destroy") lttng_destroy_session(const char *name);
314 %rename("_lttng_create_handle") lttng_create_handle(const char *session_name, struct lttng_domain *domain);
315 %rename("_lttng_destroy_handle") lttng_destroy_handle(struct lttng_handle *handle);
316 %rename("_lttng_list_sessions") lttng_list_sessions(struct lttng_session **sessions);
317 %rename("_lttng_list_domains") lttng_list_domains(const char *session_name, struct lttng_domain **domains);
318 %rename("_lttng_list_channels") lttng_list_channels(struct lttng_handle *handle,struct lttng_channel **channels);
319 %rename("_lttng_list_events") lttng_list_events(struct lttng_handle *handle, const char *channel_name, struct lttng_event **events);
320 %rename("_lttng_list_tracepoints") lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events);
321 %rename("session_daemon_alive") lttng_session_daemon_alive(void);
322 %rename("set_tracing_group") lttng_set_tracing_group(const char *name);
323 %rename("strerror") lttng_strerror(int code);
324 %rename("_lttng_register_consumer") lttng_register_consumer(struct lttng_handle *handle, const char *socket_path);
325 %rename("start") lttng_start_tracing(const char *session_name);
326 %rename("stop") lttng_stop_tracing(const char *session_name);
327 %rename("_lttng_add_context") lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx, const char *event_name, const char *channel_name);
328 %rename("_lttng_enable_event") lttng_enable_event(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name);
329 %rename("_lttng_enable_channel") lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan);
330 %rename("_lttng_disable_event") lttng_disable_event(struct lttng_handle *handle, const char *name, const char *channel_name);
331 %rename("_lttng_disable_channel") lttng_disable_channel(struct lttng_handle *handle, const char *name);
332 %rename("channel_set_default_attr") lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr);
333
334 //Redefined functions
335 struct lttng_handle *lttng_create_handle(const char *session_name,
336 struct lttng_domain *domain);
337 void lttng_destroy_handle(struct lttng_handle *handle);
338 int lttng_list_channels(struct lttng_handle *handle,struct lttng_channel **channels);
339 int lttng_list_events(struct lttng_handle *handle,
340 const char *channel_name, struct lttng_event **events);
341 int lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events);
342 int lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx,
343 const char *event_name, const char *channel_name);
344 int lttng_enable_event(struct lttng_handle *handle,
345 struct lttng_event *ev, const char *channel_name);
346 int lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan);
347 int lttng_disable_event(struct lttng_handle *handle,
348 const char *name, const char *channel_name);
349 int lttng_disable_channel(struct lttng_handle *handle, const char *name);
350 int lttng_register_consumer(struct lttng_handle *handle, const char *socket_path);
351 int lttng_list_sessions(struct lttng_session **sessions);
352 int lttng_list_domains(const char *session_name, struct lttng_domain **domains);
353
354 //Functions not needing redefinition
355 %feature("docstring")"create(str name, str path) -> int
356
357 Create a new tracing session using name and path.
358 Returns 0 on success or a negative error code."
359 int lttng_create_session(const char *name, const char *path);
360
361 %feature("docstring")"create_snapshot(str name, str snapshot_url) -> int
362
363 Create a new tracing session using name and snapshot_url in snapshot
364 mode (flight recorder).
365 Returns 0 on success or a negative error code."
366 int lttng_create_session_snapshot(const char *name, const char *path);
367
368 %feature("docstring")"destroy(str name) -> int
369
370 Tear down tracing session using name.
371 Returns 0 on success or a negative error code."
372 int lttng_destroy_session(const char *name);
373
374
375 %feature("docstring")"session_daemon_alive() -> int
376
377 Check if session daemon is alive.
378 Return 1 if alive or 0 if not.
379 On error returns a negative value."
380 int lttng_session_daemon_alive(void);
381
382
383 %feature("docstring")"set_tracing_group(str name) -> int
384
385 Sets the tracing_group variable with name.
386 This function allocates memory pointed to by tracing_group.
387 On success, returns 0, on error, returns -1 (null name) or -ENOMEM."
388 int lttng_set_tracing_group(const char *name);
389
390
391 %feature("docstring")"strerror(int code) -> char
392
393 Returns a human readable string describing
394 the error code (a negative value)."
395 const char *lttng_strerror(int code);
396
397
398 %feature("docstring")"start(str session_name) -> int
399
400 Start tracing for all traces of the session.
401 Returns size of returned session payload data or a negative error code."
402 int lttng_start_tracing(const char *session_name);
403
404
405 %feature("docstring")"stop(str session_name) -> int
406
407 Stop tracing for all traces of the session.
408 Returns size of returned session payload data or a negative error code."
409 int lttng_stop_tracing(const char *session_name);
410
411
412 %feature("docstring")"channel_set_default_attr(Domain domain, ChannelAttr attr)
413
414 Set default channel attributes.
415 If either or both of the arguments are null, attr content is zeroe'd."
416 void 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
427 def 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
454 def 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
482 def 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
519 def 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
560 def 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
600 def 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
614 def 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
632 def 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
649 def 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
663 def 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
679 def 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
693
694 // =============================================
695 // Handle class
696 // Used to prevent freeing unallocated memory
697 // =============================================
698
699 %feature("docstring")""
700 %feature("autodoc", "1");
701
702 %pythoncode %{
703 class Handle:
704 """
705 Manages a handle.
706 Takes two arguments: (str session_name, Domain domain)
707 """
708
709 __frozen = False
710
711 def __init__(self, session_name, domain):
712 if type(session_name) is not str:
713 raise TypeError("in method '__init__', argument 2 of type 'str'")
714 if type(domain) is not Domain and domain is not None:
715 raise TypeError("in method '__init__', argument 3 of type 'lttng.Domain'")
716
717 self._sname = session_name
718 if domain is None:
719 self._domtype = None
720 else:
721 self._domtype = domain.type
722 self._h = _lttng_create_handle(session_name, domain)
723 self.__frozen = True
724
725 def __del__(self):
726 _lttng_destroy_handle(self._h)
727
728 def __repr__(self):
729 if self._domtype == 1:
730 domstr = "DOMAIN_KERNEL"
731 elif self._domtype == 2:
732 domstr = "DOMAIN_UST"
733 else:
734 domstr = self._domtype
735
736 return "lttng.Handle; session('{}'), domain.type({})".format(
737 self._sname, domstr)
738
739 def __setattr__(self, attr, val):
740 if self.__frozen:
741 raise NotImplementedError("cannot modify attributes")
742 else:
743 self.__dict__[attr] = val
744 %}
745
746
747 // =============================================
748 // STRUCTURES
749 // These are directly taken from lttng.h.
750 // Any change to these structures must also be
751 // made here.
752 // =============================================
753
754 %rename("Domain") lttng_domain;
755 %rename("EventContext") lttng_event_context;
756 %rename("Event") lttng_event;
757 %rename("ChannelAttr") lttng_channel_attr;
758 %rename("Channel") lttng_channel;
759 %rename("Session") lttng_session;
760
761 struct lttng_domain{
762 enum lttng_domain_type type;
763 char padding[LTTNG_DOMAIN_PADDING1];
764
765 union {
766 pid_t pid;
767 char exec_name[NAME_MAX];
768 char padding[LTTNG_DOMAIN_PADDING2];
769 } attr;
770
771 %extend {
772 char *__repr__() {
773 static char temp[256];
774 switch ( $self->type ) {
775 case 1:
776 sprintf(temp, "lttng.Domain; type(DOMAIN_KERNEL)");
777 break;
778 case 2:
779 sprintf(temp, "lttng.Domain; type(DOMAIN_UST)");
780 break;
781 default:
782 sprintf(temp, "lttng.Domain; type(%i)", $self->type);
783 break;
784 }
785 return &temp[0];
786 }
787 }
788 };
789
790 struct lttng_event_context {
791 enum lttng_event_context_type ctx;
792 char padding[LTTNG_EVENT_CONTEXT_PADDING1];
793
794 union {
795 struct lttng_event_perf_counter_ctx perf_counter;
796 char padding[LTTNG_EVENT_CONTEXT_PADDING2];
797 } u;
798
799 %extend {
800 char *__repr__() {
801 static char temp[256];
802 switch ( $self->ctx ) {
803 case 0:
804 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PID)");
805 break;
806 case 1:
807 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PERF_COUNTER)");
808 break;
809 case 2:
810 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PROCNAME)");
811 break;
812 case 3:
813 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PRIO)");
814 break;
815 case 4:
816 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_NICE)");
817 break;
818 case 5:
819 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VPID)");
820 break;
821 case 6:
822 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_TID)");
823 break;
824 case 7:
825 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VTID)");
826 break;
827 case 8:
828 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PPID)");
829 break;
830 case 9:
831 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_VPPID)");
832 break;
833 case 10:
834 sprintf(temp, "lttng.EventContext; ctx(EVENT_CONTEXT_PTHREAD_ID)");
835 break;
836 default:
837 sprintf(temp, "lttng.EventContext; type(%i)", $self->ctx);
838 break;
839 }
840 return &temp[0];
841 }
842 }
843 };
844
845 struct lttng_event_probe_attr {
846 uint64_t addr;
847 uint64_t offset;
848 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
849 char padding[LTTNG_EVENT_PROBE_PADDING1];
850 };
851
852 struct lttng_event_function_attr {
853 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
854 char padding[LTTNG_EVENT_FUNCTION_PADDING1];
855 };
856
857 struct lttng_event {
858 enum lttng_event_type type;
859 char name[LTTNG_SYMBOL_NAME_LEN];
860
861 enum lttng_loglevel_type loglevel_type;
862 int loglevel;
863
864 int32_t enabled;
865 pid_t pid;
866
867 char padding[LTTNG_EVENT_PADDING1];
868
869 union {
870 struct lttng_event_probe_attr probe;
871 struct lttng_event_function_attr ftrace;
872
873 char padding[LTTNG_EVENT_PADDING2];
874 } attr;
875
876 %extend {
877 char *__repr__() {
878 static char temp[512];
879 char evtype[50];
880 char logtype[50];
881
882 switch ( $self->type ) {
883 case -1:
884 sprintf(evtype, "EVENT_ALL");
885 break;
886 case 0:
887 sprintf(evtype, "EVENT_TRACEPOINT");
888 break;
889 case 1:
890 sprintf(evtype, "EVENT_PROBE");
891 break;
892 case 2:
893 sprintf(evtype, "EVENT_FUNCTION");
894 break;
895 case 3:
896 sprintf(evtype, "EVENT_FUNCTION_ENTRY");
897 break;
898 case 4:
899 sprintf(evtype, "EVENT_NOOP");
900 break;
901 case 5:
902 sprintf(evtype, "EVENT_SYSCALL");
903 break;
904 default:
905 sprintf(evtype, "%i", $self->type);
906 break;
907 }
908
909 switch ( $self->loglevel_type ) {
910 case 0:
911 sprintf(logtype, "EVENT_LOGLEVEL_ALL");
912 break;
913 case 1:
914 sprintf(logtype, "EVENT_LOGLEVEL_RANGE");
915 break;
916 case 2:
917 sprintf(logtype, "EVENT_LOGLEVEL_SINGLE");
918 break;
919 default:
920 sprintf(logtype, "%i", $self->loglevel_type);
921 break;
922 }
923
924 sprintf(temp, "lttng.Event; name('%s'), type(%s), "
925 "loglevel_type(%s), loglevel(%i), "
926 "enabled(%s), pid(%i)",
927 $self->name, evtype, logtype, $self->loglevel,
928 $self->enabled ? "True" : "False", $self->pid);
929 return &temp[0];
930 }
931 }
932 };
933
934 struct lttng_channel_attr {
935 int overwrite;
936 uint64_t subbuf_size;
937 uint64_t num_subbuf;
938 unsigned int switch_timer_interval;
939 unsigned int read_timer_interval;
940 enum lttng_event_output output;
941
942 char padding[LTTNG_CHANNEL_ATTR_PADDING1];
943
944 %extend {
945 char *__repr__() {
946 static char temp[256];
947 char evout[25];
948
949 switch ( $self->output ) {
950 case 0:
951 sprintf(evout, "EVENT_SPLICE");
952 break;
953 case 1:
954 sprintf(evout, "EVENT_MMAP");
955 break;
956 default:
957 sprintf(evout, "%i", $self->output);
958 break;
959 }
960 sprintf(temp, "lttng.ChannelAttr; overwrite(%i), subbuf_size(%"PRIu64"), "
961 "num_subbuf(%"PRIu64"), switch_timer_interval(%u), "
962 "read_timer_interval(%u), output(%s)",
963 $self->overwrite, $self->subbuf_size, $self->num_subbuf,
964 $self->switch_timer_interval, $self->read_timer_interval,
965 evout);
966 return &temp[0];
967 }
968 }
969 };
970
971 struct lttng_channel {
972 char name[LTTNG_SYMBOL_NAME_LEN];
973 uint32_t enabled;
974 struct lttng_channel_attr attr;
975 char padding[LTTNG_CHANNEL_PADDING1];
976
977 %extend {
978 char *__repr__() {
979 static char temp[512];
980 snprintf(temp, sizeof(temp), "lttng.Channel; name('%s'), enabled(%s)",
981 $self->name, $self->enabled ? "True" : "False");
982 return &temp[0];
983 }
984 }
985 };
986
987 struct lttng_session {
988 char name[NAME_MAX];
989 char path[PATH_MAX];
990 uint32_t enabled;
991 uint32_t snapshot_mode;
992 unsigned int live_timer_interval;
993 union {
994 char padding[LTTNG_SESSION_PADDING1];
995 void *ptr;
996 } extended;
997
998 %extend {
999 char *__repr__() {
1000 static char temp[PATH_MAX + NAME_MAX + 512];
1001 snprintf(temp, sizeof(temp), "lttng.Session; name('%s'), path('%s'), enabled(%s)",
1002 $self->name, $self->path,
1003 $self->enabled ? "True" : "False");
1004 return &temp[0];
1005 }
1006 }
1007 };
This page took 0.04749 seconds and 3 git commands to generate.