docs: Add supported versions and fix-backport policy
[lttng-tools.git] / extras / bindings / swig / python / tests / example.py
1 #
2 # Copyright (C) 2012 Danny Serres <danny.serres@efficios.com>
3 #
4 # SPDX-License-Identifier: GPL-2.0-only
5 #
6 # This example shows basically how to use the lttng-tools python module
7
8 from lttng import *
9
10
11 # This error will be raised is something goes wrong
12 class LTTngError(Exception):
13 def __init__(self, value):
14 self.value = value
15
16 def __str__(self):
17 return repr(self.value)
18
19
20 # Setting up the domain to use
21 dom = Domain()
22 dom.type = DOMAIN_KERNEL
23
24 # Setting up a channel to use
25 channel = Channel()
26 channel.name = "mychan"
27 channel.attr.overwrite = 0
28 channel.attr.subbuf_size = 4096
29 channel.attr.num_subbuf = 8
30 channel.attr.switch_timer_interval = 0
31 channel.attr.read_timer_interval = 200
32 channel.attr.output = EVENT_SPLICE
33
34 # Setting up some events that will be used
35 event = Event()
36 event.type = EVENT_TRACEPOINT
37 event.loglevel_type = EVENT_LOGLEVEL_ALL
38
39 sched_switch = Event()
40 sched_switch.name = "sched_switch"
41 sched_switch.type = EVENT_TRACEPOINT
42 sched_switch.loglevel_type = EVENT_LOGLEVEL_ALL
43
44 sched_process_exit = Event()
45 sched_process_exit.name = "sched_process_exit"
46 sched_process_exit.type = EVENT_TRACEPOINT
47 sched_process_exit.loglevel_type = EVENT_LOGLEVEL_ALL
48
49 sched_process_free = Event()
50 sched_process_free.name = "sched_process_free"
51 sched_process_free.type = EVENT_TRACEPOINT
52 sched_process_free.loglevel_type = EVENT_LOGLEVEL_ALL
53
54
55 # Creating a new session
56 res = create("test", "/lttng-traces/test")
57 if res < 0:
58 raise LTTngError(strerror(res))
59
60 # Creating handle
61 han = None
62 han = Handle("test", dom)
63 if han is None:
64 raise LTTngError("Handle not created")
65
66 # Enabling the kernel channel
67 res = enable_channel(han, channel)
68 if res < 0:
69 raise LTTngError(strerror(res))
70
71 # Enabling some events in given channel
72 # To enable all events in default channel, use
73 # enable_event(han, event, None)
74 res = enable_event(han, sched_switch, channel.name)
75 if res < 0:
76 raise LTTngError(strerror(res))
77
78 res = enable_event(han, sched_process_exit, channel.name)
79 if res < 0:
80 raise LTTngError(strerror(res))
81
82 res = enable_event(han, sched_process_free, channel.name)
83 if res < 0:
84 raise LTTngError(strerror(res))
85
86 # Disabling an event
87 res = disable_event(han, sched_switch.name, channel.name)
88 if res < 0:
89 raise LTTngError(strerror(res))
90
91 # Getting a list of the channels
92 l = list_channels(han)
93 if type(l) is int:
94 raise LTTngError(strerror(l))
95
96 # Starting the trace
97 res = start("test")
98 if res < 0:
99 raise LTTngError(strerror(res))
100
101 # Stopping the trace
102 res = stop("test")
103 if res < 0:
104 raise LTTngError(strerror(res))
105
106 # Disabling a channel
107 res = disable_channel(han, channel.name)
108 if res < 0:
109 raise LTTngError(strerror(res))
110
111 # Destroying the handle
112 del han
113
114 # Destroying the session
115 res = destroy("test")
116 if res < 0:
117 raise LTTngError(strerror(res))
This page took 0.031885 seconds and 5 git commands to generate.