Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Comment on lines +211 to +212
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a new command, would there be a way to pass the debug argument to the agent as part of the existing signal.StackTrace command? If this is not possible in a backwards-compatible way, I'd suggest instead to add a new more generic command which allows to pass the debug value as part of the command invocation, so users could e.g. use debug=0 to write in compressed format.

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)
)