gops icon indicating copy to clipboard operation
gops copied to clipboard

Migrate gops to use spf13/cobra

Open glibsm opened this issue 3 years ago • 4 comments

Manual command setup was starting to show some strain in terms of documentation and also adding new features (regardless of what the protocol supports currently).

This new setup aims to make it easier to add new documentation and functionality (including tests).

In comparison to the previous version, this increased the binary size by 2.4M.

6.4M gops
4.0M gops_master

❯ go build .
❯ ./gops --help
gops is a tool to list and diagnose Go processes.

Usage:
  gops [flags]
  gops [command]

Examples:
  gops <cmd> <pid|addr> ...
  gops <pid> # displays process info
  gops help  # displays this help message

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  gc          Runs the garbage collector and blocks until successful.
  help        Help about any command
  memstats    Prints the allocation and garbage collection stats.
  pprof-cpu   Reads the CPU profile and launches "go tool pprof".
  pprof-heap  Reads the heap profile and launches "go tool pprof".
  process     Prints information about a Go process.
  setgc       Sets the garbage collection target percentage.
  stack       Prints the stack trace.
  stats       Prints runtime stats.
  trace       Runs the runtime tracer for 5 secs and launches "go tool trace".
  tree        Display parent-child tree for Go processes.
  version     Prints the Go version used to build the program.

Flags:
  -h, --help   help for gops

Use "gops [command] --help" for more information about a command.

glibsm avatar Jun 27 '22 17:06 glibsm

Would it be possible to split this into two commits to simplify review, i.e. one commit just moving the code to internal/cmd and one commit migrating to cobra?

Done. I also moved out a vendor/ commit to reduce the review noise

glibsm avatar Jun 28 '22 16:06 glibsm

Hit the data race in tests, need to figure out if this is something about this PR that triggered it

=== RUN   TestAgentClose
==================
WARNING: DATA RACE
Write at 0x0000007e5940 by goroutine 11:
  github.com/google/gops/agent.Listen()
      /home/runner/work/gops/gops/agent/agent.go:112 +0x218
  github.com/google/gops/agent.TestAgentClose()
      /home/runner/work/gops/gops/agent/agent_test.go:21 +0x97
  testing.tRunner()
      /opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:909 +0x199
Previous read at 0x0000007e5940 by goroutine 10:
  github.com/google/gops/agent.listen()
      /home/runner/work/gops/gops/agent/agent.go:130 +0x7e
Goroutine 11 (running) created at:
  testing.(*T).Run()
      /opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:960 +0x651
  testing.runTests.func1()
      /opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:1202 +0xa6
  testing.tRunner()
      /opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:909 +0x199
  testing.runTests()
      /opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:1200 +0x521
  testing.(*M).Run()
      /opt/hostedtoolcache/go/1.13.15/x64/src/testing/testing.go:1117 +0x2ff
  main.main()
      _testmain.go:54 +0x223

glibsm avatar Jun 29 '22 01:06 glibsm

Hit the data race in tests, need to figure out if this is something about this PR that triggered it

These should be fixed by #174

tklauser avatar Jul 07 '22 08:07 tklauser

Looks like this needs a rebase now that #174 is merged.

tklauser avatar Jul 08 '22 08:07 tklauser