| 1 | # common.py |
| 2 | # |
| 3 | # Babeltrace Python module common definitions |
| 4 | # |
| 5 | # Copyright 2012-2015 EfficiOS Inc. |
| 6 | # |
| 7 | # Author: Danny Serres <danny.serres@efficios.com> |
| 8 | # Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 9 | # |
| 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | # of this software and associated documentation files (the "Software"), to deal |
| 12 | # in the Software without restriction, including without limitation the rights |
| 13 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | # copies of the Software, and to permit persons to whom the Software is |
| 15 | # furnished to do so, subject to the following conditions: |
| 16 | # |
| 17 | # The above copyright notice and this permission notice shall be included in |
| 18 | # all copies or substantial portions of the Software. |
| 19 | # |
| 20 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | # SOFTWARE. |
| 27 | |
| 28 | class CTFStringEncoding: |
| 29 | """ |
| 30 | CTF string encodings. |
| 31 | """ |
| 32 | |
| 33 | #: None |
| 34 | NONE = 0 |
| 35 | |
| 36 | #: UTF-8 |
| 37 | UTF8 = 1 |
| 38 | |
| 39 | #: ASCII |
| 40 | ASCII = 2 |
| 41 | |
| 42 | #: Unknown |
| 43 | UNKNOWN = 3 |
| 44 | |
| 45 | |
| 46 | # Based on the enum in ctf-writer/writer.h |
| 47 | class ByteOrder: |
| 48 | """ |
| 49 | Byte orders. |
| 50 | """ |
| 51 | |
| 52 | #: Native byte order |
| 53 | BYTE_ORDER_NATIVE = 0 |
| 54 | |
| 55 | #: Little-endian |
| 56 | BYTE_ORDER_LITTLE_ENDIAN = 1 |
| 57 | |
| 58 | #: Big-endian |
| 59 | BYTE_ORDER_BIG_ENDIAN = 2 |
| 60 | |
| 61 | #: Network byte order (big-endian) |
| 62 | BYTE_ORDER_NETWORK = 3 |
| 63 | |
| 64 | #: Unknown byte order |
| 65 | BYTE_ORDER_UNKNOWN = 4 # Python-specific entry |
| 66 | |
| 67 | |
| 68 | # enum equivalent, accessible constants |
| 69 | # These are taken directly from ctf/events.h |
| 70 | # All changes to enums must also be made here |
| 71 | class CTFTypeId: |
| 72 | """ |
| 73 | CTF numeric type identifiers. |
| 74 | """ |
| 75 | |
| 76 | #: Unknown type |
| 77 | UNKNOWN = 0 |
| 78 | |
| 79 | #: Integer |
| 80 | INTEGER = 1 |
| 81 | |
| 82 | #: Floating point number |
| 83 | FLOAT = 2 |
| 84 | |
| 85 | #: Enumeration |
| 86 | ENUM = 3 |
| 87 | |
| 88 | #: String |
| 89 | STRING = 4 |
| 90 | |
| 91 | #: Structure |
| 92 | STRUCT = 5 |
| 93 | |
| 94 | #: Untagged variant |
| 95 | UNTAGGED_VARIANT = 6 |
| 96 | |
| 97 | #: Variant |
| 98 | VARIANT = 7 |
| 99 | |
| 100 | #: Array |
| 101 | ARRAY = 8 |
| 102 | |
| 103 | #: Sequence |
| 104 | SEQUENCE = 9 |
| 105 | |
| 106 | NR_CTF_TYPES = 10 |
| 107 | |
| 108 | def type_name(id): |
| 109 | """ |
| 110 | Returns the name of the CTF numeric type identifier *id*. |
| 111 | """ |
| 112 | |
| 113 | name = "UNKNOWN_TYPE" |
| 114 | constants = [ |
| 115 | attr for attr in dir(CTFTypeId) if not callable( |
| 116 | getattr( |
| 117 | CTFTypeId, |
| 118 | attr)) and not attr.startswith("__")] |
| 119 | |
| 120 | for attr in constants: |
| 121 | if getattr(CTFTypeId, attr) == id: |
| 122 | name = attr |
| 123 | break |
| 124 | |
| 125 | return name |
| 126 | |
| 127 | |
| 128 | class CTFScope: |
| 129 | """ |
| 130 | CTF scopes. |
| 131 | """ |
| 132 | |
| 133 | #: Packet header |
| 134 | TRACE_PACKET_HEADER = 0 |
| 135 | |
| 136 | #: Packet context |
| 137 | STREAM_PACKET_CONTEXT = 1 |
| 138 | |
| 139 | #: Event header |
| 140 | STREAM_EVENT_HEADER = 2 |
| 141 | |
| 142 | #: Stream event context |
| 143 | STREAM_EVENT_CONTEXT = 3 |
| 144 | |
| 145 | #: Event context |
| 146 | EVENT_CONTEXT = 4 |
| 147 | |
| 148 | #: Event fields |
| 149 | EVENT_FIELDS = 5 |
| 150 | |
| 151 | def scope_name(scope): |
| 152 | """ |
| 153 | Returns the name of the CTF scope *scope*. |
| 154 | """ |
| 155 | |
| 156 | name = "UNKNOWN_SCOPE" |
| 157 | constants = [ |
| 158 | attr for attr in dir(CTFScope) if not callable( |
| 159 | getattr( |
| 160 | CTFScope, |
| 161 | attr)) and not attr.startswith("__")] |
| 162 | |
| 163 | for attr in constants: |
| 164 | if getattr(CTFScope, attr) == scope: |
| 165 | name = attr |
| 166 | break |
| 167 | |
| 168 | return name |