mirror of
https://github.com/google/gops.git
synced 2024-11-19 20:31:58 +02:00
cmd/shared: add 'off' option to setgc (#201)
To stop GC completely, debug.SetGCPercentage needs to receive a negative integer. Passing a negative integer is cumbersome: $ gops setgc <pid> -- -1 This commit adds a more user-friendly way to achieve that: $ gops setgc <pid> off This behavior is aligned with that of the GOGC env variable, where negative or "off" can be set to stop the GC.
This commit is contained in:
parent
2b6817995c
commit
dbeb29cd3e
@ -189,6 +189,11 @@ The following command sets it to 10%:
|
|||||||
``` sh
|
``` sh
|
||||||
$ gops setgc (<pid>|<addr>) 10
|
$ gops setgc (<pid>|<addr>) 10
|
||||||
```
|
```
|
||||||
|
The following command turns off the garbage collector:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ gops setgc (<pid>|<addr>) off
|
||||||
|
```
|
||||||
|
|
||||||
#### $ gops version (\<pid\>|\<addr\>)
|
#### $ gops version (\<pid\>|\<addr\>)
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ func AgentCommands() []*cobra.Command {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "setgc",
|
name: "setgc",
|
||||||
short: "Sets the garbage collection target percentage.",
|
short: "Sets the garbage collection target percentage. To completely stop GC, set to 'off'",
|
||||||
fn: setGC,
|
fn: setGC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -127,9 +127,17 @@ func setGC(addr net.TCPAddr, params []string) error {
|
|||||||
if len(params) != 1 {
|
if len(params) != 1 {
|
||||||
return errors.New("missing gc percentage")
|
return errors.New("missing gc percentage")
|
||||||
}
|
}
|
||||||
perc, err := strconv.ParseInt(params[0], 10, strconv.IntSize)
|
var (
|
||||||
if err != nil {
|
perc int64
|
||||||
return err
|
err error
|
||||||
|
)
|
||||||
|
if strings.ToLower(params[0]) == "off" {
|
||||||
|
perc = -1
|
||||||
|
} else {
|
||||||
|
perc, err = strconv.ParseInt(params[0], 10, strconv.IntSize)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buf := make([]byte, binary.MaxVarintLen64)
|
buf := make([]byte, binary.MaxVarintLen64)
|
||||||
binary.PutVarint(buf, perc)
|
binary.PutVarint(buf, perc)
|
||||||
|
Loading…
Reference in New Issue
Block a user