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