LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package runtime | 5 package runtime |
6 | 6 |
7 import "unsafe" | 7 import "unsafe" |
8 | 8 |
9 type MemStatsType struct { | 9 // A MemStats records statistics about the memory allocator. |
| 10 type MemStats struct { |
10 // General statistics. | 11 // General statistics. |
11 // Not locked during update; approximate. | |
12 Alloc uint64 // bytes allocated and still in use | 12 Alloc uint64 // bytes allocated and still in use |
13 TotalAlloc uint64 // bytes allocated (even if freed) | 13 TotalAlloc uint64 // bytes allocated (even if freed) |
14 Sys uint64 // bytes obtained from system (should be sum of XxxSys
below) | 14 Sys uint64 // bytes obtained from system (should be sum of XxxSys
below) |
15 Lookups uint64 // number of pointer lookups | 15 Lookups uint64 // number of pointer lookups |
16 Mallocs uint64 // number of mallocs | 16 Mallocs uint64 // number of mallocs |
17 Frees uint64 // number of frees | 17 Frees uint64 // number of frees |
18 | 18 |
19 // Main allocation heap statistics. | 19 // Main allocation heap statistics. |
20 HeapAlloc uint64 // bytes allocated and still in use | 20 HeapAlloc uint64 // bytes allocated and still in use |
21 HeapSys uint64 // bytes obtained from system | 21 HeapSys uint64 // bytes obtained from system |
22 HeapIdle uint64 // bytes in idle spans | 22 HeapIdle uint64 // bytes in idle spans |
23 HeapInuse uint64 // bytes in non-idle span | 23 HeapInuse uint64 // bytes in non-idle span |
24 HeapReleased uint64 // bytes released to the OS | 24 HeapReleased uint64 // bytes released to the OS |
25 HeapObjects uint64 // total number of allocated objects | 25 HeapObjects uint64 // total number of allocated objects |
26 | 26 |
27 // Low-level fixed-size structure allocator statistics. | 27 // Low-level fixed-size structure allocator statistics. |
28 // Inuse is bytes used now. | 28 // Inuse is bytes used now. |
29 // Sys is bytes obtained from system. | 29 // Sys is bytes obtained from system. |
30 StackInuse uint64 // bootstrap stacks | 30 StackInuse uint64 // bootstrap stacks |
31 StackSys uint64 | 31 StackSys uint64 |
32 MSpanInuse uint64 // mspan structures | 32 MSpanInuse uint64 // mspan structures |
33 MSpanSys uint64 | 33 MSpanSys uint64 |
34 MCacheInuse uint64 // mcache structures | 34 MCacheInuse uint64 // mcache structures |
35 MCacheSys uint64 | 35 MCacheSys uint64 |
36 BuckHashSys uint64 // profiling bucket hash table | 36 BuckHashSys uint64 // profiling bucket hash table |
37 | 37 |
38 // Garbage collector statistics. | 38 // Garbage collector statistics. |
39 » NextGC uint64 // next run in HeapAlloc (bytes) | 39 » NextGC uint64 // next run in HeapAlloc time (bytes) |
40 LastGC uint64 // last run in absolute time (ns) | 40 LastGC uint64 // last run in absolute time (ns) |
41 PauseTotalNs uint64 | 41 PauseTotalNs uint64 |
42 PauseNs [256]uint64 // most recent GC pause times | 42 PauseNs [256]uint64 // most recent GC pause times |
43 NumGC uint32 | 43 NumGC uint32 |
44 EnableGC bool | 44 EnableGC bool |
45 DebugGC bool | 45 DebugGC bool |
46 | 46 |
47 // Per-size allocation statistics. | 47 // Per-size allocation statistics. |
48 // Not locked during update; approximate. | |
49 // 61 is NumSizeClasses in the C code. | 48 // 61 is NumSizeClasses in the C code. |
50 BySize [61]struct { | 49 BySize [61]struct { |
51 Size uint32 | 50 Size uint32 |
52 Mallocs uint64 | 51 Mallocs uint64 |
53 Frees uint64 | 52 Frees uint64 |
54 } | 53 } |
55 } | 54 } |
56 | 55 |
57 var sizeof_C_MStats uintptr // filled in by malloc.goc | 56 var sizeof_C_MStats uintptr // filled in by malloc.goc |
58 | 57 |
| 58 var memStats MemStats |
| 59 |
59 func init() { | 60 func init() { |
60 » if sizeof_C_MStats != unsafe.Sizeof(MemStats) { | 61 » if sizeof_C_MStats != unsafe.Sizeof(memStats) { |
61 » » println(sizeof_C_MStats, unsafe.Sizeof(MemStats)) | 62 » » println(sizeof_C_MStats, unsafe.Sizeof(memStats)) |
62 panic("MStats vs MemStatsType size mismatch") | 63 panic("MStats vs MemStatsType size mismatch") |
63 } | 64 } |
64 } | 65 } |
65 | 66 |
66 // MemStats holds statistics about the memory system. | 67 // ReadMemStats populates m with memory allocator statistics. |
67 // The statistics may be out of date, as the information is | 68 func ReadMemStats(m *MemStats) |
68 // updated lazily from per-thread caches. | |
69 // Use UpdateMemStats to bring the statistics up to date. | |
70 var MemStats MemStatsType | |
71 | |
72 // UpdateMemStats brings MemStats up to date. | |
73 func UpdateMemStats() | |
74 | 69 |
75 // GC runs a garbage collection. | 70 // GC runs a garbage collection. |
76 func GC() | 71 func GC() |
LEFT | RIGHT |