blob: 0b076d7a311855f4480dbec336f2b9f29c155d72 [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
Russ Cox5e575222015-12-29 15:30:38 -050010# Details
11
12The file starts with the bytes of the string "go1.5 heap dump\n".
Keith Randall32d990a2018-03-07 10:54:00 -080013This description also applies to files starting with "go1.6 heap dump\n" and "go1.7 heap dump\n". The go1.6 format is identical to 1.5, and the go1.7 format has one small change described below.
Russ Cox5e575222015-12-29 15:30:38 -050014
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
Russ Coxf3347552015-12-29 15:32:35 -050019 * 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 -050020
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
Keith Randall32d990a2018-03-07 10:54:00 -080062 * bool: whether the data field of an interface containing a value of this type has type T (false) or *T (true)
Russ Cox5e575222015-12-29 15:30:38 -050063
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
103 * uvarint: starting address of heap
104 * uvarint: ending address of heap
Infinoid63999402018-03-14 14:20:29 -0400105 * string: architecture name
Russ Cox5e575222015-12-29 15:30:38 -0500106 * 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
Keith Randall32d990a2018-03-07 10:54:00 -0800121 * * Up to go1.6, the type is always a pointer type, and represents the type of the itab.data field.
122 * * From go1.7 and beyond, the type is the type stored in the interface. To decide whether the itab.data field is T or *T requires looking at the last boolean in the referenced type's descriptor.
Russ Cox5e575222015-12-29 15:30:38 -0500123
124# osthread (M)
125 * uvarint: address of this os thread descriptor
126 * uvarint: Go internal id of thread
127 * uvarint: os's id for thread
128
129# memstats
130
131Dumps 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.
132
133# queuedfinalizer
134 * uvarint: address of object that has a finalizer
135 * uvarint: pointer to FuncVal describing the finalizer
136 * uvarint: PC of finalizer entry point
137 * uvarint: type of finalizer argument
138 * uvarint: type of object
139
140This 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.
141
142# data
143 * uvarint: address of the start of the data segment
144 * string: contents of the data segment
145 * fieldlist: kind and offset of pointer-containing fields in the data segment.
146
147# bss
148
149Same format as data, but for the bss segment.
150
151# defer
152 * uvarint: defer record address
153 * uvarint: containing goroutine
154 * uvarint: argp
155 * uvarint: pc
156 * uvarint: FuncVal of defer
157 * uvarint: PC of defer entry point
158 * uvarint: link to next defer record
159
160# panic
161 * uvarint: panic record address
162 * uvarint: containing goroutine
163 * uvarint: type ptr of panic arg eface
164 * uvarint: data field of panic arg eface
165 * uvarint: ptr to defer record that's currently running
166 * uvarint: link to next panic record
167
168# alloc/free profile record
169 * uvarint: record identifier
170 * uvarint: size of allocated object
171 * uvarint: number of stack frames. For each frame:
172 * - string: function name
173 * - string: file name
174 * - uvarint: line number
175 * uvarint: number of allocations
176 * uvarint: number of frees
177
178# alloc sample record
179 * uvarint: address of object
180 * uvarint: alloc/free profile record identifier