diff --git a/agent/agent.go b/agent/agent.go index 07a3e80..7e5b63b 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -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: diff --git a/internal/cmd/shared.go b/internal/cmd/shared.go index fc11e6b..1b1b19c 100644 --- a/internal/cmd/shared.go +++ b/internal/cmd/shared.go @@ -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 diff --git a/signal/signal.go b/signal/signal.go index c70764a..b414b1d 100644 --- a/signal/signal.go +++ b/signal/signal.go @@ -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) )