Move to kernel style SPDX license identifiers
[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 # This error will be raised is something goes wrong
11 class LTTngError(Exception):
12 def __init__(self, value):
13 self.value = value
14 def __str__(self):
15 return repr(self.value)
16
17 #Setting up the domain to use
18 dom = Domain()
19 dom.type = DOMAIN_KERNEL
20
21 #Setting up a channel to use
22 channel = Channel()
23 channel.name = "mychan"
24 channel.attr.overwrite = 0
25 channel.attr.subbuf_size = 4096
26 channel.attr.num_subbuf = 8
27 channel.attr.switch_timer_interval = 0
28 channel.attr.read_timer_interval = 200
29 channel.attr.output = EVENT_SPLICE
30
31 #Setting up some events that will be used
32 event = Event()
33 event.type = EVENT_TRACEPOINT
34 event.loglevel_type = EVENT_LOGLEVEL_ALL
35
36 sched_switch = Event()
37 sched_switch.name = "sched_switch"
38 sched_switch.type = EVENT_TRACEPOINT
39 sched_switch.loglevel_type = EVENT_LOGLEVEL_ALL
40
41 sched_process_exit = Event()
42 sched_process_exit.name = "sched_process_exit"
43 sched_process_exit.type = EVENT_TRACEPOINT
44 sched_process_exit.loglevel_type = EVENT_LOGLEVEL_ALL
45
46 sched_process_free = Event()
47 sched_process_free.name = "sched_process_free"
48 sched_process_free.type = EVENT_TRACEPOINT
49 sched_process_free.loglevel_type = EVENT_LOGLEVEL_ALL
50
51
52 #Creating a new session
53 res = create("test","/lttng-traces/test")
54 if res<0:
55 raise LTTngError(strerror(res))
56
57 #Creating handle
58 han = None
59 han = Handle("test", dom)
60 if han is None:
61 raise LTTngError("Handle not created")
62
63 #Enabling the kernel channel
64 res = enable_channel(han, channel)
65 if res<0:
66 raise LTTngError(strerror(res))
67
68 #Enabling some events in given channel
69 #To enable all events in default channel, use
70 #enable_event(han, event, None)
71 res = enable_event(han, sched_switch, channel.name)
72 if res<0:
73 raise LTTngError(strerror(res))
74
75 res = enable_event(han, sched_process_exit, channel.name)
76 if res<0:
77 raise LTTngError(strerror(res))
78
79 res = enable_event(han, sched_process_free, channel.name)
80 if res<0:
81 raise LTTngError(strerror(res))
82
83 #Disabling an event
84 res = disable_event(han, sched_switch.name, channel.name)
85 if res<0:
86 raise LTTngError(strerror(res))
87
88 #Getting a list of the channels
89 l = list_channels(han)
90 if type(l) is int:
91 raise LTTngError(strerror(l))
92
93 #Starting the trace
94 res = start("test")
95 if res<0:
96 raise LTTngError(strerror(res))
97
98 #Stopping the trace
99 res = stop("test")
100 if res<0:
101 raise LTTngError(strerror(res))
102
103 #Disabling a channel
104 res = disable_channel(han, channel.name)
105 if res<0:
106 raise LTTngError(strerror(res))
107
108 #Destroying the handle
109 del han
110
111 #Destroying the session
112 res = destroy("test")
113 if res<0:
114 raise LTTngError(strerror(res))
This page took 0.030975 seconds and 4 git commands to generate.