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