1 # The MIT License (MIT)
3 # Copyright (c) 2015 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
30 class ByteOrder(enum
.Enum
):
36 class Encoding(enum
.Enum
):
56 class PropertyMapping
:
57 def __init__(self
, object, prop
):
71 def __init__(self
, size
, byte_order
, align
=None, signed
=False,
72 base
=10, encoding
=Encoding
.NONE
, property_mappings
=None):
74 self
._byte
_order
= byte_order
86 self
._encoding
= encoding
88 if property_mappings
is None:
89 self
._property
_mappings
= []
91 self
._property
_mappings
= property_mappings
99 return self
._byte
_order
107 return self
._encoding
118 def property_mappings(self
):
119 return self
._property
_mappings
122 class FloatingPoint(Type
):
123 def __init__(self
, exp_size
, mant_size
, byte_order
, align
=8):
124 self
._exp
_size
= exp_size
125 self
._mant
_size
= mant_size
126 self
._byte
_order
= byte_order
131 return self
._exp
_size
135 return self
._mant
_size
139 return self
._exp
_size
+ self
._mant
_size
142 def byte_order(self
):
143 return self
._byte
_order
151 def __init__(self
, value_type
, members
=None):
152 self
._value
_type
= value_type
155 self
._members
= collections
.OrderedDict()
157 self
._members
= members
161 return self
._value
_type
.align
165 return self
._value
_type
.size
168 def value_type(self
):
169 return self
._value
_type
176 def last_value(self
):
177 if len(self
._members
) == 0:
180 return list(self
._members
.values())[-1][1]
182 def value_of(self
, label
):
183 return self
._members
[label
]
185 def label_of(self
, value
):
186 for label
, vrange
in self
._members
.items():
187 if value
>= vrange
[0] and value
<= vrange
[1]:
190 def __getitem__(self
, key
):
192 return self
.value_of(key
)
193 elif type(key
) is int:
194 return self
.label_of(key
)
196 raise TypeError('Wrong subscript type')
200 def __init__(self
, encoding
=Encoding
.UTF8
):
201 self
._encoding
= encoding
.UTF8
209 return self
._encoding
212 def is_dynamic(self
):
217 def __init__(self
, element_type
, length
):
218 self
._element
_type
= element_type
219 self
._length
= length
223 return self
._element
_type
.align
226 def element_type(self
):
227 return self
._element
_type
235 def __init__(self
, min_align
=1, fields
=None):
236 self
._min
_align
= min_align
239 self
._fields
= collections
.OrderedDict()
241 self
._fields
= fields
243 self
._align
= self
.min_align
245 for field
in self
.fields
.values():
246 if field
.align
is None:
249 if field
.align
> self
._align
:
250 self
._align
= field
.align
254 return self
._min
_align
264 def __getitem__(self
, key
):
265 return self
.fields
[key
]
268 return len(self
._fields
)
272 def __init__(self
, byte_order
, uuid
=None, packet_header_type
=None):
273 self
._byte
_order
= byte_order
275 self
._packet
_header
_type
= packet_header_type
282 def byte_order(self
):
283 return self
._byte
_order
286 def packet_header_type(self
):
287 return self
._packet
_header
_type
291 def __init__(self
, name
, uuid
=None, description
=None, freq
=int(1e9
),
292 error_cycles
=0, offset_seconds
=0, offset_cycles
=0,
293 absolute
=False, return_ctype
='uint32_t'):
296 self
._description
= description
298 self
._error
_cycles
= error_cycles
299 self
._offset
_seconds
= offset_seconds
300 self
._offset
_cycles
= offset_cycles
301 self
._absolute
= absolute
302 self
._return
_ctype
= return_ctype
313 def description(self
):
314 return self
._description
317 def error_cycles(self
):
318 return self
._error
_cycles
325 def offset_seconds(self
):
326 return self
._offset
_seconds
329 def offset_cycles(self
):
330 return self
._offset
_cycles
334 return self
._absolute
337 def return_ctype(self
):
338 return self
._return
_ctype
341 LogLevel
= collections
.namedtuple('LogLevel', ['name', 'value'])
345 def __init__(self
, id, name
, log_level
=None, payload_type
=None,
349 self
._payload
_type
= payload_type
350 self
._log
_level
= log_level
351 self
._context
_type
= context_type
363 return self
._log
_level
366 def context_type(self
):
367 return self
._context
_type
370 def payload_type(self
):
371 return self
._payload
_type
373 def __getitem__(self
, key
):
374 if self
.payload_type
is None:
377 return self
.payload_type
[key
]
381 def __init__(self
, id, name
=None, packet_context_type
=None,
382 event_header_type
=None, event_context_type
=None,
386 self
._packet
_context
_type
= packet_context_type
387 self
._event
_header
_type
= event_header_type
388 self
._event
_context
_type
= event_context_type
391 self
._events
= collections
.OrderedDict()
393 self
._events
= events
404 def packet_context_type(self
):
405 return self
._packet
_context
_type
408 def event_header_type(self
):
409 return self
._event
_header
_type
412 def event_context_type(self
):
413 return self
._event
_context
_type
421 def __init__(self
, trace
, env
=None, clocks
=None, streams
=None,
422 default_stream_name
=None):
424 version_tuple
= barectf
.get_version_tuple()
425 self
._env
= collections
.OrderedDict([
427 ('tracer_name', 'barectf'),
428 ('tracer_major', version_tuple
[0]),
429 ('tracer_minor', version_tuple
[1]),
430 ('tracer_patch', version_tuple
[2]),
431 ('barectf_gen_date', str(datetime
.datetime
.now().isoformat())),
435 self
._env
.update(env
)
438 self
._clocks
= collections
.OrderedDict()
440 self
._clocks
= clocks
443 self
._streams
= collections
.OrderedDict()
445 self
._streams
= streams
447 self
._default
_stream
_name
= default_stream_name
466 def default_stream_name(self
):
467 return self
._default
_stream
_name
470 def default_stream(self
):
471 if self
._default
_stream
_name
in self
._streams
:
472 return self
._streams
[self
._default
_stream
_name
]
This page took 0.038615 seconds and 5 git commands to generate.