1
0
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:
segevda 2023-02-10 12:24:10 +02:00 committed by GitHub
parent 2b6817995c
commit dbeb29cd3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -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\>)

View File

@ -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,9 +127,17 @@ 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)
if err != nil {
return err
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)