3 # Copyright (C) - 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # Import lttng bindings generated in the current tree
26 lttng_bindings_path
= os
.path
.dirname(os
.path
.abspath(__file__
)) + "/"
28 lttng_bindings_path
= os
.path
.dirname(lttng_bindings_path
)
29 lttng_bindings_path
= lttng_bindings_path
+ "/extras/bindings/swig/python"
30 lttng_bindings_libs_path
= lttng_bindings_path
+ "/.libs"
31 sys
.path
.append(lttng_bindings_path
)
32 sys
.path
.append(lttng_bindings_libs_path
)
37 def __init__(self
, handle
, session_name
, tmp_directory
, channel_name
):
39 self
.name
= session_name
40 self
.tmp_directory
= tmp_directory
41 self
.trace_path
= tmp_directory
+ "/" + session_name
42 self
.channel_name
= channel_name
44 def bail(diag
, session_info
= None):
48 if session_info
is not None:
49 stop_session(session_info
, True)
51 if os
.path
.exists(session_info
.tmp_directory
):
52 shutil
.rmtree(session_info
.tmp_directory
)
55 def print_test_result(result
, number
, description
):
60 result_string
= "not ok"
62 result_string
+= " {0} - {1}".format(number
, description
)
65 def enable_ust_tracepoint_event(session_info
, event_name
):
67 event
.name
= event_name
68 event
.type = EVENT_TRACEPOINT
69 event
.loglevel
= EVENT_LOGLEVEL_ALL
70 res
= enable_event(session_info
.handle
, event
, session_info
.channel_name
)
72 bail("Failed to enable userspace event " + event_name
, session_info
)
78 session_name
= str(uuid
.uuid1())
79 tmp_directory
= tempfile
.mkdtemp()
80 trace_path
= tmp_directory
+ "/" + session_name
82 res
= create(session_name
, trace_path
)
84 bail("Failed to create tracing session.")
87 channel
.name
= "channel0"
88 channel_set_default_attr(dom
, channel
.attr
)
90 han
= Handle(session_name
, dom
)
91 res
= enable_channel(han
, channel
)
93 session_info
= SessionInfo(han
, session_name
, tmp_directory
, channel
.name
)
95 bail("Failed to enable channel " + channel
.name
, session_info
)
98 def start_session(session_info
):
99 start(session_info
.name
)
101 def stop_session(session_info
, bailing
= False):
102 # Workaround lttng-ctl outputing directly to stdout by spawning a subprocess.
103 lttng_binary_path
= os
.path
.dirname(os
.path
.abspath(__file__
)) + "/"
105 lttng_binary_path
= os
.path
.dirname(lttng_binary_path
)
106 lttng_binary_path
= lttng_binary_path
+ "/src/bin/lttng/lttng"
108 retcode
= subprocess
.call([lttng_binary_path
, "stop", session_info
.name
], stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
109 if retcode
!= 0 and not bailing
:
110 bail("Unable to stop session " + session_info
.name
, session_info
)
111 destroy(session_info
.name
)
This page took 0.032725 seconds and 5 git commands to generate.