Commit | Line | Data |
---|---|---|
5ba9f198 | 1 | |
4767a9e7 | 2 | RFC: Common Trace Format (CTF) Proposal (pre-v1.7) |
5ba9f198 MD |
3 | |
4 | Mathieu Desnoyers, EfficiOS Inc. | |
5 | ||
6 | The goal of the present document is to propose a trace format that suits the | |
cc089c3a | 7 | needs of the embedded, telecom, high-performance and kernel communities. It is |
5ba9f198 | 8 | based on the Common Trace Format Requirements (v1.4) document. It is designed to |
cc089c3a | 9 | allow traces to be natively generated by the Linux kernel, Linux user-space |
6c7226e9 MD |
10 | applications written in C/C++, and hardware components. One major element of |
11 | CTF is the Trace Stream Description Language (TSDL) which flexibility | |
12 | enables description of various binary trace stream layouts. | |
cc089c3a MD |
13 | |
14 | The latest version of this document can be found at: | |
15 | ||
16 | git tree: git://git.efficios.com/ctf.git | |
17 | gitweb: http://git.efficios.com/?p=ctf.git | |
5ba9f198 MD |
18 | |
19 | A reference implementation of a library to read and write this trace format is | |
20 | being implemented within the BabelTrace project, a converter between trace | |
21 | formats. The development tree is available at: | |
22 | ||
23 | git tree: git://git.efficios.com/babeltrace.git | |
24 | gitweb: http://git.efficios.com/?p=babeltrace.git | |
25 | ||
26 | ||
27 | 1. Preliminary definitions | |
28 | ||
3bf79539 MD |
29 | - Event Trace: An ordered sequence of events. |
30 | - Event Stream: An ordered sequence of events, containing a subset of the | |
31 | trace event types. | |
32 | - Event Packet: A sequence of physically contiguous events within an event | |
33 | stream. | |
5ba9f198 MD |
34 | - Event: This is the basic entry in a trace. (aka: a trace record). |
35 | - An event identifier (ID) relates to the class (a type) of event within | |
3bf79539 MD |
36 | an event stream. |
37 | e.g. event: irq_entry. | |
5ba9f198 MD |
38 | - An event (or event record) relates to a specific instance of an event |
39 | class. | |
3bf79539 MD |
40 | e.g. event: irq_entry, at time X, on CPU Y |
41 | - Source Architecture: Architecture writing the trace. | |
42 | - Reader Architecture: Architecture reading the trace. | |
5ba9f198 MD |
43 | |
44 | ||
45 | 2. High-level representation of a trace | |
46 | ||
3bf79539 MD |
47 | A trace is divided into multiple event streams. Each event stream contains a |
48 | subset of the trace event types. | |
5ba9f198 | 49 | |
3bf79539 MD |
50 | The final output of the trace, after its generation and optional transport over |
51 | the network, is expected to be either on permanent or temporary storage in a | |
52 | virtual file system. Because each event stream is appended to while a trace is | |
53 | being recorded, each is associated with a separate file for output. Therefore, | |
54 | a stored trace can be represented as a directory containing one file per stream. | |
5ba9f198 | 55 | |
6c7226e9 MD |
56 | A metadata event stream contains information on trace event types |
57 | expressed in the Trace Stream Description Language (TSDL). It describes: | |
5ba9f198 MD |
58 | |
59 | - Trace version. | |
60 | - Types available. | |
3bf79539 MD |
61 | - Per-stream event header description. |
62 | - Per-stream event header selection. | |
63 | - Per-stream event context fields. | |
5ba9f198 | 64 | - Per-event |
3bf79539 | 65 | - Event type to stream mapping. |
5ba9f198 MD |
66 | - Event type to name mapping. |
67 | - Event type to ID mapping. | |
68 | - Event fields description. | |
69 | ||
70 | ||
3bf79539 | 71 | 3. Event stream |
5ba9f198 | 72 | |
3bf79539 | 73 | An event stream is divided in contiguous event packets of variable size. These |
ae8c075a MD |
74 | subdivisions have a variable size. An event packet can contain a certain |
75 | amount of padding at the end. The stream header is repeated at the | |
76 | beginning of each event packet. The rationale for the event stream | |
77 | design choices is explained in Appendix B. Stream Header Rationale. | |
5ba9f198 | 78 | |
3bf79539 MD |
79 | The event stream header will therefore be referred to as the "event packet |
80 | header" throughout the rest of this document. | |
5ba9f198 MD |
81 | |
82 | ||
83 | 4. Types | |
84 | ||
1fad7a85 MD |
85 | Types are organized as type classes. Each type class belong to either of two |
86 | kind of types: basic types or compound types. | |
87 | ||
5ba9f198 MD |
88 | 4.1 Basic types |
89 | ||
1fad7a85 MD |
90 | A basic type is a scalar type, as described in this section. It includes |
91 | integers, GNU/C bitfields, enumerations, and floating point values. | |
5ba9f198 MD |
92 | |
93 | 4.1.1 Type inheritance | |
94 | ||
80fd2569 MD |
95 | Type specifications can be inherited to allow deriving types from a |
96 | type class. For example, see the uint32_t named type derived from the "integer" | |
97 | type class below ("Integers" section). Types have a precise binary | |
98 | representation in the trace. A type class has methods to read and write these | |
99 | types, but must be derived into a type to be usable in an event field. | |
5ba9f198 MD |
100 | |
101 | 4.1.2 Alignment | |
102 | ||
103 | We define "byte-packed" types as aligned on the byte size, namely 8-bit. | |
104 | We define "bit-packed" types as following on the next bit, as defined by the | |
370eae99 | 105 | "Integers" section. |
5ba9f198 | 106 | |
3bf79539 MD |
107 | All basic types, except bitfields, are either aligned on an architecture-defined |
108 | specific alignment or byte-packed, depending on the architecture preference. | |
109 | Architectures providing fast unaligned write byte-packed basic types to save | |
5ba9f198 | 110 | space, aligning each type on byte boundaries (8-bit). Architectures with slow |
3bf79539 | 111 | unaligned writes align types on specific alignment values. If no specific |
370eae99 MD |
112 | alignment is declared for a type, it is assumed to be bit-packed for |
113 | integers with size not multiple of 8 bits and for gcc bitfields. All | |
114 | other types are byte-packed. | |
5ba9f198 | 115 | |
3bf79539 | 116 | Metadata attribute representation of a specific alignment: |
5ba9f198 MD |
117 | |
118 | align = value; /* value in bits */ | |
119 | ||
120 | 4.1.3 Byte order | |
121 | ||
3bf79539 MD |
122 | By default, the native endianness of the source architecture the trace is used. |
123 | Byte order can be overridden for a basic type by specifying a "byte_order" | |
124 | attribute. Typical use-case is to specify the network byte order (big endian: | |
125 | "be") to save data captured from the network into the trace without conversion. | |
126 | If not specified, the byte order is native. | |
5ba9f198 MD |
127 | |
128 | Metadata representation: | |
129 | ||
130 | byte_order = native OR network OR be OR le; /* network and be are aliases */ | |
131 | ||
132 | 4.1.4 Size | |
133 | ||
134 | Type size, in bits, for integers and floats is that returned by "sizeof()" in C | |
135 | multiplied by CHAR_BIT. | |
136 | We require the size of "char" and "unsigned char" types (CHAR_BIT) to be fixed | |
137 | to 8 bits for cross-endianness compatibility. | |
138 | ||
139 | Metadata representation: | |
140 | ||
141 | size = value; (value is in bits) | |
142 | ||
143 | 4.1.5 Integers | |
144 | ||
145 | Signed integers are represented in two-complement. Integer alignment, size, | |
146 | signedness and byte ordering are defined in the metadata. Integers aligned on | |
147 | byte size (8-bit) and with length multiple of byte size (8-bit) correspond to | |
148 | the C99 standard integers. In addition, integers with alignment and/or size that | |
149 | are _not_ a multiple of the byte size are permitted; these correspond to the C99 | |
150 | standard bitfields, with the added specification that the CTF integer bitfields | |
151 | have a fixed binary representation. A MIT-licensed reference implementation of | |
152 | the CTF portable bitfields is available at: | |
153 | ||
154 | http://git.efficios.com/?p=babeltrace.git;a=blob;f=include/babeltrace/bitfield.h | |
155 | ||
156 | Binary representation of integers: | |
157 | ||
158 | - On little and big endian: | |
159 | - Within a byte, high bits correspond to an integer high bits, and low bits | |
160 | correspond to low bits. | |
161 | - On little endian: | |
162 | - Integer across multiple bytes are placed from the less significant to the | |
163 | most significant. | |
164 | - Consecutive integers are placed from lower bits to higher bits (even within | |
165 | a byte). | |
166 | - On big endian: | |
167 | - Integer across multiple bytes are placed from the most significant to the | |
168 | less significant. | |
169 | - Consecutive integers are placed from higher bits to lower bits (even within | |
170 | a byte). | |
171 | ||
172 | This binary representation is derived from the bitfield implementation in GCC | |
173 | for little and big endian. However, contrary to what GCC does, integers can | |
174 | cross units boundaries (no padding is required). Padding can be explicitely | |
175 | added (see 4.1.6 GNU/C bitfields) to follow the GCC layout if needed. | |
176 | ||
177 | Metadata representation: | |
178 | ||
80fd2569 | 179 | integer { |
5ba9f198 MD |
180 | signed = true OR false; /* default false */ |
181 | byte_order = native OR network OR be OR le; /* default native */ | |
182 | size = value; /* value in bits, no default */ | |
183 | align = value; /* value in bits */ | |
2152348f | 184 | } |
5ba9f198 | 185 | |
80fd2569 | 186 | Example of type inheritance (creation of a uint32_t named type): |
5ba9f198 | 187 | |
359894ac | 188 | typealias integer { |
9e4e34e9 | 189 | size = 32; |
5ba9f198 MD |
190 | signed = false; |
191 | align = 32; | |
38b8da21 | 192 | } := uint32_t; |
5ba9f198 | 193 | |
80fd2569 | 194 | Definition of a named 5-bit signed bitfield: |
5ba9f198 | 195 | |
359894ac | 196 | typealias integer { |
5ba9f198 MD |
197 | size = 5; |
198 | signed = true; | |
199 | align = 1; | |
38b8da21 | 200 | } := int5_t; |
5ba9f198 MD |
201 | |
202 | 4.1.6 GNU/C bitfields | |
203 | ||
204 | The GNU/C bitfields follow closely the integer representation, with a | |
205 | particularity on alignment: if a bitfield cannot fit in the current unit, the | |
80fd2569 MD |
206 | unit is padded and the bitfield starts at the following unit. The unit size is |
207 | defined by the size of the type "unit_type". | |
5ba9f198 | 208 | |
2152348f | 209 | Metadata representation: |
80fd2569 MD |
210 | |
211 | unit_type name:size: | |
212 | ||
5ba9f198 MD |
213 | As an example, the following structure declared in C compiled by GCC: |
214 | ||
215 | struct example { | |
216 | short a:12; | |
217 | short b:5; | |
218 | }; | |
219 | ||
2152348f MD |
220 | The example structure is aligned on the largest element (short). The second |
221 | bitfield would be aligned on the next unit boundary, because it would not fit in | |
222 | the current unit. | |
5ba9f198 MD |
223 | |
224 | 4.1.7 Floating point | |
225 | ||
226 | The floating point values byte ordering is defined in the metadata. | |
227 | ||
228 | Floating point values follow the IEEE 754-2008 standard interchange formats. | |
229 | Description of the floating point values include the exponent and mantissa size | |
230 | in bits. Some requirements are imposed on the floating point values: | |
231 | ||
232 | - FLT_RADIX must be 2. | |
233 | - mant_dig is the number of digits represented in the mantissa. It is specified | |
234 | by the ISO C99 standard, section 5.2.4, as FLT_MANT_DIG, DBL_MANT_DIG and | |
235 | LDBL_MANT_DIG as defined by <float.h>. | |
236 | - exp_dig is the number of digits represented in the exponent. Given that | |
237 | mant_dig is one bit more than its actual size in bits (leading 1 is not | |
238 | needed) and also given that the sign bit always takes one bit, exp_dig can be | |
239 | specified as: | |
240 | ||
241 | - sizeof(float) * CHAR_BIT - FLT_MANT_DIG | |
242 | - sizeof(double) * CHAR_BIT - DBL_MANT_DIG | |
243 | - sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG | |
244 | ||
245 | Metadata representation: | |
246 | ||
80fd2569 | 247 | floating_point { |
5ba9f198 MD |
248 | exp_dig = value; |
249 | mant_dig = value; | |
250 | byte_order = native OR network OR be OR le; | |
2152348f | 251 | } |
5ba9f198 MD |
252 | |
253 | Example of type inheritance: | |
254 | ||
359894ac | 255 | typealias floating_point { |
5ba9f198 MD |
256 | exp_dig = 8; /* sizeof(float) * CHAR_BIT - FLT_MANT_DIG */ |
257 | mant_dig = 24; /* FLT_MANT_DIG */ | |
258 | byte_order = native; | |
38b8da21 | 259 | } := float; |
5ba9f198 MD |
260 | |
261 | TODO: define NaN, +inf, -inf behavior. | |
262 | ||
263 | 4.1.8 Enumerations | |
264 | ||
265 | Enumerations are a mapping between an integer type and a table of strings. The | |
266 | numerical representation of the enumeration follows the integer type specified | |
267 | by the metadata. The enumeration mapping table is detailed in the enumeration | |
3bf79539 MD |
268 | description within the metadata. The mapping table maps inclusive value ranges |
269 | (or single values) to strings. Instead of being limited to simple | |
270 | "value -> string" mappings, these enumerations map | |
80fd2569 | 271 | "[ start_value ... end_value ] -> string", which map inclusive ranges of |
3bf79539 MD |
272 | values to strings. An enumeration from the C language can be represented in |
273 | this format by having the same start_value and end_value for each element, which | |
274 | is in fact a range of size 1. This single-value range is supported without | |
4767a9e7 | 275 | repeating the start and end values with the value = string declaration. |
80fd2569 | 276 | |
a9b83695 | 277 | enum name : integer_type { |
359894ac | 278 | somestring = start_value1 ... end_value1, |
80fd2569 MD |
279 | "other string" = start_value2 ... end_value2, |
280 | yet_another_string, /* will be assigned to end_value2 + 1 */ | |
281 | "some other string" = value, | |
282 | ... | |
283 | }; | |
284 | ||
285 | If the values are omitted, the enumeration starts at 0 and increment of 1 for | |
286 | each entry: | |
287 | ||
a9b83695 | 288 | enum name : unsigned int { |
80fd2569 MD |
289 | ZERO, |
290 | ONE, | |
291 | TWO, | |
292 | TEN = 10, | |
293 | ELEVEN, | |
3bf79539 | 294 | }; |
5ba9f198 | 295 | |
80fd2569 | 296 | Overlapping ranges within a single enumeration are implementation defined. |
5ba9f198 | 297 | |
2152348f MD |
298 | A nameless enumeration can be declared as a field type or as part of a typedef: |
299 | ||
a9b83695 | 300 | enum : integer_type { |
2152348f MD |
301 | ... |
302 | } | |
303 | ||
c2742c56 MD |
304 | Enumerations omitting the container type ": integer_type" use the "int" |
305 | type (for compatibility with C99). The "int" type must be previously | |
306 | declared. E.g.: | |
307 | ||
308 | typealias integer { size = 32; align = 32; signed = true } := int; | |
309 | ||
310 | enum { | |
311 | ... | |
312 | } | |
313 | ||
1fad7a85 | 314 | |
5ba9f198 MD |
315 | 4.2 Compound types |
316 | ||
1fad7a85 MD |
317 | Compound are aggregation of type declarations. Compound types include |
318 | structures, variant, arrays, sequences, and strings. | |
319 | ||
5ba9f198 MD |
320 | 4.2.1 Structures |
321 | ||
322 | Structures are aligned on the largest alignment required by basic types | |
323 | contained within the structure. (This follows the ISO/C standard for structures) | |
324 | ||
80fd2569 | 325 | Metadata representation of a named structure: |
5ba9f198 | 326 | |
80fd2569 MD |
327 | struct name { |
328 | field_type field_name; | |
329 | field_type field_name; | |
330 | ... | |
331 | }; | |
5ba9f198 MD |
332 | |
333 | Example: | |
334 | ||
80fd2569 MD |
335 | struct example { |
336 | integer { /* Nameless type */ | |
337 | size = 16; | |
338 | signed = true; | |
339 | align = 16; | |
340 | } first_field_name; | |
341 | uint64_t second_field_name; /* Named type declared in the metadata */ | |
3bf79539 | 342 | }; |
5ba9f198 MD |
343 | |
344 | The fields are placed in a sequence next to each other. They each possess a | |
345 | field name, which is a unique identifier within the structure. | |
346 | ||
2152348f | 347 | A nameless structure can be declared as a field type or as part of a typedef: |
80fd2569 MD |
348 | |
349 | struct { | |
350 | ... | |
2152348f | 351 | } |
80fd2569 | 352 | |
77a98c82 | 353 | 4.2.2 Variants (Discriminated/Tagged Unions) |
fcba70d4 | 354 | |
fdf2bb05 MD |
355 | A CTF variant is a selection between different types. A CTF variant must |
356 | always be defined within the scope of a structure or within fields | |
357 | contained within a structure (defined recursively). A "tag" enumeration | |
358 | field must appear in either the same lexical scope, prior to the variant | |
359 | field (in field declaration order), in an uppermost lexical scope (see | |
6c7226e9 | 360 | Section 7.3.1), or in an uppermost dynamic scope (see Section 7.3.2). |
fdf2bb05 MD |
361 | The type selection is indicated by the mapping from the enumeration |
362 | value to the string used as variant type selector. The field to use as | |
363 | tag is specified by the "tag_field", specified between "< >" after the | |
364 | "variant" keyword for unnamed variants, and after "variant name" for | |
365 | named variants. | |
fcba70d4 MD |
366 | |
367 | The alignment of the variant is the alignment of the type as selected by the tag | |
368 | value for the specific instance of the variant. The alignment of the type | |
369 | containing the variant is independent of the variant alignment. The size of the | |
370 | variant is the size as selected by the tag value for the specific instance of | |
371 | the variant. | |
372 | ||
373 | A named variant declaration followed by its definition within a structure | |
374 | declaration: | |
375 | ||
376 | variant name { | |
377 | field_type sel1; | |
378 | field_type sel2; | |
379 | field_type sel3; | |
380 | ... | |
381 | }; | |
382 | ||
383 | struct { | |
a9b83695 | 384 | enum : integer_type { sel1, sel2, sel3, ... } tag_field; |
fcba70d4 MD |
385 | ... |
386 | variant name <tag_field> v; | |
387 | } | |
388 | ||
389 | An unnamed variant definition within a structure is expressed by the following | |
390 | metadata: | |
391 | ||
392 | struct { | |
a9b83695 | 393 | enum : integer_type { sel1, sel2, sel3, ... } tag_field; |
fcba70d4 MD |
394 | ... |
395 | variant <tag_field> { | |
396 | field_type sel1; | |
397 | field_type sel2; | |
398 | field_type sel3; | |
399 | ... | |
400 | } v; | |
401 | } | |
402 | ||
403 | Example of a named variant within a sequence that refers to a single tag field: | |
404 | ||
405 | variant example { | |
406 | uint32_t a; | |
407 | uint64_t b; | |
408 | short c; | |
409 | }; | |
410 | ||
411 | struct { | |
a9b83695 | 412 | enum : uint2_t { a, b, c } choice; |
15850440 | 413 | variant example <choice> v[unsigned int]; |
fcba70d4 MD |
414 | } |
415 | ||
416 | Example of an unnamed variant: | |
417 | ||
418 | struct { | |
a9b83695 | 419 | enum : uint2_t { a, b, c, d } choice; |
fcba70d4 MD |
420 | /* Unrelated fields can be added between the variant and its tag */ |
421 | int32_t somevalue; | |
422 | variant <choice> { | |
423 | uint32_t a; | |
424 | uint64_t b; | |
425 | short c; | |
426 | struct { | |
427 | unsigned int field1; | |
428 | uint64_t field2; | |
429 | } d; | |
430 | } s; | |
431 | } | |
432 | ||
433 | Example of an unnamed variant within an array: | |
434 | ||
435 | struct { | |
a9b83695 | 436 | enum : uint2_t { a, b, c } choice; |
fcba70d4 MD |
437 | variant <choice> { |
438 | uint32_t a; | |
439 | uint64_t b; | |
440 | short c; | |
15850440 | 441 | } v[10]; |
fcba70d4 MD |
442 | } |
443 | ||
444 | Example of a variant type definition within a structure, where the defined type | |
445 | is then declared within an array of structures. This variant refers to a tag | |
446 | located in an upper lexical scope. This example clearly shows that a variant | |
447 | type definition referring to the tag "x" uses the closest preceding field from | |
448 | the lexical scope of the type definition. | |
449 | ||
450 | struct { | |
a9b83695 | 451 | enum : uint2_t { a, b, c, d } x; |
fcba70d4 MD |
452 | |
453 | typedef variant <x> { /* | |
454 | * "x" refers to the preceding "x" enumeration in the | |
455 | * lexical scope of the type definition. | |
456 | */ | |
457 | uint32_t a; | |
458 | uint64_t b; | |
459 | short c; | |
460 | } example_variant; | |
461 | ||
462 | struct { | |
a9b83695 | 463 | enum : int { x, y, z } x; /* This enumeration is not used by "v". */ |
fcba70d4 | 464 | example_variant v; /* |
a9b83695 | 465 | * "v" uses the "enum : uint2_t { a, b, c, d }" |
fcba70d4 MD |
466 | * tag. |
467 | */ | |
468 | } a[10]; | |
469 | } | |
470 | ||
471 | 4.2.3 Arrays | |
5ba9f198 MD |
472 | |
473 | Arrays are fixed-length. Their length is declared in the type declaration within | |
474 | the metadata. They contain an array of "inner type" elements, which can refer to | |
475 | any type not containing the type of the array being declared (no circular | |
3bf79539 | 476 | dependency). The length is the number of elements in an array. |
5ba9f198 | 477 | |
2152348f | 478 | Metadata representation of a named array: |
80fd2569 MD |
479 | |
480 | typedef elem_type name[length]; | |
5ba9f198 | 481 | |
2152348f | 482 | A nameless array can be declared as a field type within a structure, e.g.: |
5ba9f198 | 483 | |
2152348f | 484 | uint8_t field_name[10]; |
80fd2569 | 485 | |
5ba9f198 | 486 | |
fcba70d4 | 487 | 4.2.4 Sequences |
5ba9f198 MD |
488 | |
489 | Sequences are dynamically-sized arrays. They start with an integer that specify | |
490 | the length of the sequence, followed by an array of "inner type" elements. | |
3bf79539 | 491 | The length is the number of elements in the sequence. |
5ba9f198 | 492 | |
2152348f | 493 | Metadata representation for a named sequence: |
80fd2569 MD |
494 | |
495 | typedef elem_type name[length_type]; | |
496 | ||
497 | A nameless sequence can be declared as a field type, e.g.: | |
498 | ||
80fd2569 MD |
499 | long field_name[int]; |
500 | ||
501 | The length type follows the integer types specifications, and the sequence | |
5ba9f198 MD |
502 | elements follow the "array" specifications. |
503 | ||
fcba70d4 | 504 | 4.2.5 Strings |
5ba9f198 MD |
505 | |
506 | Strings are an array of bytes of variable size and are terminated by a '\0' | |
507 | "NULL" character. Their encoding is described in the metadata. In absence of | |
508 | encoding attribute information, the default encoding is UTF-8. | |
509 | ||
80fd2569 MD |
510 | Metadata representation of a named string type: |
511 | ||
359894ac | 512 | typealias string { |
5ba9f198 | 513 | encoding = UTF8 OR ASCII; |
38b8da21 | 514 | } := name; |
5ba9f198 | 515 | |
80fd2569 MD |
516 | A nameless string type can be declared as a field type: |
517 | ||
518 | string field_name; /* Use default UTF8 encoding */ | |
5ba9f198 | 519 | |
3bf79539 MD |
520 | 5. Event Packet Header |
521 | ||
522 | The event packet header consists of two part: one is mandatory and have a fixed | |
523 | layout. The second part, the "event packet context", has its layout described in | |
524 | the metadata. | |
5ba9f198 | 525 | |
3bf79539 MD |
526 | - Aligned on page size. Fixed size. Fields either aligned or packed (depending |
527 | on the architecture preference). | |
528 | No padding at the end of the event packet header. Native architecture byte | |
5ba9f198 | 529 | ordering. |
3bf79539 MD |
530 | |
531 | Fixed layout (event packet header): | |
532 | ||
5ba9f198 MD |
533 | - Magic number (CTF magic numbers: 0xC1FC1FC1 and its reverse endianness |
534 | representation: 0xC11FFCC1) It needs to have a non-symmetric bytewise | |
535 | representation. Used to distinguish between big and little endian traces (this | |
536 | information is determined by knowing the endianness of the architecture | |
537 | reading the trace and comparing the magic number against its value and the | |
538 | reverse, 0xC11FFCC1). This magic number specifies that we use the CTF metadata | |
539 | description language described in this document. Different magic numbers | |
540 | should be used for other metadata description languages. | |
3bf79539 | 541 | - Trace UUID, used to ensure the event packet match the metadata used. |
5ba9f198 MD |
542 | (note: we cannot use a metadata checksum because metadata can be appended to |
543 | while tracing is active) | |
3bf79539 MD |
544 | - Stream ID, used as reference to stream description in metadata. |
545 | ||
546 | Metadata-defined layout (event packet context): | |
547 | ||
548 | - Event packet content size (in bytes). | |
549 | - Event packet size (in bytes, includes padding). | |
550 | - Event packet content checksum (optional). Checksum excludes the event packet | |
551 | header. | |
552 | - Per-stream event packet sequence count (to deal with UDP packet loss). The | |
553 | number of significant sequence counter bits should also be present, so | |
554 | wrap-arounds are deal with correctly. | |
555 | - Timestamp at the beginning and timestamp at the end of the event packet. | |
556 | Both timestamps are written in the packet header, but sampled respectively | |
557 | while (or before) writing the first event and while (or after) writing the | |
558 | last event in the packet. The inclusive range between these timestamps should | |
559 | include all event timestamps assigned to events contained within the packet. | |
5ba9f198 | 560 | - Events discarded count |
3bf79539 MD |
561 | - Snapshot of a per-stream free-running counter, counting the number of |
562 | events discarded that were supposed to be written in the stream prior to | |
563 | the first event in the event packet. | |
5ba9f198 | 564 | * Note: producer-consumer buffer full condition should fill the current |
3bf79539 | 565 | event packet with padding so we know exactly where events have been |
5ba9f198 | 566 | discarded. |
3bf79539 MD |
567 | - Lossless compression scheme used for the event packet content. Applied |
568 | directly to raw data. New types of compression can be added in following | |
569 | versions of the format. | |
5ba9f198 MD |
570 | 0: no compression scheme |
571 | 1: bzip2 | |
572 | 2: gzip | |
3bf79539 MD |
573 | 3: xz |
574 | - Cypher used for the event packet content. Applied after compression. | |
5ba9f198 MD |
575 | 0: no encryption |
576 | 1: AES | |
3bf79539 | 577 | - Checksum scheme used for the event packet content. Applied after encryption. |
5ba9f198 MD |
578 | 0: no checksum |
579 | 1: md5 | |
580 | 2: sha1 | |
581 | 3: crc32 | |
582 | ||
3bf79539 MD |
583 | 5.1 Event Packet Header Fixed Layout Description |
584 | ||
fc5425db MD |
585 | The event packet header layout is indicated by the trace packet.header |
586 | field. Here is an example structure type for the packet header with the | |
587 | fields typically expected: | |
588 | ||
80fd2569 MD |
589 | struct event_packet_header { |
590 | uint32_t magic; | |
591 | uint8_t trace_uuid[16]; | |
3bf79539 | 592 | uint32_t stream_id; |
80fd2569 | 593 | }; |
5ba9f198 | 594 | |
fc5425db MD |
595 | trace { |
596 | ... | |
597 | packet.header := struct event_packet_header; | |
598 | }; | |
599 | ||
3bf79539 MD |
600 | 5.2 Event Packet Context Description |
601 | ||
602 | Event packet context example. These are declared within the stream declaration | |
603 | in the metadata. All these fields are optional except for "content_size" and | |
604 | "packet_size", which must be present in the context. | |
605 | ||
606 | An example event packet context type: | |
607 | ||
80fd2569 | 608 | struct event_packet_context { |
3bf79539 MD |
609 | uint64_t timestamp_begin; |
610 | uint64_t timestamp_end; | |
611 | uint32_t checksum; | |
612 | uint32_t stream_packet_count; | |
613 | uint32_t events_discarded; | |
614 | uint32_t cpu_id; | |
615 | uint32_t/uint16_t content_size; | |
616 | uint32_t/uint16_t packet_size; | |
617 | uint8_t stream_packet_count_bits; /* Significant counter bits */ | |
618 | uint8_t compression_scheme; | |
619 | uint8_t encryption_scheme; | |
3b0f8e4d | 620 | uint8_t checksum_scheme; |
3bf79539 | 621 | }; |
5ba9f198 | 622 | |
fcba70d4 | 623 | |
5ba9f198 MD |
624 | 6. Event Structure |
625 | ||
626 | The overall structure of an event is: | |
627 | ||
fcba70d4 | 628 | 1 - Stream Packet Context (as specified by the stream metadata) |
fdf2bb05 MD |
629 | 2 - Event Header (as specified by the stream metadata) |
630 | 3 - Stream Event Context (as specified by the stream metadata) | |
631 | 4 - Event Context (as specified by the event metadata) | |
632 | 5 - Event Payload (as specified by the event metadata) | |
5ba9f198 | 633 | |
fdf2bb05 | 634 | This structure defines an implicit dynamic scoping, where variants |
7d9d7e92 MD |
635 | located in inner structures (those with a higher number in the listing |
636 | above) can refer to the fields of outer structures (with lower number in | |
6c7226e9 | 637 | the listing above). See Section 7.3 TSDL Scopes for more detail. |
5ba9f198 | 638 | |
fdf2bb05 | 639 | 6.1 Event Header |
fcba70d4 MD |
640 | |
641 | Event headers can be described within the metadata. We hereby propose, as an | |
642 | example, two types of events headers. Type 1 accommodates streams with less than | |
643 | 31 event IDs. Type 2 accommodates streams with 31 or more event IDs. | |
5ba9f198 | 644 | |
3bf79539 MD |
645 | One major factor can vary between streams: the number of event IDs assigned to |
646 | a stream. Luckily, this information tends to stay relatively constant (modulo | |
5ba9f198 | 647 | event registration while trace is being recorded), so we can specify different |
3bf79539 | 648 | representations for streams containing few event IDs and streams containing |
5ba9f198 MD |
649 | many event IDs, so we end up representing the event ID and timestamp as densely |
650 | as possible in each case. | |
651 | ||
fcba70d4 MD |
652 | The header is extended in the rare occasions where the information cannot be |
653 | represented in the ranges available in the standard event header. They are also | |
3bf79539 MD |
654 | used in the rare occasions where the data required for a field could not be |
655 | collected: the flag corresponding to the missing field within the missing_fields | |
656 | array is then set to 1. | |
5ba9f198 MD |
657 | |
658 | Types uintX_t represent an X-bit unsigned integer. | |
659 | ||
660 | ||
fdf2bb05 | 661 | 6.1.1 Type 1 - Few event IDs |
5ba9f198 MD |
662 | |
663 | - Aligned on 32-bit (or 8-bit if byte-packed, depending on the architecture | |
664 | preference). | |
5ba9f198 | 665 | - Native architecture byte ordering. |
fcba70d4 MD |
666 | - For "compact" selection |
667 | - Fixed size: 32 bits. | |
668 | - For "extended" selection | |
669 | - Size depends on the architecture and variant alignment. | |
5ba9f198 | 670 | |
80fd2569 | 671 | struct event_header_1 { |
fcba70d4 MD |
672 | /* |
673 | * id: range: 0 - 30. | |
674 | * id 31 is reserved to indicate an extended header. | |
675 | */ | |
a9b83695 | 676 | enum : uint5_t { compact = 0 ... 30, extended = 31 } id; |
fcba70d4 MD |
677 | variant <id> { |
678 | struct { | |
679 | uint27_t timestamp; | |
680 | } compact; | |
681 | struct { | |
682 | uint32_t id; /* 32-bit event IDs */ | |
683 | uint64_t timestamp; /* 64-bit timestamps */ | |
684 | } extended; | |
685 | } v; | |
5ba9f198 MD |
686 | }; |
687 | ||
5ba9f198 | 688 | |
fdf2bb05 | 689 | 6.1.2 Type 2 - Many event IDs |
5ba9f198 | 690 | |
fcba70d4 | 691 | - Aligned on 16-bit (or 8-bit if byte-packed, depending on the architecture |
5ba9f198 | 692 | preference). |
5ba9f198 | 693 | - Native architecture byte ordering. |
fcba70d4 MD |
694 | - For "compact" selection |
695 | - Size depends on the architecture and variant alignment. | |
696 | - For "extended" selection | |
697 | - Size depends on the architecture and variant alignment. | |
5ba9f198 | 698 | |
80fd2569 | 699 | struct event_header_2 { |
fcba70d4 MD |
700 | /* |
701 | * id: range: 0 - 65534. | |
702 | * id 65535 is reserved to indicate an extended header. | |
703 | */ | |
a9b83695 | 704 | enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id; |
fcba70d4 MD |
705 | variant <id> { |
706 | struct { | |
707 | uint32_t timestamp; | |
708 | } compact; | |
709 | struct { | |
710 | uint32_t id; /* 32-bit event IDs */ | |
711 | uint64_t timestamp; /* 64-bit timestamps */ | |
712 | } extended; | |
713 | } v; | |
5ba9f198 MD |
714 | }; |
715 | ||
5ba9f198 MD |
716 | |
717 | 6.2 Event Context | |
718 | ||
719 | The event context contains information relative to the current event. The choice | |
fcba70d4 MD |
720 | and meaning of this information is specified by the metadata "stream" and |
721 | "event" information. The "stream" context is applied to all events within the | |
722 | stream. The "stream" context structure follows the event header. The "event" | |
723 | context is applied to specific events. Its structure follows the "stream" | |
724 | context stucture. | |
5ba9f198 | 725 | |
fcba70d4 MD |
726 | An example of stream-level event context is to save the event payload size with |
727 | each event, or to save the current PID with each event. These are declared | |
728 | within the stream declaration within the metadata: | |
5ba9f198 | 729 | |
fcba70d4 MD |
730 | stream { |
731 | ... | |
732 | event { | |
733 | ... | |
4fa992a5 | 734 | context := struct { |
80fd2569 MD |
735 | uint pid; |
736 | uint16_t payload_size; | |
3bf79539 | 737 | }; |
fcba70d4 MD |
738 | } |
739 | }; | |
740 | ||
741 | An example of event-specific event context is to declare a bitmap of missing | |
742 | fields, only appended after the stream event context if the extended event | |
743 | header is selected. NR_FIELDS is the number of fields within the event (a | |
744 | numeric value). | |
5ba9f198 | 745 | |
fcba70d4 MD |
746 | event { |
747 | context = struct { | |
748 | variant <id> { | |
749 | struct { } compact; | |
750 | struct { | |
751 | uint1_t missing_fields[NR_FIELDS]; /* missing event fields bitmap */ | |
752 | } extended; | |
753 | } v; | |
754 | }; | |
755 | ... | |
756 | } | |
5ba9f198 MD |
757 | |
758 | 6.3 Event Payload | |
759 | ||
760 | An event payload contains fields specific to a given event type. The fields | |
761 | belonging to an event type are described in the event-specific metadata | |
762 | within a structure type. | |
763 | ||
764 | 6.3.1 Padding | |
765 | ||
766 | No padding at the end of the event payload. This differs from the ISO/C standard | |
767 | for structures, but follows the CTF standard for structures. In a trace, even | |
768 | though it makes sense to align the beginning of a structure, it really makes no | |
769 | sense to add padding at the end of the structure, because structures are usually | |
770 | not followed by a structure of the same type. | |
771 | ||
772 | This trick can be done by adding a zero-length "end" field at the end of the C | |
773 | structures, and by using the offset of this field rather than using sizeof() | |
3bf79539 | 774 | when calculating the size of a structure (see Appendix "A. Helper macros"). |
5ba9f198 MD |
775 | |
776 | 6.3.2 Alignment | |
777 | ||
778 | The event payload is aligned on the largest alignment required by types | |
779 | contained within the payload. (This follows the ISO/C standard for structures) | |
780 | ||
781 | ||
6c7226e9 MD |
782 | 7. Trace Stream Description Language (TSDL) |
783 | ||
784 | The Trace Stream Description Language (TSDL) allows expression of the | |
785 | binary trace streams layout in a C99-like Domain Specific Language | |
786 | (DSL). | |
787 | ||
788 | ||
789 | 7.1 Metadata | |
790 | ||
791 | The trace stream layout description is located in the trace meta-data. | |
792 | The meta-data is itself located in a stream identified by its name: | |
793 | "metadata". | |
5ba9f198 | 794 | |
4fafe1ad MD |
795 | It is made of "event packets", which each start with an event packet |
796 | header. The event type within the metadata stream have no event header | |
6c7226e9 MD |
797 | nor event context. Each event only contains a "string" payload without |
798 | any null-character. The events are packed one next to another. Each | |
799 | event packet start with an event packet header, which contains, amongst | |
800 | other fields, the magic number, trace UUID and packet length. In the | |
801 | event packet header, the trace UUID is represented as an array of bytes. | |
802 | Within the string-based metadata description, the trace UUID is | |
803 | represented as a string of hexadecimal digits and dashes "-". | |
4fafe1ad | 804 | |
6c7226e9 MD |
805 | The metadata can be parsed by reading characters within the metadata |
806 | stream, for each packet starting after the packet header, for the length | |
807 | of the packet payload specified in the header. Text contained within | |
808 | "/*" and "*/", as well as within "//" and end of line, are treated as | |
809 | comments. Boolean values can be represented as true, TRUE, or 1 for | |
810 | true, and false, FALSE, or 0 for false. | |
fcba70d4 | 811 | |
fdf2bb05 | 812 | |
6c7226e9 | 813 | 7.2 Declaration vs Definition |
fdf2bb05 MD |
814 | |
815 | A declaration associates a layout to a type, without specifying where | |
816 | this type is located in the event structure hierarchy (see Section 6). | |
817 | This therefore includes typedef, typealias, as well as all type | |
818 | specifiers. In certain circumstances (typedef, structure field and | |
819 | variant field), a declaration is followed by a declarator, which specify | |
820 | the newly defined type name (for typedef), or the field name (for | |
821 | declarations located within structure and variants). Array and sequence, | |
822 | declared with square brackets ("[" "]"), are part of the declarator, | |
a9b83695 | 823 | similarly to C99. The enumeration base type is specified by |
6c7226e9 | 824 | ": enum_base", which is part of the type specifier. The variant tag |
a9b83695 | 825 | name, specified between "<" ">", is also part of the type specifier. |
fdf2bb05 MD |
826 | |
827 | A definition associates a type to a location in the event structure | |
b9606a77 MD |
828 | hierarchy (see Section 6). This association is denoted by ":=", as shown |
829 | in Section 7.3. | |
fdf2bb05 MD |
830 | |
831 | ||
6c7226e9 | 832 | 7.3 TSDL Scopes |
fdf2bb05 | 833 | |
6c7226e9 MD |
834 | TSDL uses two different types of scoping: a lexical scope is used for |
835 | declarations and type definitions, and a dynamic scope is used for | |
836 | variants references to tag fields. | |
fdf2bb05 | 837 | |
6c7226e9 | 838 | 7.3.1 Lexical Scope |
fdf2bb05 | 839 | |
d285084f MD |
840 | Each of "trace", "stream", "event", "struct" and "variant" have their own |
841 | nestable declaration scope, within which types can be declared using "typedef" | |
fdf2bb05 | 842 | and "typealias". A root declaration scope also contains all declarations |
7d9d7e92 | 843 | located outside of any of the aforementioned declarations. An inner |
fdf2bb05 | 844 | declaration scope can refer to type declared within its container |
7d9d7e92 MD |
845 | lexical scope prior to the inner declaration scope. Redefinition of a |
846 | typedef or typealias is not valid, although hiding an upper scope | |
fdf2bb05 MD |
847 | typedef or typealias is allowed within a sub-scope. |
848 | ||
6c7226e9 | 849 | 7.3.2 Dynamic Scope |
fdf2bb05 | 850 | |
7d9d7e92 MD |
851 | A dynamic scope consists in the lexical scope augmented with the |
852 | implicit event structure definition hierarchy presented at Section 6. | |
853 | The dynamic scope is only used for variant tag definitions. It is used | |
854 | at definition time to look up the location of the tag field associated | |
855 | with a variant. | |
856 | ||
857 | Therefore, variants in lower levels in the dynamic scope (e.g. event | |
858 | context) can refer to a tag field located in upper levels (e.g. in the | |
859 | event header) by specifying, in this case, the associated tag with | |
860 | <header.field_name>. This allows, for instance, the event context to | |
861 | define a variant referring to the "id" field of the event header as | |
862 | selector. | |
fdf2bb05 MD |
863 | |
864 | The target dynamic scope must be specified explicitly when referring to | |
865 | a field outside of the local static scope. The dynamic scope prefixes | |
866 | are thus: | |
867 | ||
7d9d7e92 MD |
868 | - Stream Packet Context: <stream.packet.context. >, |
869 | - Event Header: <stream.event.header. >, | |
870 | - Stream Event Context: <stream.event.context. >, | |
871 | - Event Context: <event.context. >, | |
872 | - Event Payload: <event.fields. >. | |
fdf2bb05 MD |
873 | |
874 | Multiple declarations of the same field name within a single scope is | |
875 | not valid. It is however valid to re-use the same field name in | |
876 | different scopes. There is no possible conflict, because the dynamic | |
877 | scope must be specified when a variant refers to a tag field located in | |
878 | a different dynamic scope. | |
879 | ||
457d8b0a MD |
880 | The information available in the dynamic scopes can be thought of as the |
881 | current tracing context. At trace production, information about the | |
882 | current context is saved into the specified scope field levels. At trace | |
883 | consumption, for each event, the current trace context is therefore | |
884 | readable by accessing the upper dynamic scopes. | |
885 | ||
fdf2bb05 | 886 | |
6c7226e9 | 887 | 7.4 TSDL Examples |
d285084f | 888 | |
6c7226e9 MD |
889 | The grammar representing the TSDL metadata is presented in Appendix C. |
890 | TSDL Grammar. This section presents a rather ligher reading that | |
891 | consists in examples of TSDL metadata, with template values: | |
5ba9f198 MD |
892 | |
893 | trace { | |
fdf2bb05 | 894 | major = value; /* Trace format version */ |
5ba9f198 | 895 | minor = value; |
fdf2bb05 | 896 | uuid = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; /* Trace UUID */ |
fc5425db MD |
897 | packet.header := struct { |
898 | uint32_t magic; | |
899 | uint8_t trace_uuid[16]; | |
900 | uint32_t stream_id; | |
901 | }; | |
3bf79539 | 902 | }; |
5ba9f198 | 903 | |
3bf79539 MD |
904 | stream { |
905 | id = stream_id; | |
fdf2bb05 | 906 | /* Type 1 - Few event IDs; Type 2 - Many event IDs. See section 6.1. */ |
4fa992a5 MD |
907 | event.header := event_header_1 OR event_header_2; |
908 | event.context := struct { | |
77a98c82 | 909 | ... |
3bf79539 | 910 | }; |
4fa992a5 | 911 | packet.context := struct { |
77a98c82 | 912 | ... |
3bf79539 MD |
913 | }; |
914 | }; | |
5ba9f198 MD |
915 | |
916 | event { | |
3d13ef1a | 917 | name = event_name; |
3bf79539 MD |
918 | id = value; /* Numeric identifier within the stream */ |
919 | stream = stream_id; | |
4fa992a5 | 920 | context := struct { |
fcba70d4 MD |
921 | ... |
922 | }; | |
4fa992a5 | 923 | fields := struct { |
80fd2569 MD |
924 | ... |
925 | }; | |
3bf79539 | 926 | }; |
5ba9f198 MD |
927 | |
928 | /* More detail on types in section 4. Types */ | |
929 | ||
3d13ef1a MD |
930 | /* |
931 | * Named types: | |
932 | * | |
4fa992a5 | 933 | * Type declarations behave similarly to the C standard. |
3d13ef1a MD |
934 | */ |
935 | ||
80af8ac6 | 936 | typedef aliased_type_specifiers new_type_declarators; |
2152348f | 937 | |
3d13ef1a | 938 | /* e.g.: typedef struct example new_type_name[10]; */ |
80fd2569 | 939 | |
4fa992a5 MD |
940 | /* |
941 | * typealias | |
942 | * | |
943 | * The "typealias" declaration can be used to give a name (including | |
80af8ac6 MD |
944 | * pointer declarator specifier) to a type. It should also be used to |
945 | * map basic C types (float, int, unsigned long, ...) to a CTF type. | |
946 | * Typealias is a superset of "typedef": it also allows assignment of a | |
38b8da21 | 947 | * simple variable identifier to a type. |
4fa992a5 MD |
948 | */ |
949 | ||
950 | typealias type_class { | |
80fd2569 | 951 | ... |
38b8da21 | 952 | } := type_specifiers type_declarator; |
2152348f | 953 | |
3d13ef1a MD |
954 | /* |
955 | * e.g.: | |
4fa992a5 | 956 | * typealias integer { |
3d13ef1a MD |
957 | * size = 32; |
958 | * align = 32; | |
959 | * signed = false; | |
38b8da21 | 960 | * } := struct page *; |
359894ac MD |
961 | * |
962 | * typealias integer { | |
963 | * size = 32; | |
964 | * align = 32; | |
965 | * signed = true; | |
38b8da21 | 966 | * } := int; |
3d13ef1a | 967 | */ |
80fd2569 MD |
968 | |
969 | struct name { | |
3bf79539 MD |
970 | ... |
971 | }; | |
5ba9f198 | 972 | |
fcba70d4 MD |
973 | variant name { |
974 | ... | |
975 | }; | |
976 | ||
a9b83695 | 977 | enum name : integer_type { |
3bf79539 MD |
978 | ... |
979 | }; | |
980 | ||
2152348f | 981 | |
4fa992a5 MD |
982 | /* |
983 | * Unnamed types, contained within compound type fields, typedef or typealias. | |
984 | */ | |
2152348f | 985 | |
80fd2569 MD |
986 | struct { |
987 | ... | |
2152348f | 988 | } |
5ba9f198 | 989 | |
fcba70d4 MD |
990 | variant { |
991 | ... | |
992 | } | |
993 | ||
a9b83695 | 994 | enum : integer_type { |
80fd2569 | 995 | ... |
2152348f MD |
996 | } |
997 | ||
998 | typedef type new_type[length]; | |
3bf79539 | 999 | |
2152348f MD |
1000 | struct { |
1001 | type field_name[length]; | |
1002 | } | |
1003 | ||
1004 | typedef type new_type[length_type]; | |
1005 | ||
1006 | struct { | |
1007 | type field_name[length_type]; | |
1008 | } | |
1009 | ||
1010 | integer { | |
80fd2569 | 1011 | ... |
2152348f | 1012 | } |
3bf79539 | 1013 | |
2152348f | 1014 | floating_point { |
80fd2569 | 1015 | ... |
2152348f MD |
1016 | } |
1017 | ||
1018 | struct { | |
1019 | integer_type field_name:size; /* GNU/C bitfield */ | |
1020 | } | |
1021 | ||
1022 | struct { | |
1023 | string field_name; | |
1024 | } | |
3bf79539 | 1025 | |
fcba70d4 | 1026 | |
3bf79539 | 1027 | A. Helper macros |
5ba9f198 MD |
1028 | |
1029 | The two following macros keep track of the size of a GNU/C structure without | |
1030 | padding at the end by placing HEADER_END as the last field. A one byte end field | |
1031 | is used for C90 compatibility (C99 flexible arrays could be used here). Note | |
1032 | that this does not affect the effective structure size, which should always be | |
1033 | calculated with the header_sizeof() helper. | |
1034 | ||
1035 | #define HEADER_END char end_field | |
1036 | #define header_sizeof(type) offsetof(typeof(type), end_field) | |
3bf79539 MD |
1037 | |
1038 | ||
1039 | B. Stream Header Rationale | |
1040 | ||
1041 | An event stream is divided in contiguous event packets of variable size. These | |
1042 | subdivisions allow the trace analyzer to perform a fast binary search by time | |
1043 | within the stream (typically requiring to index only the event packet headers) | |
1044 | without reading the whole stream. These subdivisions have a variable size to | |
1045 | eliminate the need to transfer the event packet padding when partially filled | |
1046 | event packets must be sent when streaming a trace for live viewing/analysis. | |
1047 | An event packet can contain a certain amount of padding at the end. Dividing | |
1048 | streams into event packets is also useful for network streaming over UDP and | |
1049 | flight recorder mode tracing (a whole event packet can be swapped out of the | |
1050 | buffer atomically for reading). | |
1051 | ||
1052 | The stream header is repeated at the beginning of each event packet to allow | |
1053 | flexibility in terms of: | |
1054 | ||
1055 | - streaming support, | |
1056 | - allowing arbitrary buffers to be discarded without making the trace | |
1057 | unreadable, | |
1058 | - allow UDP packet loss handling by either dealing with missing event packet | |
1059 | or asking for re-transmission. | |
1060 | - transparently support flight recorder mode, | |
1061 | - transparently support crash dump. | |
1062 | ||
1063 | The event stream header will therefore be referred to as the "event packet | |
1064 | header" throughout the rest of this document. | |
fcba70d4 | 1065 | |
6c7226e9 MD |
1066 | |
1067 | C. TSDL Grammar | |
fcba70d4 | 1068 | |
4fa992a5 | 1069 | /* |
6c7226e9 | 1070 | * Common Trace Format (CTF) Trace Stream Description Language (TSDL) Grammar. |
4fa992a5 MD |
1071 | * |
1072 | * Inspired from the C99 grammar: | |
1073 | * http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf (Annex A) | |
6c7226e9 MD |
1074 | * and c++1x grammar (draft) |
1075 | * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3291.pdf (Annex A) | |
4fa992a5 MD |
1076 | * |
1077 | * Specialized for CTF needs by including only constant and declarations from | |
1078 | * C99 (excluding function declarations), and by adding support for variants, | |
6c7226e9 MD |
1079 | * sequences and CTF-specific specifiers. Enumeration container types |
1080 | * semantic is inspired from c++1x enum-base. | |
4fa992a5 MD |
1081 | */ |
1082 | ||
1083 | 1) Lexical grammar | |
1084 | ||
1085 | 1.1) Lexical elements | |
1086 | ||
1087 | token: | |
1088 | keyword | |
1089 | identifier | |
1090 | constant | |
1091 | string-literal | |
1092 | punctuator | |
1093 | ||
1094 | 1.2) Keywords | |
1095 | ||
1096 | keyword: is one of | |
1097 | ||
1098 | const | |
1099 | char | |
1100 | double | |
1101 | enum | |
1102 | event | |
1103 | floating_point | |
1104 | float | |
1105 | integer | |
1106 | int | |
1107 | long | |
1108 | short | |
1109 | signed | |
1110 | stream | |
1111 | string | |
1112 | struct | |
1113 | trace | |
3e1e1a78 | 1114 | typealias |
4fa992a5 MD |
1115 | typedef |
1116 | unsigned | |
1117 | variant | |
1118 | void | |
1119 | _Bool | |
1120 | _Complex | |
1121 | _Imaginary | |
1122 | ||
1123 | ||
1124 | 1.3) Identifiers | |
1125 | ||
1126 | identifier: | |
1127 | identifier-nondigit | |
1128 | identifier identifier-nondigit | |
1129 | identifier digit | |
1130 | ||
1131 | identifier-nondigit: | |
1132 | nondigit | |
1133 | universal-character-name | |
1134 | any other implementation-defined characters | |
1135 | ||
1136 | nondigit: | |
1137 | _ | |
1138 | [a-zA-Z] /* regular expression */ | |
1139 | ||
1140 | digit: | |
1141 | [0-9] /* regular expression */ | |
1142 | ||
1143 | 1.4) Universal character names | |
1144 | ||
1145 | universal-character-name: | |
1146 | \u hex-quad | |
1147 | \U hex-quad hex-quad | |
1148 | ||
1149 | hex-quad: | |
1150 | hexadecimal-digit hexadecimal-digit hexadecimal-digit hexadecimal-digit | |
1151 | ||
1152 | 1.5) Constants | |
1153 | ||
1154 | constant: | |
1155 | integer-constant | |
1156 | enumeration-constant | |
1157 | character-constant | |
1158 | ||
1159 | integer-constant: | |
1160 | decimal-constant integer-suffix-opt | |
1161 | octal-constant integer-suffix-opt | |
1162 | hexadecimal-constant integer-suffix-opt | |
1163 | ||
1164 | decimal-constant: | |
1165 | nonzero-digit | |
1166 | decimal-constant digit | |
1167 | ||
1168 | octal-constant: | |
1169 | 0 | |
1170 | octal-constant octal-digit | |
1171 | ||
1172 | hexadecimal-constant: | |
1173 | hexadecimal-prefix hexadecimal-digit | |
1174 | hexadecimal-constant hexadecimal-digit | |
1175 | ||
1176 | hexadecimal-prefix: | |
1177 | 0x | |
1178 | 0X | |
1179 | ||
1180 | nonzero-digit: | |
1181 | [1-9] | |
1182 | ||
1183 | integer-suffix: | |
1184 | unsigned-suffix long-suffix-opt | |
1185 | unsigned-suffix long-long-suffix | |
1186 | long-suffix unsigned-suffix-opt | |
1187 | long-long-suffix unsigned-suffix-opt | |
1188 | ||
1189 | unsigned-suffix: | |
1190 | u | |
1191 | U | |
1192 | ||
1193 | long-suffix: | |
1194 | l | |
1195 | L | |
1196 | ||
1197 | long-long-suffix: | |
1198 | ll | |
1199 | LL | |
1200 | ||
1201 | digit-sequence: | |
1202 | digit | |
1203 | digit-sequence digit | |
1204 | ||
1205 | hexadecimal-digit-sequence: | |
1206 | hexadecimal-digit | |
1207 | hexadecimal-digit-sequence hexadecimal-digit | |
1208 | ||
1209 | enumeration-constant: | |
1210 | identifier | |
1211 | string-literal | |
1212 | ||
1213 | character-constant: | |
1214 | ' c-char-sequence ' | |
1215 | L' c-char-sequence ' | |
1216 | ||
1217 | c-char-sequence: | |
1218 | c-char | |
1219 | c-char-sequence c-char | |
1220 | ||
1221 | c-char: | |
1222 | any member of source charset except single-quote ('), backslash | |
1223 | (\), or new-line character. | |
1224 | escape-sequence | |
1225 | ||
1226 | escape-sequence: | |
1227 | simple-escape-sequence | |
1228 | octal-escape-sequence | |
1229 | hexadecimal-escape-sequence | |
1230 | universal-character-name | |
1231 | ||
1232 | simple-escape-sequence: one of | |
1233 | \' \" \? \\ \a \b \f \n \r \t \v | |
1234 | ||
1235 | octal-escape-sequence: | |
1236 | \ octal-digit | |
1237 | \ octal-digit octal-digit | |
1238 | \ octal-digit octal-digit octal-digit | |
1239 | ||
1240 | hexadecimal-escape-sequence: | |
1241 | \x hexadecimal-digit | |
1242 | hexadecimal-escape-sequence hexadecimal-digit | |
1243 | ||
1244 | 1.6) String literals | |
1245 | ||
1246 | string-literal: | |
1247 | " s-char-sequence-opt " | |
1248 | L" s-char-sequence-opt " | |
1249 | ||
1250 | s-char-sequence: | |
1251 | s-char | |
1252 | s-char-sequence s-char | |
1253 | ||
1254 | s-char: | |
1255 | any member of source charset except double-quote ("), backslash | |
1256 | (\), or new-line character. | |
1257 | escape-sequence | |
1258 | ||
1259 | 1.7) Punctuators | |
1260 | ||
1261 | punctuator: one of | |
1262 | [ ] ( ) { } . -> * + - < > : ; ... = , | |
1263 | ||
1264 | ||
1265 | 2) Phrase structure grammar | |
1266 | ||
1267 | primary-expression: | |
1268 | identifier | |
1269 | constant | |
1270 | string-literal | |
1271 | ( unary-expression ) | |
1272 | ||
1273 | postfix-expression: | |
1274 | primary-expression | |
1275 | postfix-expression [ unary-expression ] | |
1276 | postfix-expression . identifier | |
1277 | postfix-expressoin -> identifier | |
1278 | ||
1279 | unary-expression: | |
1280 | postfix-expression | |
1281 | unary-operator postfix-expression | |
1282 | ||
1283 | unary-operator: one of | |
1284 | + - | |
1285 | ||
4fa992a5 MD |
1286 | assignment-operator: |
1287 | = | |
1288 | ||
b9606a77 MD |
1289 | type-assignment-operator: |
1290 | := | |
1291 | ||
4fa992a5 MD |
1292 | constant-expression: |
1293 | unary-expression | |
1294 | ||
1295 | constant-expression-range: | |
1296 | constant-expression ... constant-expression | |
1297 | ||
1298 | 2.2) Declarations: | |
1299 | ||
1300 | declaration: | |
689e04b4 | 1301 | declaration-specifiers declarator-list-opt ; |
4fa992a5 MD |
1302 | ctf-specifier ; |
1303 | ||
1304 | declaration-specifiers: | |
689e04b4 | 1305 | storage-class-specifier declaration-specifiers-opt |
4fa992a5 MD |
1306 | type-specifier declaration-specifiers-opt |
1307 | type-qualifier declaration-specifiers-opt | |
1308 | ||
1309 | declarator-list: | |
1310 | declarator | |
1311 | declarator-list , declarator | |
1312 | ||
d285084f MD |
1313 | abstract-declarator-list: |
1314 | abstract-declarator | |
1315 | abstract-declarator-list , abstract-declarator | |
1316 | ||
4fa992a5 MD |
1317 | storage-class-specifier: |
1318 | typedef | |
1319 | ||
1320 | type-specifier: | |
1321 | void | |
1322 | char | |
1323 | short | |
1324 | int | |
1325 | long | |
1326 | float | |
1327 | double | |
1328 | signed | |
1329 | unsigned | |
1330 | _Bool | |
1331 | _Complex | |
cfdd51ec | 1332 | _Imaginary |
9dfcfc0f MD |
1333 | struct-specifier |
1334 | variant-specifier | |
4fa992a5 MD |
1335 | enum-specifier |
1336 | typedef-name | |
1337 | ctf-type-specifier | |
1338 | ||
1339 | struct-specifier: | |
3b0f8e4d | 1340 | struct identifier-opt { struct-or-variant-declaration-list-opt } |
4fa992a5 MD |
1341 | struct identifier |
1342 | ||
1343 | struct-or-variant-declaration-list: | |
1344 | struct-or-variant-declaration | |
1345 | struct-or-variant-declaration-list struct-or-variant-declaration | |
1346 | ||
1347 | struct-or-variant-declaration: | |
1348 | specifier-qualifier-list struct-or-variant-declarator-list ; | |
550aca33 | 1349 | declaration-specifiers storage-class-specifier declaration-specifiers declarator-list ; |
38b8da21 MD |
1350 | typealias declaration-specifiers abstract-declarator-list := declaration-specifiers abstract-declarator-list ; |
1351 | typealias declaration-specifiers abstract-declarator-list := declarator-list ; | |
4fa992a5 MD |
1352 | |
1353 | specifier-qualifier-list: | |
1354 | type-specifier specifier-qualifier-list-opt | |
1355 | type-qualifier specifier-qualifier-list-opt | |
1356 | ||
1357 | struct-or-variant-declarator-list: | |
1358 | struct-or-variant-declarator | |
1359 | struct-or-variant-declarator-list , struct-or-variant-declarator | |
1360 | ||
1361 | struct-or-variant-declarator: | |
1362 | declarator | |
1363 | declarator-opt : constant-expression | |
1364 | ||
1365 | variant-specifier: | |
1366 | variant identifier-opt variant-tag-opt { struct-or-variant-declaration-list } | |
1367 | variant identifier variant-tag | |
1368 | ||
1369 | variant-tag: | |
1370 | < identifier > | |
1371 | ||
1372 | enum-specifier: | |
1373 | enum identifier-opt { enumerator-list } | |
1374 | enum identifier-opt { enumerator-list , } | |
1375 | enum identifier | |
a9b83695 MD |
1376 | enum identifier-opt : declaration-specifiers { enumerator-list } |
1377 | enum identifier-opt : declaration-specifiers { enumerator-list , } | |
4fa992a5 MD |
1378 | |
1379 | enumerator-list: | |
1380 | enumerator | |
1381 | enumerator-list , enumerator | |
1382 | ||
1383 | enumerator: | |
1384 | enumeration-constant | |
1385 | enumeration-constant = constant-expression | |
1386 | enumeration-constant = constant-expression-range | |
1387 | ||
1388 | type-qualifier: | |
1389 | const | |
1390 | ||
1391 | declarator: | |
1392 | pointer-opt direct-declarator | |
1393 | ||
1394 | direct-declarator: | |
1395 | identifier | |
1396 | ( declarator ) | |
1397 | direct-declarator [ type-specifier ] | |
1398 | direct-declarator [ constant-expression ] | |
1399 | ||
d285084f MD |
1400 | abstract-declarator: |
1401 | pointer-opt direct-abstract-declarator | |
1402 | ||
1403 | direct-abstract-declarator: | |
1404 | identifier-opt | |
1405 | ( abstract-declarator ) | |
1406 | direct-abstract-declarator [ type-specifier ] | |
1407 | direct-abstract-declarator [ constant-expression ] | |
1408 | direct-abstract-declarator [ ] | |
1409 | ||
4fa992a5 | 1410 | pointer: |
3b0f8e4d MD |
1411 | * type-qualifier-list-opt |
1412 | * type-qualifier-list-opt pointer | |
4fa992a5 MD |
1413 | |
1414 | type-qualifier-list: | |
1415 | type-qualifier | |
1416 | type-qualifier-list type-qualifier | |
1417 | ||
4fa992a5 MD |
1418 | typedef-name: |
1419 | identifier | |
1420 | ||
1421 | 2.3) CTF-specific declarations | |
1422 | ||
1423 | ctf-specifier: | |
1424 | event { ctf-assignment-expression-list-opt } | |
1425 | stream { ctf-assignment-expression-list-opt } | |
1426 | trace { ctf-assignment-expression-list-opt } | |
38b8da21 MD |
1427 | typealias declaration-specifiers abstract-declarator-list := declaration-specifiers abstract-declarator-list ; |
1428 | typealias declaration-specifiers abstract-declarator-list := declarator-list ; | |
4fa992a5 MD |
1429 | |
1430 | ctf-type-specifier: | |
1431 | floating_point { ctf-assignment-expression-list-opt } | |
1432 | integer { ctf-assignment-expression-list-opt } | |
1433 | string { ctf-assignment-expression-list-opt } | |
1434 | ||
1435 | ctf-assignment-expression-list: | |
1436 | ctf-assignment-expression | |
1437 | ctf-assignment-expression-list ; ctf-assignment-expression | |
1438 | ||
1439 | ctf-assignment-expression: | |
1440 | unary-expression assignment-operator unary-expression | |
1441 | unary-expression type-assignment-operator type-specifier | |
550aca33 | 1442 | declaration-specifiers storage-class-specifier declaration-specifiers declarator-list |
38b8da21 MD |
1443 | typealias declaration-specifiers abstract-declarator-list := declaration-specifiers abstract-declarator-list |
1444 | typealias declaration-specifiers abstract-declarator-list := declarator-list |