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