1
0
mirror of https://github.com/google/gops.git synced 2024-11-24 08:22:25 +02:00

add stack-legacy command to dump call traces in legacy format

Unfortunately legacy format is more helpful in debug as it dumps
goroutine labels. 'gops stack' doesn't dump them.

Golang issue: https://github.com/golang/go/issues/63712
This commit is contained in:
Alex Lyashko 2023-10-24 14:11:08 -04:00
parent 582fc2828e
commit 4b85e90101
3 changed files with 14 additions and 0 deletions

View File

@ -208,6 +208,8 @@ func formatBytes(val uint64) string {
func handle(conn io.ReadWriter, msg []byte) error {
switch msg[0] {
case signal.StackTraceLegacy:
return pprof.Lookup("goroutine").WriteTo(conn, 1)
case signal.StackTrace:
return pprof.Lookup("goroutine").WriteTo(conn, 2)
case signal.GC:

View File

@ -35,6 +35,11 @@ func AgentCommands() []*cobra.Command {
short: "Prints the stack trace.",
fn: stackTrace,
},
{
name: "stack-legacy",
short: "Prints the stack trace in legacy mode but with labels.",
fn: stackTraceLegacy,
},
{
name: "gc",
short: "Runs the garbage collector and blocks until successful.",
@ -147,6 +152,10 @@ func stackTrace(addr net.TCPAddr, _ []string) error {
return cmdWithPrint(addr, signal.StackTrace)
}
func stackTraceLegacy(addr net.TCPAddr, _ []string) error {
return cmdWithPrint(addr, signal.StackTraceLegacy)
}
func gc(addr net.TCPAddr, _ []string) error {
_, err := cmd(addr, signal.GC)
return err

View File

@ -35,4 +35,7 @@ const (
// SetGCPercent sets the garbage collection target percentage.
SetGCPercent = byte(0x10)
// StackTraceLegacy represents a command to print stack trace in a legacy format (but it includes labels).
StackTraceLegacy = byte(0x11)
)