-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.go
More file actions
53 lines (49 loc) · 1.39 KB
/
tree.go
File metadata and controls
53 lines (49 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"os"
"regexp"
"github.com/spf13/cobra"
)
func newTreeCmd() *cobra.Command {
var shared sharedFlags
var method string
var depth int
var minPct float64
var hide string
cmd := &cobra.Command{
Use: "tree <file>",
Short: "Call tree descending from a method (optional -m; shows all if omitted)",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
pctx, err := preprocessProfile(shared.toOpts(args[0], "tree"))
if err != nil {
return err
}
sf := pctx.sf
if hide != "" {
re, err := regexp.Compile(hide)
if err != nil {
return fmt.Errorf("invalid --hide regex: %v", err)
}
sf = sf.hideFrames(re)
}
cmdTree(sf, method, depth, minPct)
return nil
},
}
shared.register(cmd)
cmd.Flags().StringVarP(&method, "method", "m", "", "Substring match on method name")
cmd.Flags().IntVar(&depth, "depth", 4, "Max depth")
cmd.Flags().Float64Var(&minPct, "min-pct", 1.0, "Hide nodes below this %")
cmd.Flags().StringVar(&hide, "hide", "", "Remove matching frames before analysis (regex)")
return cmd
}
func cmdTree(sf *stackFile, method string, maxDepth int, minPct float64) {
if sf.totalSamples == 0 {
fmt.Fprintln(os.Stdout, "no samples (empty profile or all filtered out)")
return
}
pt := buildTreePT(sf, method)
pt.fprintTree(os.Stdout, sf, treeDisplayMethod(method), maxDepth, minPct, true)
}