From 09875fe1603307080f3a4172985c5dca3bd9912d Mon Sep 17 00:00:00 2001 From: Duco van Amstel Date: Sun, 18 Nov 2018 17:55:05 +0000 Subject: Update direct dependencies where possible --- vendor/github.com/google/gops/agent/agent.go | 55 +++++++++++++++------- vendor/github.com/google/gops/internal/internal.go | 10 ++++ vendor/github.com/google/gops/signal/signal.go | 3 ++ 3 files changed, 52 insertions(+), 16 deletions(-) (limited to 'vendor/github.com/google/gops') diff --git a/vendor/github.com/google/gops/agent/agent.go b/vendor/github.com/google/gops/agent/agent.go index 57083918..24c0b896 100644 --- a/vendor/github.com/google/gops/agent/agent.go +++ b/vendor/github.com/google/gops/agent/agent.go @@ -7,6 +7,8 @@ package agent import ( + "bufio" + "encoding/binary" "fmt" "io" "io/ioutil" @@ -14,14 +16,13 @@ import ( "os" gosignal "os/signal" "runtime" + "runtime/debug" "runtime/pprof" "runtime/trace" "strconv" "sync" "time" - "bufio" - "github.com/google/gops/internal" "github.com/google/gops/signal" "github.com/kardianos/osext" @@ -43,10 +44,16 @@ type Options struct { // Optional. Addr string - // NoShutdownCleanup tells the agent not to automatically cleanup - // resources if the running process receives an interrupt. + // ConfigDir is the directory to store the configuration file, + // PID of the gops process, filename, port as well as content. + // Optional. + ConfigDir string + + // ShutdownCleanup automatically cleans up resources if the + // running process receives an interrupt. Otherwise, users + // can call Close before shutting down. // Optional. - NoShutdownCleanup bool + ShutdownCleanup bool } // Listen starts the gops agent on a host process. Once agent started, users @@ -58,26 +65,29 @@ type Options struct { // Note: The agent exposes an endpoint via a TCP connection that can be used by // any program on the system. Review your security requirements before starting // the agent. -func Listen(opts *Options) error { +func Listen(opts Options) error { mu.Lock() defer mu.Unlock() - if opts == nil { - opts = &Options{} - } if portfile != "" { return fmt.Errorf("gops: agent already listening at: %v", listener.Addr()) } - gopsdir, err := internal.ConfigDir() - if err != nil { - return err + // new + gopsdir := opts.ConfigDir + if gopsdir == "" { + cfgDir, err := internal.ConfigDir() + if err != nil { + return err + } + gopsdir = cfgDir } - err = os.MkdirAll(gopsdir, os.ModePerm) + + err := os.MkdirAll(gopsdir, os.ModePerm) if err != nil { return err } - if !opts.NoShutdownCleanup { + if opts.ShutdownCleanup { gracefulShutdown() } @@ -165,7 +175,7 @@ func formatBytes(val uint64) string { return fmt.Sprintf("%d bytes", val) } -func handle(conn io.Writer, msg []byte) error { +func handle(conn io.ReadWriter, msg []byte) error { switch msg[0] { case signal.StackTrace: return pprof.Lookup("goroutine").WriteTo(conn, 2) @@ -190,13 +200,20 @@ func handle(conn io.Writer, msg []byte) error { fmt.Fprintf(conn, "heap-objects: %v\n", s.HeapObjects) fmt.Fprintf(conn, "stack-in-use: %v\n", formatBytes(s.StackInuse)) fmt.Fprintf(conn, "stack-sys: %v\n", formatBytes(s.StackSys)) + fmt.Fprintf(conn, "stack-mspan-inuse: %v\n", formatBytes(s.MSpanInuse)) + fmt.Fprintf(conn, "stack-mspan-sys: %v\n", formatBytes(s.MSpanSys)) + fmt.Fprintf(conn, "stack-mcache-inuse: %v\n", formatBytes(s.MCacheInuse)) + fmt.Fprintf(conn, "stack-mcache-sys: %v\n", formatBytes(s.MCacheSys)) + fmt.Fprintf(conn, "other-sys: %v\n", formatBytes(s.OtherSys)) + fmt.Fprintf(conn, "gc-sys: %v\n", formatBytes(s.GCSys)) fmt.Fprintf(conn, "next-gc: when heap-alloc >= %v\n", formatBytes(s.NextGC)) lastGC := "-" if s.LastGC != 0 { lastGC = fmt.Sprint(time.Unix(0, int64(s.LastGC))) } fmt.Fprintf(conn, "last-gc: %v\n", lastGC) - fmt.Fprintf(conn, "gc-pause: %v\n", time.Duration(s.PauseTotalNs)) + fmt.Fprintf(conn, "gc-pause-total: %v\n", time.Duration(s.PauseTotalNs)) + fmt.Fprintf(conn, "gc-pause: %v\n", s.PauseNs[(s.NumGC+255)%256]) fmt.Fprintf(conn, "num-gc: %v\n", s.NumGC) fmt.Fprintf(conn, "enable-gc: %v\n", s.EnableGC) fmt.Fprintf(conn, "debug-gc: %v\n", s.DebugGC) @@ -232,6 +249,12 @@ func handle(conn io.Writer, msg []byte) error { trace.Start(conn) time.Sleep(5 * time.Second) trace.Stop() + case signal.SetGCPercent: + perc, err := binary.ReadVarint(bufio.NewReader(conn)) + if err != nil { + return err + } + fmt.Fprintf(conn, "New GC percent set to %v. Previous value was %v.\n", perc, debug.SetGCPercent(int(perc))) } return nil } diff --git a/vendor/github.com/google/gops/internal/internal.go b/vendor/github.com/google/gops/internal/internal.go index 13828220..80eac63f 100644 --- a/vendor/github.com/google/gops/internal/internal.go +++ b/vendor/github.com/google/gops/internal/internal.go @@ -1,3 +1,7 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package internal import ( @@ -11,7 +15,13 @@ import ( "strings" ) +const gopsConfigDirEnvKey = "GOPS_CONFIG_DIR" + func ConfigDir() (string, error) { + if configDir := os.Getenv(gopsConfigDirEnvKey); configDir != "" { + return configDir, nil + } + if runtime.GOOS == "windows" { return filepath.Join(os.Getenv("APPDATA"), "gops"), nil } diff --git a/vendor/github.com/google/gops/signal/signal.go b/vendor/github.com/google/gops/signal/signal.go index b2bfbe15..c70764a0 100644 --- a/vendor/github.com/google/gops/signal/signal.go +++ b/vendor/github.com/google/gops/signal/signal.go @@ -32,4 +32,7 @@ const ( // BinaryDump returns running binary file. BinaryDump = byte(0x9) + + // SetGCPercent sets the garbage collection target percentage. + SetGCPercent = byte(0x10) ) -- cgit v1.2.3