2 RFC: Common Trace Format (CTF) Proposal (pre-v1.7)
4 Mathieu Desnoyers, EfficiOS Inc.
6 The goal of the present document is to propose a trace format that suits the
7 needs of the embedded, telecom, high-performance and kernel communities. It is
8 based on the Common Trace Format Requirements (v1.4) document. It is designed to
9 allow traces to be natively generated by the Linux kernel, Linux user-space
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.
14 The latest version of this document can be found at:
16 git tree: git://git.efficios.com/ctf.git
17 gitweb: http://git.efficios.com/?p=ctf.git
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:
23 git tree: git://git.efficios.com/babeltrace.git
24 gitweb: http://git.efficios.com/?p=babeltrace.git
27 1. Preliminary definitions
29 - Event Trace: An ordered sequence of events.
30 - Event Stream: An ordered sequence of events, containing a subset of the
32 - Event Packet: A sequence of physically contiguous events within an event
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
37 e.g. event: irq_entry.
38 - An event (or event record) relates to a specific instance of an event
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.
45 2. High-level representation of a trace
47 A trace is divided into multiple event streams. Each event stream contains a
48 subset of the trace event types.
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.
56 A metadata event stream contains information on trace event types
57 expressed in the Trace Stream Description Language (TSDL). It describes:
61 - Per-stream event header description.
62 - Per-stream event header selection.
63 - Per-stream event context fields.
65 - Event type to stream mapping.
66 - Event type to name mapping.
67 - Event type to ID mapping.
68 - Event fields description.
73 An event stream is divided in contiguous event packets of variable size. These
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.
79 The event stream header will therefore be referred to as the "event packet
80 header" throughout the rest of this document.
85 Types are organized as type classes. Each type class belong to either of two
86 kind of types: basic types or compound types.
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.
93 4.1.1 Type inheritance
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.
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
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
110 space, aligning each type on byte boundaries (8-bit). Architectures with slow
111 unaligned writes align types on specific alignment values. If no specific
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.
116 Metadata attribute representation of a specific alignment:
118 align = value; /* value in bits */
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.
128 Metadata representation:
130 byte_order = native OR network OR be OR le; /* network and be are aliases */
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.
139 Metadata representation:
141 size = value; (value is in bits)
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:
154 http://git.efficios.com/?p=babeltrace.git;a=blob;f=include/babeltrace/bitfield.h
156 Binary representation of integers:
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.
162 - Integer across multiple bytes are placed from the less significant to the
164 - Consecutive integers are placed from lower bits to higher bits (even within
167 - Integer across multiple bytes are placed from the most significant to the
169 - Consecutive integers are placed from higher bits to lower bits (even within
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.
177 Metadata representation:
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 */
186 Example of type inheritance (creation of a uint32_t named type):
194 Definition of a named 5-bit signed bitfield:
202 4.1.6 GNU/C bitfields
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
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".
209 Metadata representation:
213 As an example, the following structure declared in C compiled by GCC:
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
226 The floating point values byte ordering is defined in the metadata.
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:
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
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
245 Metadata representation:
250 byte_order = native OR network OR be OR le;
253 Example of type inheritance:
255 typealias floating_point {
256 exp_dig = 8; /* sizeof(float) * CHAR_BIT - FLT_MANT_DIG */
257 mant_dig = 24; /* FLT_MANT_DIG */
261 TODO: define NaN, +inf, -inf behavior.
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
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
271 "[ start_value ... end_value ] -> string", which map inclusive ranges of
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
275 repeating the start and end values with the value = string declaration.
277 enum name : integer_type {
278 somestring = start_value1 ... end_value1,
279 "other string" = start_value2 ... end_value2,
280 yet_another_string, /* will be assigned to end_value2 + 1 */
281 "some other string" = value,
285 If the values are omitted, the enumeration starts at 0 and increment of 1 for
288 enum name : unsigned int {
296 Overlapping ranges within a single enumeration are implementation defined.
298 A nameless enumeration can be declared as a field type or as part of a typedef:
300 enum : integer_type {
304 Enumerations omitting the container type ": integer_type" use the "int"
305 type (for compatibility with C99). The "int" type must be previously
308 typealias integer { size = 32; align = 32; signed = true } := int;
317 Compound are aggregation of type declarations. Compound types include
318 structures, variant, arrays, sequences, and strings.
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)
325 Metadata representation of a named structure:
328 field_type field_name;
329 field_type field_name;
336 integer { /* Nameless type */
341 uint64_t second_field_name; /* Named type declared in the metadata */
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.
347 A nameless structure can be declared as a field type or as part of a typedef:
353 4.2.2 Variants (Discriminated/Tagged Unions)
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
360 Section 7.3.1), or in an uppermost dynamic scope (see Section 7.3.2).
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
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
373 A named variant declaration followed by its definition within a structure
384 enum : integer_type { sel1, sel2, sel3, ... } tag_field;
386 variant name <tag_field> v;
389 An unnamed variant definition within a structure is expressed by the following
393 enum : integer_type { sel1, sel2, sel3, ... } tag_field;
395 variant <tag_field> {
403 Example of a named variant within a sequence that refers to a single tag field:
412 enum : uint2_t { a, b, c } choice;
413 variant example <choice> v[unsigned int];
416 Example of an unnamed variant:
419 enum : uint2_t { a, b, c, d } choice;
420 /* Unrelated fields can be added between the variant and its tag */
433 Example of an unnamed variant within an array:
436 enum : uint2_t { a, b, c } choice;
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.
451 enum : uint2_t { a, b, c, d } x;
453 typedef variant <x> { /*
454 * "x" refers to the preceding "x" enumeration in the
455 * lexical scope of the type definition.
463 enum : int { x, y, z } x; /* This enumeration is not used by "v". */
464 example_variant v; /*
465 * "v" uses the "enum : uint2_t { a, b, c, d }"
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
476 dependency). The length is the number of elements in an array.
478 Metadata representation of a named array:
480 typedef elem_type name[length];
482 A nameless array can be declared as a field type within a structure, e.g.:
484 uint8_t field_name[10];
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.
491 The length is the number of elements in the sequence.
493 Metadata representation for a named sequence:
495 typedef elem_type name[length_type];
497 A nameless sequence can be declared as a field type, e.g.:
499 long field_name[int];
501 The length type follows the integer types specifications, and the sequence
502 elements follow the "array" specifications.
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.
510 Metadata representation of a named string type:
513 encoding = UTF8 OR ASCII;
516 A nameless string type can be declared as a field type:
518 string field_name; /* Use default UTF8 encoding */
520 5. Event Packet Header
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
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
531 Fixed layout (event packet header):
533 - Magic number (CTF magic number: 0xC1FC1FC1 This magic number specifies
534 that we use the CTF metadata description language described in this
535 document. Different magic numbers should be used for other metadata
536 description languages.
537 - Trace UUID, used to ensure the event packet match the metadata used.
538 (note: we cannot use a metadata checksum because metadata can be appended to
539 while tracing is active)
540 - Stream ID, used as reference to stream description in metadata.
542 Metadata-defined layout (event packet context):
544 - Event packet content size (in bytes).
545 - Event packet size (in bytes, includes padding).
546 - Event packet content checksum (optional). Checksum excludes the event packet
548 - Per-stream event packet sequence count (to deal with UDP packet loss). The
549 number of significant sequence counter bits should also be present, so
550 wrap-arounds are dealt with correctly.
551 - Timestamp at the beginning and timestamp at the end of the event packet.
552 Both timestamps are written in the packet header, but sampled respectively
553 while (or before) writing the first event and while (or after) writing the
554 last event in the packet. The inclusive range between these timestamps should
555 include all event timestamps assigned to events contained within the packet.
556 - Events discarded count
557 - Snapshot of a per-stream free-running counter, counting the number of
558 events discarded that were supposed to be written in the stream prior to
559 the first event in the event packet.
560 * Note: producer-consumer buffer full condition should fill the current
561 event packet with padding so we know exactly where events have been
563 - Lossless compression scheme used for the event packet content. Applied
564 directly to raw data. New types of compression can be added in following
565 versions of the format.
566 0: no compression scheme
570 - Cypher used for the event packet content. Applied after compression.
573 - Checksum scheme used for the event packet content. Applied after encryption.
579 5.1 Event Packet Header Fixed Layout Description
581 The event packet header layout is indicated by the trace packet.header
582 field. Here is an example structure type for the packet header with the
583 fields typically expected:
585 struct event_packet_header {
587 uint8_t trace_uuid[16];
593 packet.header := struct event_packet_header;
596 If the trace_uuid is not present, no validation that the metadata
597 actually corresponds to the stream is performed.
599 If the stream_id packet header field is missing, the trace can only
600 contain a single stream. Its "id" field can be left out, and its events
601 don't need to declare a "stream_id" field.
604 5.2 Event Packet Context Description
606 Event packet context example. These are declared within the stream declaration
607 in the metadata. All these fields are optional. If the packet size field is
608 missing, the whole stream only contains a single packet. If the content
609 size field is missing, the packet is filled (no padding). The content
610 and packet sizes include all headers.
612 An example event packet context type:
614 struct event_packet_context {
615 uint64_t timestamp_begin;
616 uint64_t timestamp_end;
618 uint32_t stream_packet_count;
619 uint32_t events_discarded;
621 uint32_t/uint16_t content_size;
622 uint32_t/uint16_t packet_size;
623 uint8_t stream_packet_count_bits; /* Significant counter bits */
624 uint8_t compression_scheme;
625 uint8_t encryption_scheme;
626 uint8_t checksum_scheme;
632 The overall structure of an event is:
634 1 - Stream Packet Context (as specified by the stream metadata)
635 2 - Event Header (as specified by the stream metadata)
636 3 - Stream Event Context (as specified by the stream metadata)
637 4 - Event Context (as specified by the event metadata)
638 5 - Event Payload (as specified by the event metadata)
640 This structure defines an implicit dynamic scoping, where variants
641 located in inner structures (those with a higher number in the listing
642 above) can refer to the fields of outer structures (with lower number in
643 the listing above). See Section 7.3 TSDL Scopes for more detail.
647 Event headers can be described within the metadata. We hereby propose, as an
648 example, two types of events headers. Type 1 accommodates streams with less than
649 31 event IDs. Type 2 accommodates streams with 31 or more event IDs.
651 One major factor can vary between streams: the number of event IDs assigned to
652 a stream. Luckily, this information tends to stay relatively constant (modulo
653 event registration while trace is being recorded), so we can specify different
654 representations for streams containing few event IDs and streams containing
655 many event IDs, so we end up representing the event ID and timestamp as densely
656 as possible in each case.
658 The header is extended in the rare occasions where the information cannot be
659 represented in the ranges available in the standard event header. They are also
660 used in the rare occasions where the data required for a field could not be
661 collected: the flag corresponding to the missing field within the missing_fields
662 array is then set to 1.
664 Types uintX_t represent an X-bit unsigned integer.
667 6.1.1 Type 1 - Few event IDs
669 - Aligned on 32-bit (or 8-bit if byte-packed, depending on the architecture
671 - Native architecture byte ordering.
672 - For "compact" selection
673 - Fixed size: 32 bits.
674 - For "extended" selection
675 - Size depends on the architecture and variant alignment.
677 struct event_header_1 {
680 * id 31 is reserved to indicate an extended header.
682 enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
688 uint32_t id; /* 32-bit event IDs */
689 uint64_t timestamp; /* 64-bit timestamps */
695 6.1.2 Type 2 - Many event IDs
697 - Aligned on 16-bit (or 8-bit if byte-packed, depending on the architecture
699 - Native architecture byte ordering.
700 - For "compact" selection
701 - Size depends on the architecture and variant alignment.
702 - For "extended" selection
703 - Size depends on the architecture and variant alignment.
705 struct event_header_2 {
707 * id: range: 0 - 65534.
708 * id 65535 is reserved to indicate an extended header.
710 enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;
716 uint32_t id; /* 32-bit event IDs */
717 uint64_t timestamp; /* 64-bit timestamps */
725 The event context contains information relative to the current event. The choice
726 and meaning of this information is specified by the metadata "stream" and
727 "event" information. The "stream" context is applied to all events within the
728 stream. The "stream" context structure follows the event header. The "event"
729 context is applied to specific events. Its structure follows the "stream"
732 An example of stream-level event context is to save the event payload size with
733 each event, or to save the current PID with each event. These are declared
734 within the stream declaration within the metadata:
742 uint16_t payload_size;
747 An example of event-specific event context is to declare a bitmap of missing
748 fields, only appended after the stream event context if the extended event
749 header is selected. NR_FIELDS is the number of fields within the event (a
757 uint1_t missing_fields[NR_FIELDS]; /* missing event fields bitmap */
766 An event payload contains fields specific to a given event type. The fields
767 belonging to an event type are described in the event-specific metadata
768 within a structure type.
772 No padding at the end of the event payload. This differs from the ISO/C standard
773 for structures, but follows the CTF standard for structures. In a trace, even
774 though it makes sense to align the beginning of a structure, it really makes no
775 sense to add padding at the end of the structure, because structures are usually
776 not followed by a structure of the same type.
778 This trick can be done by adding a zero-length "end" field at the end of the C
779 structures, and by using the offset of this field rather than using sizeof()
780 when calculating the size of a structure (see Appendix "A. Helper macros").
784 The event payload is aligned on the largest alignment required by types
785 contained within the payload. (This follows the ISO/C standard for structures)
788 7. Trace Stream Description Language (TSDL)
790 The Trace Stream Description Language (TSDL) allows expression of the
791 binary trace streams layout in a C99-like Domain Specific Language
797 The trace stream layout description is located in the trace meta-data.
798 The meta-data is itself located in a stream identified by its name:
801 It is made of "event packets", which each start with an event packet
802 header. The event type within the metadata stream have no event header
803 nor event context. Each event only contains a "string" payload without
804 any null-character. The events are packed one next to another. Each
805 event packet start with an event packet header, which contains, amongst
806 other fields, the magic number, trace UUID and packet length. In the
807 event packet header, the trace UUID is represented as an array of bytes.
808 Within the string-based metadata description, the trace UUID is
809 represented as a string of hexadecimal digits and dashes "-".
811 The metadata can be parsed by reading characters within the metadata
812 stream, for each packet starting after the packet header, for the length
813 of the packet payload specified in the header. Text contained within
814 "/*" and "*/", as well as within "//" and end of line, are treated as
815 comments. Boolean values can be represented as true, TRUE, or 1 for
816 true, and false, FALSE, or 0 for false.
819 7.2 Declaration vs Definition
821 A declaration associates a layout to a type, without specifying where
822 this type is located in the event structure hierarchy (see Section 6).
823 This therefore includes typedef, typealias, as well as all type
824 specifiers. In certain circumstances (typedef, structure field and
825 variant field), a declaration is followed by a declarator, which specify
826 the newly defined type name (for typedef), or the field name (for
827 declarations located within structure and variants). Array and sequence,
828 declared with square brackets ("[" "]"), are part of the declarator,
829 similarly to C99. The enumeration base type is specified by
830 ": enum_base", which is part of the type specifier. The variant tag
831 name, specified between "<" ">", is also part of the type specifier.
833 A definition associates a type to a location in the event structure
834 hierarchy (see Section 6). This association is denoted by ":=", as shown
840 TSDL uses two different types of scoping: a lexical scope is used for
841 declarations and type definitions, and a dynamic scope is used for
842 variants references to tag fields.
846 Each of "trace", "stream", "event", "struct" and "variant" have their own
847 nestable declaration scope, within which types can be declared using "typedef"
848 and "typealias". A root declaration scope also contains all declarations
849 located outside of any of the aforementioned declarations. An inner
850 declaration scope can refer to type declared within its container
851 lexical scope prior to the inner declaration scope. Redefinition of a
852 typedef or typealias is not valid, although hiding an upper scope
853 typedef or typealias is allowed within a sub-scope.
857 A dynamic scope consists in the lexical scope augmented with the
858 implicit event structure definition hierarchy presented at Section 6.
859 The dynamic scope is only used for variant tag definitions. It is used
860 at definition time to look up the location of the tag field associated
863 Therefore, variants in lower levels in the dynamic scope (e.g. event
864 context) can refer to a tag field located in upper levels (e.g. in the
865 event header) by specifying, in this case, the associated tag with
866 <header.field_name>. This allows, for instance, the event context to
867 define a variant referring to the "id" field of the event header as
870 The target dynamic scope must be specified explicitly when referring to
871 a field outside of the local static scope. The dynamic scope prefixes
874 - Trace Packet Header: <trace.packet.header. >,
875 - Stream Packet Context: <stream.packet.context. >,
876 - Event Header: <stream.event.header. >,
877 - Stream Event Context: <stream.event.context. >,
878 - Event Context: <event.context. >,
879 - Event Payload: <event.fields. >.
881 Multiple declarations of the same field name within a single scope is
882 not valid. It is however valid to re-use the same field name in
883 different scopes. There is no possible conflict, because the dynamic
884 scope must be specified when a variant refers to a tag field located in
885 a different dynamic scope.
887 The information available in the dynamic scopes can be thought of as the
888 current tracing context. At trace production, information about the
889 current context is saved into the specified scope field levels. At trace
890 consumption, for each event, the current trace context is therefore
891 readable by accessing the upper dynamic scopes.
896 The grammar representing the TSDL metadata is presented in Appendix C.
897 TSDL Grammar. This section presents a rather ligher reading that
898 consists in examples of TSDL metadata, with template values.
900 The stream "id" can be left out if there is only one stream in the
901 trace. The event "id" field can be left out if there is only one event
905 major = value; /* Trace format version */
907 uuid = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; /* Trace UUID */
908 byte_order = be OR le; /* Endianness (required) */
909 packet.header := struct {
911 uint8_t trace_uuid[16];
918 /* Type 1 - Few event IDs; Type 2 - Many event IDs. See section 6.1. */
919 event.header := event_header_1 OR event_header_2;
920 event.context := struct {
923 packet.context := struct {
930 id = value; /* Numeric identifier within the stream */
940 /* More detail on types in section 4. Types */
945 * Type declarations behave similarly to the C standard.
948 typedef aliased_type_specifiers new_type_declarators;
950 /* e.g.: typedef struct example new_type_name[10]; */
955 * The "typealias" declaration can be used to give a name (including
956 * pointer declarator specifier) to a type. It should also be used to
957 * map basic C types (float, int, unsigned long, ...) to a CTF type.
958 * Typealias is a superset of "typedef": it also allows assignment of a
959 * simple variable identifier to a type.
962 typealias type_class {
964 } := type_specifiers type_declarator;
968 * typealias integer {
972 * } := struct page *;
974 * typealias integer {
989 enum name : integer_type {
995 * Unnamed types, contained within compound type fields, typedef or typealias.
1006 enum : integer_type {
1010 typedef type new_type[length];
1013 type field_name[length];
1016 typedef type new_type[length_type];
1019 type field_name[length_type];
1031 integer_type field_name:size; /* GNU/C bitfield */
1041 The two following macros keep track of the size of a GNU/C structure without
1042 padding at the end by placing HEADER_END as the last field. A one byte end field
1043 is used for C90 compatibility (C99 flexible arrays could be used here). Note
1044 that this does not affect the effective structure size, which should always be
1045 calculated with the header_sizeof() helper.
1047 #define HEADER_END char end_field
1048 #define header_sizeof(type) offsetof(typeof(type), end_field)
1051 B. Stream Header Rationale
1053 An event stream is divided in contiguous event packets of variable size. These
1054 subdivisions allow the trace analyzer to perform a fast binary search by time
1055 within the stream (typically requiring to index only the event packet headers)
1056 without reading the whole stream. These subdivisions have a variable size to
1057 eliminate the need to transfer the event packet padding when partially filled
1058 event packets must be sent when streaming a trace for live viewing/analysis.
1059 An event packet can contain a certain amount of padding at the end. Dividing
1060 streams into event packets is also useful for network streaming over UDP and
1061 flight recorder mode tracing (a whole event packet can be swapped out of the
1062 buffer atomically for reading).
1064 The stream header is repeated at the beginning of each event packet to allow
1065 flexibility in terms of:
1067 - streaming support,
1068 - allowing arbitrary buffers to be discarded without making the trace
1070 - allow UDP packet loss handling by either dealing with missing event packet
1071 or asking for re-transmission.
1072 - transparently support flight recorder mode,
1073 - transparently support crash dump.
1075 The event stream header will therefore be referred to as the "event packet
1076 header" throughout the rest of this document.
1082 * Common Trace Format (CTF) Trace Stream Description Language (TSDL) Grammar.
1084 * Inspired from the C99 grammar:
1085 * http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf (Annex A)
1086 * and c++1x grammar (draft)
1087 * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3291.pdf (Annex A)
1089 * Specialized for CTF needs by including only constant and declarations from
1090 * C99 (excluding function declarations), and by adding support for variants,
1091 * sequences and CTF-specific specifiers. Enumeration container types
1092 * semantic is inspired from c++1x enum-base.
1097 1.1) Lexical elements
1140 identifier identifier-nondigit
1143 identifier-nondigit:
1145 universal-character-name
1146 any other implementation-defined characters
1150 [a-zA-Z] /* regular expression */
1153 [0-9] /* regular expression */
1155 1.4) Universal character names
1157 universal-character-name:
1159 \U hex-quad hex-quad
1162 hexadecimal-digit hexadecimal-digit hexadecimal-digit hexadecimal-digit
1168 enumeration-constant
1172 decimal-constant integer-suffix-opt
1173 octal-constant integer-suffix-opt
1174 hexadecimal-constant integer-suffix-opt
1178 decimal-constant digit
1182 octal-constant octal-digit
1184 hexadecimal-constant:
1185 hexadecimal-prefix hexadecimal-digit
1186 hexadecimal-constant hexadecimal-digit
1196 unsigned-suffix long-suffix-opt
1197 unsigned-suffix long-long-suffix
1198 long-suffix unsigned-suffix-opt
1199 long-long-suffix unsigned-suffix-opt
1215 digit-sequence digit
1217 hexadecimal-digit-sequence:
1219 hexadecimal-digit-sequence hexadecimal-digit
1221 enumeration-constant:
1227 L' c-char-sequence '
1231 c-char-sequence c-char
1234 any member of source charset except single-quote ('), backslash
1235 (\), or new-line character.
1239 simple-escape-sequence
1240 octal-escape-sequence
1241 hexadecimal-escape-sequence
1242 universal-character-name
1244 simple-escape-sequence: one of
1245 \' \" \? \\ \a \b \f \n \r \t \v
1247 octal-escape-sequence:
1249 \ octal-digit octal-digit
1250 \ octal-digit octal-digit octal-digit
1252 hexadecimal-escape-sequence:
1253 \x hexadecimal-digit
1254 hexadecimal-escape-sequence hexadecimal-digit
1256 1.6) String literals
1259 " s-char-sequence-opt "
1260 L" s-char-sequence-opt "
1264 s-char-sequence s-char
1267 any member of source charset except double-quote ("), backslash
1268 (\), or new-line character.
1274 [ ] ( ) { } . -> * + - < > : ; ... = ,
1277 2) Phrase structure grammar
1283 ( unary-expression )
1287 postfix-expression [ unary-expression ]
1288 postfix-expression . identifier
1289 postfix-expressoin -> identifier
1293 unary-operator postfix-expression
1295 unary-operator: one of
1298 assignment-operator:
1301 type-assignment-operator:
1304 constant-expression:
1307 constant-expression-range:
1308 constant-expression ... constant-expression
1313 declaration-specifiers declarator-list-opt ;
1316 declaration-specifiers:
1317 storage-class-specifier declaration-specifiers-opt
1318 type-specifier declaration-specifiers-opt
1319 type-qualifier declaration-specifiers-opt
1323 declarator-list , declarator
1325 abstract-declarator-list:
1327 abstract-declarator-list , abstract-declarator
1329 storage-class-specifier:
1352 struct identifier-opt { struct-or-variant-declaration-list-opt }
1355 struct-or-variant-declaration-list:
1356 struct-or-variant-declaration
1357 struct-or-variant-declaration-list struct-or-variant-declaration
1359 struct-or-variant-declaration:
1360 specifier-qualifier-list struct-or-variant-declarator-list ;
1361 declaration-specifiers storage-class-specifier declaration-specifiers declarator-list ;
1362 typealias declaration-specifiers abstract-declarator-list := declaration-specifiers abstract-declarator-list ;
1363 typealias declaration-specifiers abstract-declarator-list := declarator-list ;
1365 specifier-qualifier-list:
1366 type-specifier specifier-qualifier-list-opt
1367 type-qualifier specifier-qualifier-list-opt
1369 struct-or-variant-declarator-list:
1370 struct-or-variant-declarator
1371 struct-or-variant-declarator-list , struct-or-variant-declarator
1373 struct-or-variant-declarator:
1375 declarator-opt : constant-expression
1378 variant identifier-opt variant-tag-opt { struct-or-variant-declaration-list }
1379 variant identifier variant-tag
1385 enum identifier-opt { enumerator-list }
1386 enum identifier-opt { enumerator-list , }
1388 enum identifier-opt : declaration-specifiers { enumerator-list }
1389 enum identifier-opt : declaration-specifiers { enumerator-list , }
1393 enumerator-list , enumerator
1396 enumeration-constant
1397 enumeration-constant = constant-expression
1398 enumeration-constant = constant-expression-range
1404 pointer-opt direct-declarator
1409 direct-declarator [ type-specifier ]
1410 direct-declarator [ constant-expression ]
1412 abstract-declarator:
1413 pointer-opt direct-abstract-declarator
1415 direct-abstract-declarator:
1417 ( abstract-declarator )
1418 direct-abstract-declarator [ type-specifier ]
1419 direct-abstract-declarator [ constant-expression ]
1420 direct-abstract-declarator [ ]
1423 * type-qualifier-list-opt
1424 * type-qualifier-list-opt pointer
1426 type-qualifier-list:
1428 type-qualifier-list type-qualifier
1433 2.3) CTF-specific declarations
1436 event { ctf-assignment-expression-list-opt }
1437 stream { ctf-assignment-expression-list-opt }
1438 trace { ctf-assignment-expression-list-opt }
1439 typealias declaration-specifiers abstract-declarator-list := declaration-specifiers abstract-declarator-list ;
1440 typealias declaration-specifiers abstract-declarator-list := declarator-list ;
1443 floating_point { ctf-assignment-expression-list-opt }
1444 integer { ctf-assignment-expression-list-opt }
1445 string { ctf-assignment-expression-list-opt }
1447 ctf-assignment-expression-list:
1448 ctf-assignment-expression
1449 ctf-assignment-expression-list ; ctf-assignment-expression
1451 ctf-assignment-expression:
1452 unary-expression assignment-operator unary-expression
1453 unary-expression type-assignment-operator type-specifier
1454 declaration-specifiers storage-class-specifier declaration-specifiers declarator-list
1455 typealias declaration-specifiers abstract-declarator-list := declaration-specifiers abstract-declarator-list
1456 typealias declaration-specifiers abstract-declarator-list := declarator-list