bbcc2b403fa9f20bb10667df3459011ae6be6ee1
1 # The MIT License (MIT)
3 # Copyright (c) 2016-2017 Philippe Proulx <pproulx@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
23 from bt2
import native_bt
, object, stream
, utils
31 class CtfWriterClock(bt2
.object._SharedObject
):
32 def __init__(self
, name
, description
=None, frequency
=None, precision
=None,
33 offset
=None, is_absolute
=None, uuid
=None):
34 utils
._check
_str
(name
)
35 ptr
= native_bt
.ctf_clock_create(name
)
38 raise bt2
.CreationError('cannot create CTF writer clock object')
42 if description
is not None:
43 self
.description
= description
45 if frequency
is not None:
46 self
.frequency
= frequency
48 if precision
is not None:
49 self
.precision
= precision
51 if offset
is not None:
54 if is_absolute
is not None:
55 self
.is_absolute
= is_absolute
60 def __eq__(self
, other
):
61 if type(self
) is not type(other
):
62 # not comparing apples to apples
65 if self
.addr
== other
.addr
:
86 return self_props
== other_props
89 return CtfWriterClock(name
=self
.name
, description
=self
.description
,
90 frequency
=self
.frequency
,
91 precision
=self
.precision
, offset
=self
.offset
,
92 is_absolute
=self
.is_absolute
, uuid
=self
.uuid
)
94 def __deepcopy__(self
, memo
):
101 name
= native_bt
.ctf_clock_get_name(self
._ptr
)
102 assert(name
is not None)
106 def description(self
):
107 description
= native_bt
.ctf_clock_get_description(self
._ptr
)
111 def description(self
, description
):
112 utils
._check
_str
(description
)
113 ret
= native_bt
.ctf_clock_set_description(self
._ptr
, description
)
114 utils
._handle
_ret
(ret
, "cannot set CTF writer clock object's description")
118 frequency
= native_bt
.ctf_clock_get_frequency(self
._ptr
)
119 assert(frequency
>= 1)
123 def frequency(self
, frequency
):
124 utils
._check
_uint
64(frequency
)
125 ret
= native_bt
.ctf_clock_set_frequency(self
._ptr
, frequency
)
126 utils
._handle
_ret
(ret
, "cannot set CTF writer clock object's frequency")
130 precision
= native_bt
.ctf_clock_get_precision(self
._ptr
)
131 assert(precision
>= 0)
135 def precision(self
, precision
):
136 utils
._check
_uint
64(precision
)
137 ret
= native_bt
.ctf_clock_set_precision(self
._ptr
, precision
)
138 utils
._handle
_ret
(ret
, "cannot set CTF writer clock object's precision")
142 ret
, offset_s
= native_bt
.ctf_clock_get_offset_s(self
._ptr
)
144 ret
, offset_cycles
= native_bt
.ctf_clock_get_offset(self
._ptr
)
146 return bt2
.ClockClassOffset(offset_s
, offset_cycles
)
149 def offset(self
, offset
):
150 utils
._check
_type
(offset
, bt2
.ClockClassOffset
)
151 ret
= native_bt
.ctf_clock_set_offset_s(self
._ptr
, offset
.seconds
)
152 utils
._handle
_ret
(ret
, "cannot set CTF writer clock object's offset (seconds)")
153 ret
= native_bt
.ctf_clock_set_offset(self
._ptr
, offset
.cycles
)
154 utils
._handle
_ret
(ret
, "cannot set CTF writer clock object's offset (cycles)")
157 def is_absolute(self
):
158 is_absolute
= native_bt
.ctf_clock_get_is_absolute(self
._ptr
)
159 assert(is_absolute
>= 0)
160 return is_absolute
> 0
163 def is_absolute(self
, is_absolute
):
164 utils
._check
_bool
(is_absolute
)
165 ret
= native_bt
.ctf_clock_set_is_absolute(self
._ptr
, int(is_absolute
))
166 utils
._handle
_ret
(ret
, "cannot set CTF writer clock object's absoluteness")
170 uuid_bytes
= native_bt
.ctf_clock_get_uuid(self
._ptr
)
171 assert(uuid_bytes
is not None)
172 return uuidp
.UUID(bytes
=uuid_bytes
)
175 def uuid(self
, uuid
):
176 utils
._check
_type
(uuid
, uuidp
.UUID
)
177 ret
= native_bt
.ctf_clock_set_uuid(self
._ptr
, uuid
.bytes
)
178 utils
._handle
_ret
(ret
, "cannot set CTF writer clock object's UUID")
180 def _time(self
, time
):
181 utils
._check
_int
64(time
)
182 ret
= native_bt
.ctf_clock_set_time(self
._ptr
, time
)
184 time
= property(fset
=_time
)
187 class _CtfWriterStream
:
189 def discarded_events_count(self
):
190 ret
, count
= native_bt
.stream_get_discarded_events_count(self
._ptr
)
191 utils
._handle
_ret
(ret
, "cannot get CTF writer stream object's discarded events count")
194 def append_discarded_events(self
, count
):
195 utils
._check
_uint
64(count
)
196 native_bt
.stream_append_discarded_events(self
._ptr
, count
)
198 def append_event(self
, event
):
199 utils
._check
_type
(event
, bt2
.event
._Event
)
200 ret
= native_bt
.stream_append_event(self
._ptr
, event
._ptr
)
201 utils
._handle
_ret
(ret
, 'cannot append event object to CTF writer stream object')
204 ret
= native_bt
.stream_flush(self
._ptr
)
205 utils
._handle
_ret
(ret
, 'cannot flush CTF writer stream object')
208 def packet_header_field(self
):
209 field_ptr
= native_bt
.stream_get_packet_header(self
._ptr
)
211 if field_ptr
is None:
214 return bt2
.field
._create
_from
_ptr
(field_ptr
)
216 @packet_header_field.setter
217 def packet_header_field(self
, packet_header_field
):
218 packet_header_field_ptr
= None
220 if packet_header_field
is not None:
221 utils
._check
_type
(packet_header_field
, bt2
.field
._Field
)
222 packet_header_field_ptr
= packet_header_field
._ptr
224 ret
= native_bt
.stream_set_packet_header(self
._ptr
,
225 packet_header_field_ptr
)
226 utils
._handle
_ret
(ret
, "cannot set CTF writer stream object's packet header field")
229 def packet_context_field(self
):
230 field_ptr
= native_bt
.stream_get_packet_context(self
._ptr
)
232 if field_ptr
is None:
235 return bt2
.field
._create
_from
_ptr
(field_ptr
)
237 @packet_context_field.setter
238 def packet_context_field(self
, packet_context_field
):
239 packet_context_field_ptr
= None
241 if packet_context_field
is not None:
242 utils
._check
_type
(packet_context_field
, bt2
.field
._Field
)
243 packet_context_field_ptr
= packet_context_field
._ptr
245 ret
= native_bt
.stream_set_packet_context(self
._ptr
,
246 packet_context_field_ptr
)
247 utils
._handle
_ret
(ret
, "cannot set CTF writer stream object's packet context field")
249 def __eq__(self
, other
):
250 if type(other
) is not type(self
):
253 if self
.addr
== other
.addr
:
256 if not _StreamBase
.__eq
__(self
, other
):
260 self
.discarded_events_count
,
261 self
.packet_header_field
,
262 self
.packet_context_field
,
265 other
.discarded_events_count
,
266 other
.packet_header_field
,
267 other
.packet_context_field
,
269 return self_props
== other_props
271 def _copy(self
, copy_func
):
272 cpy
= self
.stream_class(self
.name
)
273 cpy
.append_discarded_events(self
.discarded_events_count
)
274 cpy
.packet_header_field
= copy_func(self
.packet_header_field
)
275 cpy
.packet_context_field
= copy_func(self
.packet_context_field
)
279 return self
._copy
(copy
.copy
)
281 def __deepcopy__(self
, memo
):
282 cpy
= self
._copy
(copy
.deepcopy
)
287 class CtfWriter(bt2
.object._SharedObject
):
288 def __init__(self
, path
):
289 utils
._check
_str
(path
)
290 ptr
= native_bt
.ctf_writer_create(path
)
293 raise bt2
.CreationError('cannot create CTF writer object')
295 super().__init
__(ptr
)
299 trace_ptr
= native_bt
.ctf_writer_get_trace(self
._ptr
)
301 return bt2
.Trace
._create
_from
_ptr
(trace_ptr
)
304 def metadata_string(self
):
305 metadata_string
= native_bt
.ctf_writer_get_metadata_string(self
._ptr
)
306 assert(metadata_string
is not None)
307 return metadata_string
309 def flush_metadata(self
):
310 native_bt
.ctf_writer_flush_metadata(self
._ptr
)
312 def add_clock(self
, clock
):
313 utils
._check
_type
(clock
, CtfWriterClock
)
314 ret
= native_bt
.ctf_writer_add_clock(self
._ptr
, clock
._ptr
)
315 utils
._handle
_ret
(ret
, 'cannot add CTF writer clock object to CTF writer object')
This page took 0.035609 seconds and 3 git commands to generate.