2 # babeltrace_and_lttng.py
4 # Babeltrace and LTTng example script
6 # Copyright 2012 EfficiOS Inc.
8 # Author: Danny Serres <danny.serres@efficios.com>
10 # Permission is hereby granted, free of charge, to any person obtaining a copy
11 # of this software and associated documentation files (the "Software"), to deal
12 # in the Software without restriction, including without limitation the rights
13 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 # copies of the Software, and to permit persons to whom the Software is
15 # furnished to do so, subject to the following conditions:
17 # The above copyright notice and this permission notice shall be included in
18 # all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 # This script uses both lttng-tools and babeltrace
30 # python modules. It creates a session, enables
31 # events, starts tracing for 2 seconds, stops tracing,
32 # destroys the session and outputs the trace in the
33 # specified output file.
35 # WARNING: will destroy any existing trace having
36 # the same name as ses_name
39 # ------------------------------------------------------
40 ses_name
= "babeltrace-lttng-test"
41 trace_path
= "/lttng-traces/babeltrace-lttng-trace/"
42 out_file
= "babeltrace-lttng-trace-text-output.txt"
43 # ------------------------------------------------------
48 import babeltrace
.reader
51 raise ImportError( "both babeltrace and lttng-tools "
52 "python modules must be installed")
55 # Errors to raise if something goes wrong
56 class LTTngError(Exception):
60 class BabeltraceError(Exception):
66 # Making sure session does not already exist
67 lttng
.destroy(ses_name
)
69 # Creating a new session and handle
70 ret
= lttng
.create(ses_name
, trace_path
)
72 raise LTTngError(lttng
.strerror(ret
))
74 domain
= lttng
.Domain()
75 domain
.type = lttng
.DOMAIN_KERNEL
78 han
= lttng
.Handle(ses_name
, domain
)
80 raise LTTngError("Handle not created")
85 event
.type = lttng
.EVENT_ALL
86 event
.loglevel_type
= lttng
.EVENT_LOGLEVEL_ALL
87 ret
= lttng
.enable_event(han
, event
, None)
89 raise LTTngError(lttng
.strerror(ret
))
92 ret
= lttng
.start(ses_name
)
94 raise LTTngError(lttng
.strerror(ret
))
98 ret
= lttng
.stop(ses_name
)
100 raise LTTngError(lttng
.strerror(ret
))
103 # Destroying tracing session
104 ret
= lttng
.destroy(ses_name
)
106 raise LTTngError(lttng
.strerror(ret
))
111 # Create TraceCollecion and add trace:
112 traces
= babeltrace
.reader
.TraceCollection()
113 ret
= traces
.add_trace(trace_path
+ "/kernel", "ctf")
115 raise BabeltraceError("Error adding trace")
117 # Reading events from trace
118 # and outputting timestamps and event names
120 print("Writing trace file...")
121 output
= open(out_file
, "wt")
123 for event
in traces
.events
:
124 output
.write("TS: {}, {} : {}\n".format(
125 event
.timestamp
, event
.cycles
, event
.name
))
This page took 0.03138 seconds and 4 git commands to generate.