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