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
|
||||
$ gops setgc (<pid>|<addr>) 10
|
||||
```
|
||||
The following command turns off the garbage collector:
|
||||
|
||||
```sh
|
||||
$ gops setgc (<pid>|<addr>) off
|
||||
```
|
||||
|
||||
#### $ gops version (\<pid\>|\<addr\>)
|
||||
|
||||
|
@ -43,7 +43,7 @@ func AgentCommands() []*cobra.Command {
|
||||
},
|
||||
{
|
||||
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,
|
||||
},
|
||||
{
|
||||
@ -127,10 +127,18 @@ func setGC(addr net.TCPAddr, params []string) error {
|
||||
if len(params) != 1 {
|
||||
return errors.New("missing gc percentage")
|
||||
}
|
||||
perc, err := strconv.ParseInt(params[0], 10, strconv.IntSize)
|
||||
var (
|
||||
perc int64
|
||||
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)
|
||||
binary.PutVarint(buf, perc)
|
||||
return cmdWithPrint(addr, signal.SetGCPercent, buf...)
|
||||
|
Loading…
Reference in New Issue
Block a user