Skip to content

Commit

Permalink
Add 'ww debug trace' command.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Nov 14, 2022
1 parent cc40f7b commit 18bed13
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var subcommands = []*cli.Command{
env(),
info(),
profile(),
// trace(),
trace(),
}

func Command() *cli.Command {
Expand Down
14 changes: 0 additions & 14 deletions internal/cmd/debug/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package debug

import (
"bytes"
"errors"
"fmt"
"io"
"os"
"time"

"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -93,15 +91,3 @@ func runPprof() cli.ActionFunc {
}
}
}

func writer(c *cli.Context) (*os.File, error) {
if c.Bool("stdout") {
return os.Stdout, nil
}

if c.IsSet("out") {
return os.Create(c.Path("out"))
}

return nil, errors.New("must pass -out or -stdout")
}
59 changes: 59 additions & 0 deletions internal/cmd/debug/trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package debug

import (
"time"

"github.com/urfave/cli/v2"
)

func trace() *cli.Command {
return &cli.Command{
Name: "trace",
Usage: "perform a runtime trace on a live host",
ArgsUsage: "<peer>",
Flags: []cli.Flag{
&cli.PathFlag{
Name: "out",
Usage: "output file",
},
&cli.DurationFlag{
Name: "duration",
Aliases: []string{"dur"},
Usage: "sampling duration for CPU profile",
Value: time.Second,
},
&cli.BoolFlag{
Name: "stdout",
Aliases: []string{"s"},
Usage: "output samples to stdout",
},
},
Action: runTrace(),
}
}

func runTrace() cli.ActionFunc {
return func(c *cli.Context) error {
// a, release := node.Walk(c.Context, target(c))
// defer release()

// d, release := anchor.Host(a).Debug(c.Context)
// defer release()

// TEST
d, release := node.Debug(c.Context)
defer release()
// -- TEST

tracer, release := d.Tracer(c.Context)
defer release()

w, err := writer(c)
if err != nil {
return err
}
defer w.Close()

return tracer.Sample(c.Context, w, c.Duration("dur"))
}
}
20 changes: 20 additions & 0 deletions internal/cmd/debug/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package debug

import (
"errors"
"os"

"github.com/urfave/cli/v2"
)

func writer(c *cli.Context) (*os.File, error) {
if c.Bool("stdout") {
return os.Stdout, nil
}

if c.IsSet("out") {
return os.Create(c.Path("out"))
}

return nil, errors.New("must pass -out or -stdout")
}

0 comments on commit 18bed13

Please sign in to comment.