Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 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 debug | 5 package debug |
6 | 6 |
7 import ( | 7 import ( |
8 "runtime" | 8 "runtime" |
9 "sort" | 9 "sort" |
10 "time" | 10 "time" |
11 ) | 11 ) |
12 | 12 |
13 // GCStats collect information about recent garbage collections. | 13 // GCStats collect information about recent garbage collections. |
14 type GCStats struct { | 14 type GCStats struct { |
15 LastGC time.Time // time of last collection | 15 LastGC time.Time // time of last collection |
16 NumGC int64 // number of garbage collections | 16 NumGC int64 // number of garbage collections |
17 PauseTotal time.Duration // total pause for all collections | 17 PauseTotal time.Duration // total pause for all collections |
18 Pause []time.Duration // pause history, most recent first | 18 Pause []time.Duration // pause history, most recent first |
19 PauseQuantiles []time.Duration | 19 PauseQuantiles []time.Duration |
20 } | 20 } |
21 | 21 |
22 // Implemented in package runtime. | 22 // Implemented in package runtime. |
23 func readGCStats(*[]time.Duration) | 23 func readGCStats(*[]time.Duration) |
24 func enableGC(bool) bool | 24 func enableGC(bool) bool |
25 func setGCPercent(int) int | 25 func setGCPercent(int) int |
26 func freeOSMemory() | 26 func freeOSMemory() |
27 func setMaxStack(int) int | |
khr
2013/08/09 22:12:47
Why is this in runtime/debug/garbage.go and not ru
| |
27 | 28 |
28 // ReadGCStats reads statistics about garbage collection into stats. | 29 // ReadGCStats reads statistics about garbage collection into stats. |
29 // The number of entries in the pause history is system-dependent; | 30 // The number of entries in the pause history is system-dependent; |
30 // stats.Pause slice will be reused if large enough, reallocated otherwise. | 31 // stats.Pause slice will be reused if large enough, reallocated otherwise. |
31 // ReadGCStats may use the full capacity of the stats.Pause slice. | 32 // ReadGCStats may use the full capacity of the stats.Pause slice. |
32 // If stats.PauseQuantiles is non-empty, ReadGCStats fills it with quantiles | 33 // If stats.PauseQuantiles is non-empty, ReadGCStats fills it with quantiles |
33 // summarizing the distribution of pause time. For example, if | 34 // summarizing the distribution of pause time. For example, if |
34 // len(stats.PauseQuantiles) is 5, it will be filled with the minimum, | 35 // len(stats.PauseQuantiles) is 5, it will be filled with the minimum, |
35 // 25%, 50%, 75%, and maximum pause times. | 36 // 25%, 50%, 75%, and maximum pause times. |
36 func ReadGCStats(stats *GCStats) { | 37 func ReadGCStats(stats *GCStats) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 return setGCPercent(percent) | 93 return setGCPercent(percent) |
93 } | 94 } |
94 | 95 |
95 // FreeOSMemory forces a garbage collection followed by an | 96 // FreeOSMemory forces a garbage collection followed by an |
96 // attempt to return as much memory to the operating system | 97 // attempt to return as much memory to the operating system |
97 // as possible. (Even if this is not called, the runtime gradually | 98 // as possible. (Even if this is not called, the runtime gradually |
98 // returns memory to the operating system in a background task.) | 99 // returns memory to the operating system in a background task.) |
99 func FreeOSMemory() { | 100 func FreeOSMemory() { |
100 freeOSMemory() | 101 freeOSMemory() |
101 } | 102 } |
103 | |
104 // SetMaxStack sets the maximum amount of memory that | |
105 // can be used by a single goroutine stack. | |
106 // If any goroutine exceeds this limit while growing its stack, | |
107 // the program crashes. | |
108 // SetMaxStack returns the previous setting. | |
109 // The initial setting is 1 GB. | |
110 // | |
111 // SetMaxStack is useful mainly for limiting the damage done by | |
112 // goroutines that enter an infinite recursion. | |
dvyukov
2013/08/10 13:37:18
probably add that it should be called early and do
rsc
2013/08/16 02:33:43
I added "It only limits future stack growth". I do
| |
113 func SetMaxStack(bytes int) int { | |
114 return setMaxStack(bytes) | |
115 } | |
OLD | NEW |