Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/shared: add 'off' option to setgc #201

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\>)

Expand Down
16 changes: 12 additions & 4 deletions internal/cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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)
Expand Down