1
0
mirror of https://github.com/google/gops.git synced 2025-07-03 23:50:26 +02:00

add -version

This commit is contained in:
Jaana Burcu Dogan
2016-11-03 22:53:07 -07:00
parent 5cc8e840d5
commit f9f22cc06a
3 changed files with 13 additions and 4 deletions

View File

@ -64,6 +64,9 @@ func handle(conn net.Conn, msg []byte) error {
fmt.Fprintf(conn, "Last GC: %v ago\n", time.Now().Sub(stats.LastGC))
fmt.Fprintf(conn, "Total pause: %v\n", stats.PauseTotal)
}
case signal.Version:
fmt.Fprintf(conn, "%v\n", runtime.Version())
}
return nil
}

View File

@ -13,4 +13,7 @@ const (
// GCStats prints GC stats.
GCStats = byte(0x3)
// Version prints the Go version.
Version = byte(0x4)
)

11
gops.go
View File

@ -27,6 +27,7 @@ Options: (All requires the agent and the -p=<pid> flag.)
-stack Prints the stack trace.
-gc Runs the garbage collector and blocks until successful.
-gcstats Prints the garbage collection stats.
-version Prints the Go version used to build the program.
`
var (
@ -34,6 +35,7 @@ var (
stack = flag.Bool("stack", false, "")
gc = flag.Bool("gc", false, "")
gcstats = flag.Bool("gcstats", false, "")
version = flag.Bool("version", false, "")
help = flag.Bool("help", false, "")
)
@ -52,24 +54,25 @@ func main() {
if *help {
usage()
}
if *stack {
out, err := cmd(signal.Stack)
exit(err)
fmt.Println(out)
}
if *gc {
_, err := cmd(signal.GC)
exit(err)
}
if *gcstats {
out, err := cmd(signal.GCStats)
exit(err)
fmt.Printf(out)
}
if *version {
out, err := cmd(signal.Version)
exit(err)
fmt.Printf(out)
}
}
func cmd(c byte) (string, error) {