1
0
mirror of https://github.com/google/gops.git synced 2025-06-30 23:44:50 +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, "Last GC: %v ago\n", time.Now().Sub(stats.LastGC))
fmt.Fprintf(conn, "Total pause: %v\n", stats.PauseTotal) fmt.Fprintf(conn, "Total pause: %v\n", stats.PauseTotal)
} }
case signal.Version:
fmt.Fprintf(conn, "%v\n", runtime.Version())
} }
return nil return nil
} }

View File

@ -13,4 +13,7 @@ const (
// GCStats prints GC stats. // GCStats prints GC stats.
GCStats = byte(0x3) 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. -stack Prints the stack trace.
-gc Runs the garbage collector and blocks until successful. -gc Runs the garbage collector and blocks until successful.
-gcstats Prints the garbage collection stats. -gcstats Prints the garbage collection stats.
-version Prints the Go version used to build the program.
` `
var ( var (
@ -34,6 +35,7 @@ var (
stack = flag.Bool("stack", false, "") stack = flag.Bool("stack", false, "")
gc = flag.Bool("gc", false, "") gc = flag.Bool("gc", false, "")
gcstats = flag.Bool("gcstats", false, "") gcstats = flag.Bool("gcstats", false, "")
version = flag.Bool("version", false, "")
help = flag.Bool("help", false, "") help = flag.Bool("help", false, "")
) )
@ -52,24 +54,25 @@ func main() {
if *help { if *help {
usage() usage()
} }
if *stack { if *stack {
out, err := cmd(signal.Stack) out, err := cmd(signal.Stack)
exit(err) exit(err)
fmt.Println(out) fmt.Println(out)
} }
if *gc { if *gc {
_, err := cmd(signal.GC) _, err := cmd(signal.GC)
exit(err) exit(err)
} }
if *gcstats { if *gcstats {
out, err := cmd(signal.GCStats) out, err := cmd(signal.GCStats)
exit(err) exit(err)
fmt.Printf(out) fmt.Printf(out)
} }
if *version {
out, err := cmd(signal.Version)
exit(err)
fmt.Printf(out)
}
} }
func cmd(c byte) (string, error) { func cmd(c byte) (string, error) {