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