d837a53270e1e24a51c976c81d4a5292233d9f6d
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 # ------------------------------------------------------
43 raise ImportError( "both babeltrace and lttng-tools "
44 "python modules must be installed")
47 # Errors to raise if something goes wrong
48 class LTTngError(Exception):
52 class BabeltraceError(Exception):
58 # Making sure session does not already exist
59 lttng
.destroy(ses_name
)
61 # Creating a new session and handle
62 ret
= lttng
.create(ses_name
, trace_path
)
64 raise LTTngError(lttng
.strerror(ret
))
66 domain
= lttng
.Domain()
67 domain
.type = lttng
.DOMAIN_KERNEL
70 han
= lttng
.Handle(ses_name
, domain
)
72 raise LTTngError("Handle not created")
77 event
.type = lttng
.EVENT_ALL
78 event
.loglevel_type
= lttng
.EVENT_LOGLEVEL_ALL
79 ret
= lttng
.enable_event(han
, event
, None)
81 raise LTTngError(lttng
.strerror(ret
))
84 ret
= lttng
.start(ses_name
)
86 raise LTTngError(lttng
.strerror(ret
))
90 ret
= lttng
.stop(ses_name
)
92 raise LTTngError(lttng
.strerror(ret
))
95 # Destroying tracing session
96 ret
= lttng
.destroy(ses_name
)
98 raise LTTngError(lttng
.strerror(ret
))
103 # Create TraceCollecion and add trace:
104 traces
= babeltrace
.TraceCollection()
105 ret
= traces
.add_trace(trace_path
+ "/kernel", "ctf")
107 raise BabeltraceError("Error adding trace")
109 # Reading events from trace
110 # and outputting timestamps and event names
112 print("Writing trace file...")
113 output
= open(out_file
, "wt")
115 for event
in traces
.events
:
116 output
.write("TS: {}, {} : {}\n".format(
117 event
.timestamp
, event
.cycles
, event
.name
))
This page took 0.038355 seconds and 4 git commands to generate.