Skip to content

Commit

Permalink
add stack-legacy command to dump call traces in legacy format
Browse files Browse the repository at this point in the history
Unfortunately legacy format is more helpful in debug as it dumps
goroutine labels. 'gops stack' doesn't dump them.

Golang issue: golang/go#63712
  • Loading branch information
xaurx committed Oct 24, 2023
1 parent 582fc28 commit 4b85e90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions signal/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

0 comments on commit 4b85e90

Please sign in to comment.