diff --git a/agent/agent.go b/agent/agent.go index 07200c8..3083222 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -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 } diff --git a/agent/signal/signal.go b/agent/signal/signal.go index 6f54daf..bc46b92 100644 --- a/agent/signal/signal.go +++ b/agent/signal/signal.go @@ -13,4 +13,7 @@ const ( // GCStats prints GC stats. GCStats = byte(0x3) + + // Version prints the Go version. + Version = byte(0x4) ) diff --git a/gops.go b/gops.go index 824fa02..6a7bef7 100644 --- a/gops.go +++ b/gops.go @@ -27,6 +27,7 @@ Options: (All requires the agent and the -p= 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) {