1 # The MIT License (MIT)
3 # Copyright (c) 2013-2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 from babeltrace
import reader_event_declaration
30 A :class:`TraceHandle` is a handle allowing the user to manipulate
31 a specific trace directly. It is a unique identifier representing a
32 trace, and is not meant to be instantiated by the user.
36 raise NotImplementedError("TraceHandle cannot be instantiated")
39 # TODO print an id or some information about component / query result?
40 return "Babeltrace TraceHandle: trace_id('{0}')".format(self
._id
)
43 return hash((self
.path
, self
.id))
45 def __eq__(self
, other
):
46 if type(other
) is not type(self
):
49 return (self
.path
, self
.id) == (other
.path
, other
.id)
54 Numeric ID of this trace handle.
62 Path of the underlying trace.
67 def _query_trace_info(self
):
69 result
= bt2
.QueryExecutor().query(self
._trace
_collection
._fs
_comp
_cls
,
70 'trace-info', {'path': self
._path
})
74 assert(len(result
) == 1)
78 def timestamp_begin(self
):
80 Buffers creation timestamp (nanoseconds since Epoch) of the
84 result
= self
._query
_trace
_info
()
87 return int(result
[0]['range-ns']['begin'])
92 def timestamp_end(self
):
94 Buffers destruction timestamp (nanoseconds since Epoch) of the
98 result
= self
._query
_trace
_info
()
101 return int(result
[0]['range-ns']['end'])
106 def _has_intersection(self
):
107 result
= self
._query
_trace
_info
()
110 return 'intersection-range-ns' in result
[0]
114 def _get_event_declarations(self
):
115 notif_iter
= bt2
.TraceCollectionNotificationIterator([
116 bt2
.SourceComponentSpec('ctf', 'fs', self
._path
)
119 # raises if the trace contains no streams
120 first_notif
= next(notif_iter
)
121 assert(type(first_notif
) is bt2
.StreamBeginningNotification
)
122 trace
= first_notif
.stream
.stream_class
.trace
123 ec_iters
= [sc
.values() for sc
in trace
.values()]
124 return map(reader_event_declaration
._create
_event
_declaration
,
125 itertools
.chain(*ec_iters
))
130 Generates all the :class:`EventDeclaration` objects of the
135 return self
._get
_event
_declarations
()