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