blob: 08bfd002843db3efc92a995efab99cbeeb318b12 [file] [log] [blame]
José Fonseca38ab5182014-05-23 21:16:11 +01001# Trace binary format specification #
2
3This document specifies the binary format of trace streams.
4
Jose Fonseca6c3d2672016-10-05 23:06:40 +01005## Compression ##
6
7Trace streams are not written verbatim to file, but compressed.
8
9By default traces are compressed with [Snappy](https://github.com/google/snappy)
10(see below for details). Previously they used to be compressed with gzip. And
11recently it also possible to have them compressed with
12[Brotli](https://github.com/google/brotli), though this is mostly intended for
13space savings on large databases of trace files.
14
15`apitrace repack` utility can be used to recompress the stream without any loss.
16
17### Snappy ###
18
19The used Snappy format is different from the standard _Snappy framing format_,
20because it predates it.
21
22 file = header chunk*
23
24 header = 'a' 't'
25
26 chunk = compressed_length compressed_data
27
28 compressed_length = uint32 // length of compressed data in little endian
29 compressed_data = byte*
José Fonseca38ab5182014-05-23 21:16:11 +010030
31
32## Versions ##
33
Jose Fonsecab5ce0152016-10-05 22:32:47 +010034We keep backwards compatibility reading old traces, i.e., it should always be
José Fonseca38ab5182014-05-23 21:16:11 +010035possible to parse and retrace old trace files.
36
37The trace version number refers not only to changes in the binary format
38representation, but also semantic changes in the way certain functions should
39be retraced.
40
41| `version_no` | Changes |
42| ------------ | ------- |
43| 0 | initial implementation |
44| 1 | support for OpenGL user arrays as blobs (whereas before calls that operated with user memory instead of VBOs should be ignored) |
45| 2 | malloc/free memory calls |
46| 3 | enums signatures with the whole set of name/value pairs |
47| 4 | call enter events include thread no |
48| 5 | support for call backtraces |
Jose Fonsecac5b912e2017-06-22 13:53:06 +010049| 6 | unicode strings |
José Fonseca38ab5182014-05-23 21:16:11 +010050
51Writing/editing old traces is not supported however. An older version of
Jose Fonsecab5ce0152016-10-05 22:32:47 +010052apitrace should be used in such circumstances.
José Fonseca38ab5182014-05-23 21:16:11 +010053
54
55## Basic types ##
56
57| Type | Description |
58| ---- | ----------- |
59| `byte` | Raw byte. |
Jose Fonsecab5ce0152016-10-05 22:32:47 +010060| `uint` | Variable-length unsigned integer, where the most significant bit is zero for last byte or non-zero if more bytes follow; the 7 least significant bits of each byte are used for the integer's bits, in little-endian order. |
José Fonseca38ab5182014-05-23 21:16:11 +010061| `float` | 32 bits single precision floating point number |
62| `double` | 64 bits single precision floating point number |
63
64Strings are length-prefixed. The trailing zero is implied, not appearing neither in the length prefix nor in the raw bytes.
65
66 string = count byte*
67
68 count = uint
69
70
71## Grammar ##
72
73The trace consists of a small header with version information, followed by an
74arbitrary number of events.
75
Jose Fonsecae8a5de72017-06-22 15:18:52 +010076 trace = version_no semantic_version_no event* // version_no >= 6
77 | version_no event* // version_no < 6
José Fonseca38ab5182014-05-23 21:16:11 +010078
79 version_no = uint
Jose Fonsecae8a5de72017-06-22 15:18:52 +010080 semantic_version_no = uint
81
José Fonseca38ab5182014-05-23 21:16:11 +010082
83### Calls ###
84
85Calls consist of an enter and leave event pair. Calls are numbered from zero,
86and the call number is implied for the enter event.
87
88 event = 0x00 thread_no call_sig call_detail+ // enter call (version_no >= 4)
89 | 0x00 call_sig call_detail+ // enter call (version_no < 4)
90 | 0x01 call_no call_detail+ // leave call
91
92 call_sig = id function_name count arg_name* // first occurrence
93 | id // follow-on occurrences
94
95 call_detail = 0x00 // terminator
96 | 0x01 arg_no value // argument value
97 | 0x02 value // return value
98 | 0x03 thread_no // thread number (version_no < 4)
99 | 0x04 count frame* // stack backtrace
100
101 arg_name = string
102 function_name = string
103
104 arg_no = uint
105 call_no = uint
106 thread_no = uint
107
108 id = uint
109
110### Values ###
111
112 value = 0x00 // null pointer
113 | 0x01 // false value
114 | 0x02 // true
115 | 0x03 uint // negative integer
116 | 0x04 uint // positive integer value
117 | 0x05 float // single-precision floating point value
118 | 0x06 double // double-precision floating point value
119 | 0x07 string // character string value (zero terminator implied)
120 | 0x08 string // binary blob
José Fonseca1ba7d252014-06-03 13:24:32 +0100121 | 0x09 enum_sig value // enumeration (version_no >= 3)
122 | 0x09 string value // enumeration (version_no < 3)
123 | 0x0a bitmask_sig value // integer bitmask
124 | 0x0b count value* // array
125 | 0x0c struct_sig value* // structure
126 | 0x0d uint // opaque pointer
127 | 0x0e value value // human-machine representation
José Fonsecad5cda7c2014-09-25 15:19:09 +0100128 | 0x0f wstring // wide character string value (zero terminator implied)
José Fonseca38ab5182014-05-23 21:16:11 +0100129
130 enum_sig = id count (name value)+ // first occurrence
131 | id // follow-on occurrences
132
Jose Fonsecab5ce0152016-10-05 22:32:47 +0100133 bitmask_sig = id count (name uint)+ // first occurrence
134 | id // follow-on occurrences
José Fonseca38ab5182014-05-23 21:16:11 +0100135
Jose Fonsecab5ce0152016-10-05 22:32:47 +0100136 struct_sig = id struct_name count member_name* // first occurrence
137 | id // follow-on occurrences
José Fonseca38ab5182014-05-23 21:16:11 +0100138
139 name = string
Jose Fonsecab5ce0152016-10-05 22:32:47 +0100140 struct_name = string
José Fonseca38ab5182014-05-23 21:16:11 +0100141 member_name = string
142
José Fonsecad5cda7c2014-09-25 15:19:09 +0100143 wstring = count uint*
144
José Fonseca38ab5182014-05-23 21:16:11 +0100145### Backtraces ###
146
147 frame = id frame_detail+ // first occurrence
148 | id // follow-on occurrences
149
150 frame_detail = 0x00 // terminator
151 | 0x01 string // module name
152 | 0x02 string // function name
153 | 0x03 string // source file name
154 | 0x04 uint // source line number
155 | 0x05 uint // byte offset from module start