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