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.
21 # This script uses both lttng-tools and babeltrace
22 # python modules. It creates a session, enables
23 # events, starts tracing for 2 seconds, stops tracing,
24 # destroys the session and outputs the trace in the
25 # specified output file.
27 # WARNING: will destroy any existing trace having
28 # the same name as ses_name
31 # ------------------------------------------------------
32 ses_name
= "babeltrace-lttng-test"
33 trace_path
= "/lttng-traces/babeltrace-lttng-trace/"
34 out_file
= "babeltrace-lttng-trace-text-output.txt"
35 # ------------------------------------------------------
40 import babeltrace
, lttng
42 raise ImportError( "both babeltrace and lttng-tools "
43 "python modules must be installed" )
46 # Errors to raise if something goes wrong
47 class LTTngError(Exception):
49 class BabeltraceError(Exception):
55 # Making sure session does not already exist
56 lttng
.destroy(ses_name
)
58 # Creating a new session and handle
59 ret
= lttng
.create(ses_name
,trace_path
)
61 raise LTTngError(lttng
.strerror(ret
))
63 domain
= lttng
.Domain()
64 domain
.type = lttng
.DOMAIN_KERNEL
67 han
= lttng
.Handle(ses_name
, domain
)
69 raise LTTngError("Handle not created")
74 event
.type = lttng
.EVENT_ALL
75 event
.loglevel_type
= lttng
.EVENT_LOGLEVEL_ALL
76 ret
= lttng
.enable_event(han
, event
, None)
78 raise LTTngError(lttng
.strerror(ret
))
81 ret
= lttng
.start(ses_name
)
83 raise LTTngError(lttng
.strerror(ret
))
87 ret
= lttng
.stop(ses_name
)
89 raise LTTngError(lttng
.strerror(ret
))
92 # Destroying tracing session
93 ret
= lttng
.destroy(ses_name
)
95 raise LTTngError(lttng
.strerror(ret
))
100 # Create TraceCollecion and add trace:
101 traces
= babeltrace
.TraceCollection()
102 ret
= traces
.add_trace(trace_path
+ "/kernel", "ctf")
104 raise BabeltraceError("Error adding trace")
106 # Reading events from trace
107 # and outputting timestamps and event names
109 print("Writing trace file...")
110 output
= open(out_file
, "wt")
112 for event
in traces
.events
:
113 output
.write("TS: {}, {} : {}\n".format(event
.get_timestamp(),
114 event
.get_cycles(), event
.get_name()))
This page took 0.035206 seconds and 5 git commands to generate.