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