blob: fc83e180468e22d53e98b2622e3e63c2b7390893 [file] [log] [blame] [view]
Andrew Gerrand5bc444d2014-12-10 11:35:11 +11001Heap dump format for other versions:
2
Russ Coxd0a958a2015-12-29 15:31:21 -05003 * Go 1.4: [[heapdump14]]
Keith Randallf70ee372018-03-07 10:54:57 -08004 * Go 1.5 and later: [[heapdump15-through-heapdump17]]
Andrew Gerrand5bc444d2014-12-10 11:35:11 +11005
6# Introduction
7
8Go 1.3 added 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
10
11# Details
12
13The file starts with the bytes of the string "go1.3 heap dump\n".
14
15The rest of the file is a sequence of records. Records can be of several different kinds. Records will contain the following primitives:
16 * uvarint - a 64-bit unsigned integer encoded as in encoding/binary.{Put,Read}Uvarint
17 * string - a uvarint-encoded length followed by that many bytes of data
18 * bool - a uvarint-encoded 0 for false or 1 for true
19 * 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 possible kinds are 1=Ptr, 2=String, 3=Slice, 4=Iface, and 5=Eface. 0=Eol is the end of list marker. The end of list marker does not have a corresponding offset.
20
21Each record starts with a uvarint-encoded integer describing the type of the record:
22 * 0 = EOF
23 * 1 = object
24 * 2 = otherroot
25 * 3 = type
26 * 4 = goroutine
27 * 5 = stack frame
28 * 6 = dump params
29 * 7 = registered finalizer
30 * 8 = itab
31 * 9 = OS thread
32 * 10 = mem stats
33 * 11 = queued finalizer
34 * 12 = data segment
35 * 13 = bss segment
36 * 14 = defer record
37 * 15 = panic record
38 * 16 = alloc/free profile record
39 * 17 = alloc stack trace sample
40
41The remaining fields of each record are type-dependent and are described below.
42
43# EOF
44
45An EOF record has no fields and must appear last.
46
47# object
48 * uvarint: address of object
49 * uvarint: address of type descriptor (or 0 if unknown)
50 * uvarint: kind of object (0=regular 1=array 2=channel 127=conservatively scanned)
51 * string: contents of object
52
53For array or channel kinds, the type must be nonzero.
54
55The size of the contents string is the size of the containing sizeclass, not the size of the type itself. As such, contents size may be somewhat bigger than the type size. It may be a lot bigger for array and channel types. For instance, an array with n elements will have a content size bigger than or equal to n times the type size.
56
57# otherroot
58 * string: textual description of where this root came from
59 * uvarint: root pointer
60
61# type
62 * uvarint: address of type descriptor
63 * uvarint: size of an object of this type
64 * string: name of type
65 * bool: whether the data field of an interface containing a value of this type is a pointer
66 * fieldlist: a list of the kinds and locations of pointer-containing fields in objects of this type
67
68# goroutine (G)
69
70 * uvarint: address of descriptor
71 * uvarint: pointer to the top of stack (the currently running frame, a.k.a. depth 0)
72 * uvarint: go routine ID
73 * uvarint: the location of the go statement that created this goroutine
74 * uvarint: status
75 * bool: is a Go routine started by the system
76 * bool: is a background Go routine
77 * uvarint: approximate time the go routine last started waiting (nanoseconds since the Epoch)
78 * string: textual reason why it is waiting
79 * uvarint: context pointer of currently running frame
80 * uvarint: address of os thread descriptor (M)
81 * uvarint: top defer record
82 * uvarint: top panic record
83
84Possible statuses:
85 * 0 = idle
86 * 1 = runnable
87 * 3 = syscall
88 * 4 = waiting
89
90The wait fields must be present in all cases, but they only mean something if the status is "waiting".
91
92# stack frame
93 * uvarint: stack pointer (lowest address in frame)
94 * uvarint: depth in stack (0 = top of stack)
95 * uvarint: stack pointer of child frame (or 0 if none)
96 * string: contents of stack frame
97 * uvarint: entry pc for function
98 * uvarint: current pc for function
99 * uvarint: continuation pc for function (where function may resume, if anywhere)
100 * string: function name
101 * fieldlist: list of kind and offset of pointer-containing fields in this frame
102
103# dump params
104
105 * bool: big endian
106 * uvarint: pointer size in bytes
107 * uvarint: channel header size in bytes
108 * uvarint: starting address of heap
109 * uvarint: ending address of heap
110 * uvarint: thechar = architecture specifier
111 * string: GOEXPERIMENT environment variable value
112 * uvarint: runtime.ncpu
113
114# finalizer
115 * uvarint: address of object that has a finalizer
116 * uvarint: pointer to FuncVal describing the finalizer
117 * uvarint: PC of finalizer entry point
118 * uvarint: type of finalizer argument
119 * uvarint: type of object
120
121This 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.
122
123# itab
124 * uvarint: Itab address
125 * bool: whether the data field of an Iface with this itab is a pointer
126
127# osthread (M)
128 * uvarint: address of this os thread descriptor
129 * uvarint: Go internal id of thread
130 * uvarint: os's id for thread
131
132# memstats
133
134Dumps 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.
135
136# queuedfinalizer
137 * uvarint: address of object that has a finalizer
138 * uvarint: pointer to FuncVal describing the finalizer
139 * uvarint: PC of finalizer entry point
140 * uvarint: type of finalizer argument
141 * uvarint: type of object
142
143This 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.
144
145# data
146 * uvarint: address of the start of the data segment
147 * string: contents of the data segment
148 * fieldlist: kind and offset of pointer-containing fields in the data segment.
149
150# bss
151
152Same format as data, but for the bss segment.
153
154# defer
155 * uvarint: defer record address
156 * uvarint: containing goroutine
157 * uvarint: argp
158 * uvarint: pc
159 * uvarint: FuncVal of defer
160 * uvarint: PC of defer entry point
161 * uvarint: link to next defer record
162
163# panic
164 * uvarint: panic record address
165 * uvarint: containing goroutine
166 * uvarint: type ptr of panic arg eface
167 * uvarint: data field of panic arg eface
168 * uvarint: ptr to defer record that's currently running
169 * uvarint: link to next panic record
170
171# alloc/free profile record
172 * uvarint: record identifier
173 * uvarint: size of allocated object
174 * uvarint: number of stack frames. For each frame:
175 * - string: function name
176 * - string: file name
177 * - uvarint: line number
178 * uvarint: number of allocations
179 * uvarint: number of frees
180
181# alloc sample record
182 * uvarint: address of object
183 * uvarint: alloc/free profile record identifier