fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[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
6a871bbe 10
36907cb5
DS
11# This error will be raised is something goes wrong
12class LTTngError(Exception):
6a871bbe
KS
13 def __init__(self, value):
14 self.value = value
15
16 def __str__(self):
17 return repr(self.value)
18
36907cb5 19
6a871bbe 20# Setting up the domain to use
36907cb5
DS
21dom = Domain()
22dom.type = DOMAIN_KERNEL
23
6a871bbe 24# Setting up a channel to use
36907cb5
DS
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
6a871bbe 34# Setting up some events that will be used
36907cb5
DS
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
6a871bbe
KS
55# Creating a new session
56res = create("test", "/lttng-traces/test")
57if res < 0:
58 raise LTTngError(strerror(res))
36907cb5 59
6a871bbe 60# Creating handle
36907cb5
DS
61han = None
62han = Handle("test", dom)
63if han is None:
6a871bbe 64 raise LTTngError("Handle not created")
36907cb5 65
6a871bbe 66# Enabling the kernel channel
36907cb5 67res = enable_channel(han, channel)
6a871bbe
KS
68if res < 0:
69 raise LTTngError(strerror(res))
36907cb5 70
6a871bbe
KS
71# Enabling some events in given channel
72# To enable all events in default channel, use
73# enable_event(han, event, None)
36907cb5 74res = enable_event(han, sched_switch, channel.name)
6a871bbe
KS
75if res < 0:
76 raise LTTngError(strerror(res))
36907cb5
DS
77
78res = enable_event(han, sched_process_exit, channel.name)
6a871bbe
KS
79if res < 0:
80 raise LTTngError(strerror(res))
36907cb5
DS
81
82res = enable_event(han, sched_process_free, channel.name)
6a871bbe
KS
83if res < 0:
84 raise LTTngError(strerror(res))
36907cb5 85
6a871bbe 86# Disabling an event
36907cb5 87res = disable_event(han, sched_switch.name, channel.name)
6a871bbe
KS
88if res < 0:
89 raise LTTngError(strerror(res))
36907cb5 90
6a871bbe 91# Getting a list of the channels
36907cb5
DS
92l = list_channels(han)
93if type(l) is int:
6a871bbe 94 raise LTTngError(strerror(l))
36907cb5 95
6a871bbe 96# Starting the trace
36907cb5 97res = start("test")
6a871bbe
KS
98if res < 0:
99 raise LTTngError(strerror(res))
36907cb5 100
6a871bbe 101# Stopping the trace
36907cb5 102res = stop("test")
6a871bbe
KS
103if res < 0:
104 raise LTTngError(strerror(res))
36907cb5 105
6a871bbe 106# Disabling a channel
36907cb5 107res = disable_channel(han, channel.name)
6a871bbe
KS
108if res < 0:
109 raise LTTngError(strerror(res))
36907cb5 110
6a871bbe 111# Destroying the handle
36907cb5
DS
112del han
113
6a871bbe 114# Destroying the session
36907cb5 115res = destroy("test")
6a871bbe
KS
116if res < 0:
117 raise LTTngError(strerror(res))
This page took 0.056475 seconds and 4 git commands to generate.