blob: fb6e4891eb63c3d60588e96531f7595e497c9777 [file] [log] [blame] [view]
Russ Cox5e575222015-12-29 15:30:38 -05001Heap dump format for other versions:
2
3 * [[heapdump13]]
4 * [[heapdump14]]
5
6# Introduction
7
8Go 1.5 has a runtime/debug.WriteHeapDump function that writes all objects in the heap plus additional info (roots, goroutines, finalizers, etc.) to a file. The format of this file is specified here.
9
10XXX WORK IN PROGRESS XXX
11
12# Details
13
14The file starts with the bytes of the string "go1.5 heap dump\n".
15
16The rest of the file is a sequence of records. Records can be of several different kinds. Records will contain the following primitives:
17 * uvarint - a 64-bit unsigned integer encoded as in encoding/binary.{Put,Read}Uvarint
18 * string - a uvarint-encoded length followed by that many bytes of data
19 * bool - a uvarint-encoded 0 for false or 1 for true
Russ Coxf3347552015-12-29 15:32:35 -050020 * fieldlist - a description of the pointer-bearing portions of a memory region. It consists of repeated pairs of uvarints encoding a field kind and a field offset, followed by and end-of-list marker. The only possible kind is 1=Ptr. Earlier versions of the heap dump could contain 2=Iface and 3=Eface, but the runtime no longer tracks that information, so it is not present in the dump. Interface values appear as a pair of pointers. 0=Eol is the end of list marker. The end of list marker does not have a corresponding offset.
Russ Cox5e575222015-12-29 15:30:38 -050021
22Each record starts with a uvarint-encoded integer describing the type of the record:
23 * 0 = EOF
24 * 1 = object
25 * 2 = otherroot
26 * 3 = type
27 * 4 = goroutine
28 * 5 = stack frame
29 * 6 = dump params
30 * 7 = registered finalizer
31 * 8 = itab
32 * 9 = OS thread
33 * 10 = mem stats
34 * 11 = queued finalizer
35 * 12 = data segment
36 * 13 = bss segment
37 * 14 = defer record
38 * 15 = panic record
39 * 16 = alloc/free profile record
40 * 17 = alloc stack trace sample
41
42The remaining fields of each record are type-dependent and are described below.
43
44# EOF
45
46An EOF record has no fields and must appear last.
47
48# object
49 * uvarint: address of object
50 * string: contents of object
51 * fieldlist: describes pointer-containing fields of the object
52
53The size of the contents string is the size of the containing sizeclass, not the size of the object itself. As such, contents size may be somewhat bigger than the contained object's type.
54
55# otherroot
56 * string: textual description of where this root came from
57 * uvarint: root pointer
58
59# type
60 * uvarint: address of type descriptor
61 * uvarint: size of an object of this type
62 * string: name of type
Russ Cox71e5ae92015-12-29 15:49:56 -050063 * bool: whether the data field of an interface containing a value of this type is a pointer (for Go 1.5 and later, always true)
Russ Cox5e575222015-12-29 15:30:38 -050064
65# goroutine (G)
66
67 * uvarint: address of descriptor
68 * uvarint: pointer to the top of stack (the currently running frame, a.k.a. depth 0)
69 * uvarint: go routine ID
70 * uvarint: the location of the go statement that created this goroutine
71 * uvarint: status
72 * bool: is a Go routine started by the system
73 * bool: is a background Go routine
74 * uvarint: approximate time the go routine last started waiting (nanoseconds since the Epoch)
75 * string: textual reason why it is waiting
76 * uvarint: context pointer of currently running frame
77 * uvarint: address of os thread descriptor (M)
78 * uvarint: top defer record
79 * uvarint: top panic record
80
81Possible statuses:
82 * 0 = idle
83 * 1 = runnable
84 * 3 = syscall
85 * 4 = waiting
86
87The wait fields must be present in all cases, but they only mean something if the status is "waiting".
88
89# stack frame
90 * uvarint: stack pointer (lowest address in frame)
91 * uvarint: depth in stack (0 = top of stack)
92 * uvarint: stack pointer of child frame (or 0 if none)
93 * string: contents of stack frame
94 * uvarint: entry pc for function
95 * uvarint: current pc for function
96 * uvarint: continuation pc for function (where function may resume, if anywhere)
97 * string: function name
98 * fieldlist: list of kind and offset of pointer-containing fields in this frame
99
100# dump params
101
102 * bool: big endian
103 * uvarint: pointer size in bytes
104 * uvarint: starting address of heap
105 * uvarint: ending address of heap
106 * uvarint: thechar = architecture specifier
107 * string: GOEXPERIMENT environment variable value
108 * uvarint: runtime.ncpu
109
110# finalizer
111 * uvarint: address of object that has a finalizer
112 * uvarint: pointer to FuncVal describing the finalizer
113 * uvarint: PC of finalizer entry point
114 * uvarint: type of finalizer argument
115 * uvarint: type of object
116
117This finalizer has been registered with the runtime system, but the object to which it refers was either reachable as of the most recent GC or allocated since the most recent GC.
118
119# itab
120 * uvarint: Itab address
121 * uvarint: address of type descriptor for contained type
122
123# osthread (M)
124 * uvarint: address of this os thread descriptor
125 * uvarint: Go internal id of thread
126 * uvarint: os's id for thread
127
128# memstats
129
130Dumps the first 26 fields of [MemStats](http://golang.org/pkg/runtime/#MemStats). All fields are dumped with a uvarint except the 25th which is dumped with 256 uvarints.
131
132# queuedfinalizer
133 * uvarint: address of object that has a finalizer
134 * uvarint: pointer to FuncVal describing the finalizer
135 * uvarint: PC of finalizer entry point
136 * uvarint: type of finalizer argument
137 * uvarint: type of object
138
139This finalizer is ready to run - the object to which it refers is unreachable. The runtime system just hasn't gotten around to running it yet.
140
141# data
142 * uvarint: address of the start of the data segment
143 * string: contents of the data segment
144 * fieldlist: kind and offset of pointer-containing fields in the data segment.
145
146# bss
147
148Same format as data, but for the bss segment.
149
150# defer
151 * uvarint: defer record address
152 * uvarint: containing goroutine
153 * uvarint: argp
154 * uvarint: pc
155 * uvarint: FuncVal of defer
156 * uvarint: PC of defer entry point
157 * uvarint: link to next defer record
158
159# panic
160 * uvarint: panic record address
161 * uvarint: containing goroutine
162 * uvarint: type ptr of panic arg eface
163 * uvarint: data field of panic arg eface
164 * uvarint: ptr to defer record that's currently running
165 * uvarint: link to next panic record
166
167# alloc/free profile record
168 * uvarint: record identifier
169 * uvarint: size of allocated object
170 * uvarint: number of stack frames. For each frame:
171 * - string: function name
172 * - string: file name
173 * - uvarint: line number
174 * uvarint: number of allocations
175 * uvarint: number of frees
176
177# alloc sample record
178 * uvarint: address of object
179 * uvarint: alloc/free profile record identifier