blob: 444dd3bd8b8cce0753aa905611ff81f1f4c220ac [file] [log] [blame] [view]
Andrew Gerrand5bc444d2014-12-10 11:35:11 +11001Heap dump format for other versions:
2
Russ Cox569d2892015-12-29 15:31:04 -05003 * Go 1.3: [[heapdump13]]
Keith Randall5605c192018-03-07 10:55:13 -08004 * Go 1.5 and later: [[heapdump15-through-heapdump17]]
Andrew Gerrand5bc444d2014-12-10 11:35:11 +11005
6# Introduction
7
8Go 1.4 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
10
11# Details
12
13The file starts with the bytes of the string "go1.4 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=Iface, and 3=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 * string: contents of object
50 * fieldlist: describes pointer-containing fields of the object
51
52The 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.
53
54# otherroot
55 * string: textual description of where this root came from
56 * uvarint: root pointer
57
58# type
59 * uvarint: address of type descriptor
60 * uvarint: size of an object of this type
61 * string: name of type
62 * bool: whether the data field of an interface containing a value of this type is a pointer
63
64# goroutine (G)
65
66 * uvarint: address of descriptor
67 * uvarint: pointer to the top of stack (the currently running frame, a.k.a. depth 0)
68 * uvarint: go routine ID
69 * uvarint: the location of the go statement that created this goroutine
70 * uvarint: status
71 * bool: is a Go routine started by the system
72 * bool: is a background Go routine
73 * uvarint: approximate time the go routine last started waiting (nanoseconds since the Epoch)
74 * string: textual reason why it is waiting
75 * uvarint: context pointer of currently running frame
76 * uvarint: address of os thread descriptor (M)
77 * uvarint: top defer record
78 * uvarint: top panic record
79
80Possible statuses:
81 * 0 = idle
82 * 1 = runnable
83 * 3 = syscall
84 * 4 = waiting
85
86The wait fields must be present in all cases, but they only mean something if the status is "waiting".
87
88# stack frame
89 * uvarint: stack pointer (lowest address in frame)
90 * uvarint: depth in stack (0 = top of stack)
91 * uvarint: stack pointer of child frame (or 0 if none)
92 * string: contents of stack frame
93 * uvarint: entry pc for function
94 * uvarint: current pc for function
95 * uvarint: continuation pc for function (where function may resume, if anywhere)
96 * string: function name
97 * fieldlist: list of kind and offset of pointer-containing fields in this frame
98
99# dump params
100
101 * bool: big endian
102 * uvarint: pointer size in bytes
Andrew Gerrand5bc444d2014-12-10 11:35:11 +1100103 * uvarint: starting address of heap
104 * uvarint: ending address of heap
105 * uvarint: thechar = architecture specifier
106 * string: GOEXPERIMENT environment variable value
107 * uvarint: runtime.ncpu
108
109# finalizer
110 * uvarint: address of object that has a finalizer
111 * uvarint: pointer to FuncVal describing the finalizer
112 * uvarint: PC of finalizer entry point
113 * uvarint: type of finalizer argument
114 * uvarint: type of object
115
116This 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.
117
118# itab
119 * uvarint: Itab address
120 * uvarint: address of type descriptor for contained type
121
122# osthread (M)
123 * uvarint: address of this os thread descriptor
124 * uvarint: Go internal id of thread
125 * uvarint: os's id for thread
126
127# memstats
128
129Dumps 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.
130
131# queuedfinalizer
132 * uvarint: address of object that has a finalizer
133 * uvarint: pointer to FuncVal describing the finalizer
134 * uvarint: PC of finalizer entry point
135 * uvarint: type of finalizer argument
136 * uvarint: type of object
137
138This 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.
139
140# data
141 * uvarint: address of the start of the data segment
142 * string: contents of the data segment
143 * fieldlist: kind and offset of pointer-containing fields in the data segment.
144
145# bss
146
147Same format as data, but for the bss segment.
148
149# defer
150 * uvarint: defer record address
151 * uvarint: containing goroutine
152 * uvarint: argp
153 * uvarint: pc
154 * uvarint: FuncVal of defer
155 * uvarint: PC of defer entry point
156 * uvarint: link to next defer record
157
158# panic
159 * uvarint: panic record address
160 * uvarint: containing goroutine
161 * uvarint: type ptr of panic arg eface
162 * uvarint: data field of panic arg eface
163 * uvarint: ptr to defer record that's currently running
164 * uvarint: link to next panic record
165
166# alloc/free profile record
167 * uvarint: record identifier
168 * uvarint: size of allocated object
169 * uvarint: number of stack frames. For each frame:
170 * - string: function name
171 * - string: file name
172 * - uvarint: line number
173 * uvarint: number of allocations
174 * uvarint: number of frees
175
176# alloc sample record
177 * uvarint: address of object
178 * uvarint: alloc/free profile record identifier