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