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
24 import babeltrace
.common
as common
25 import babeltrace
.reader_field_declaration
as field_declaration
28 def _create_event_declaration(event_class
):
29 event_declaration
= EventDeclaration
.__new
__(EventDeclaration
)
30 event_declaration
._event
_class
= event_class
31 return event_declaration
33 class EventDeclaration
:
35 An event declaration contains the properties of a class of events,
36 that is, the common properties and fields layout of all the actual
37 recorded events associated with this declaration.
39 This class is not meant to be instantiated by the user. It is
40 returned by :attr:`TraceHandle.events`.
43 raise NotImplementedError("EventDeclaration cannot be instantiated")
45 def _get_scope_field_type(self
, scope
):
47 ec
= self
._event
_class
48 if scope
is common
.CTFScope
.EVENT_FIELDS
:
49 return ec
.payload_field_type
51 if scope
is common
.CTFScope
.EVENT_CONTEXT
:
52 return ec
.context_field_type
54 if scope
is common
.CTFScope
.STREAM_EVENT_CONTEXT
:
55 return ec
.stream_class
.event_context_field_type
57 if scope
is common
.CTFScope
.STREAM_EVENT_HEADER
:
58 return ec
.stream_class
.event_header_field_type
60 if scope
is common
.CTFScope
.STREAM_PACKET_CONTEXT
:
61 return ec
.stream_class
.packet_context_field_type
63 if scope
is common
.CTFScope
.TRACE_PACKET_HEADER
:
64 return ec
.stream_class
.trace
.packet_header_field_type
68 raise ValueError("Invalid scope provided")
73 Event name, or ``None`` on error.
76 return self
._event
_class
.name
81 Event numeric ID, or -1 on error.
84 return self
._event
_class
.id
89 Generates all the field declarations of this event, going
90 through each scope in the following order:
92 1. Event fields (:attr:`babeltrace.common.CTFScope.EVENT_FIELDS`)
93 2. Event context (:attr:`babeltrace.common.CTFScope.EVENT_CONTEXT`)
94 3. Stream event context (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_CONTEXT`)
95 4. Event header (:attr:`babeltrace.common.CTFScope.STREAM_EVENT_HEADER`)
96 5. Packet context (:attr:`babeltrace.common.CTFScope.STREAM_PACKET_CONTEXT`)
97 6. Packet header (:attr:`babeltrace.common.CTFScope.TRACE_PACKET_HEADER`)
99 All the generated field declarations inherit
100 :class:`FieldDeclaration`, and are among:
102 * :class:`IntegerFieldDeclaration`
103 * :class:`FloatFieldDeclaration`
104 * :class:`EnumerationFieldDeclaration`
105 * :class:`StringFieldDeclaration`
106 * :class:`ArrayFieldDeclaration`
107 * :class:`SequenceFieldDeclaration`
108 * :class:`StructureFieldDeclaration`
109 * :class:`VariantFieldDeclaration`
112 for scope
in _SCOPES
:
113 for declaration
in self
.fields_scope(scope
):
116 def fields_scope(self
, scope
):
118 Generates all the field declarations of the event's scope
121 *scope* must be one of :class:`babeltrace.common.CTFScope` constants.
123 All the generated field declarations inherit
124 :class:`FieldDeclaration`, and are among:
126 * :class:`IntegerFieldDeclaration`
127 * :class:`FloatFieldDeclaration`
128 * :class:`EnumerationFieldDeclaration`
129 * :class:`StringFieldDeclaration`
130 * :class:`ArrayFieldDeclaration`
131 * :class:`SequenceFieldDeclaration`
132 * :class:`StructureFieldDeclaration`
133 * :class:`VariantFieldDeclaration`
136 scope_field_type
= self
._get
_scope
_field
_type
(scope
)
137 for name
, field_type
in scope_field_type
.items():
138 yield field_declaration
._create
_field
_declaration
(field_type
, name
,
141 # Priority of the scopes when searching for event fields
143 common
.CTFScope
.EVENT_FIELDS
,
144 common
.CTFScope
.EVENT_CONTEXT
,
145 common
.CTFScope
.STREAM_EVENT_CONTEXT
,
146 common
.CTFScope
.STREAM_EVENT_HEADER
,
147 common
.CTFScope
.STREAM_PACKET_CONTEXT
,
148 common
.CTFScope
.TRACE_PACKET_HEADER