-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
84 lines (76 loc) · 1.79 KB
/
main.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//go:build linux
// +build linux
package main
import (
"fmt"
"os"
"syscall"
"github.com/jschwinger233/gofuncgraph/version"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"golang.org/x/sys/unix"
)
func init() {
rlimit := syscall.Rlimit{
Cur: unix.RLIM_INFINITY,
Max: unix.RLIM_INFINITY,
}
if err := syscall.Setrlimit(unix.RLIMIT_MEMLOCK, &rlimit); err != nil {
log.Fatal(err)
}
rlimit = syscall.Rlimit{
Cur: 1048576,
Max: 1048576,
}
if err := syscall.Setrlimit(unix.RLIMIT_NOFILE, &rlimit); err != nil {
log.Fatal(err)
}
}
func main() {
cli.VersionPrinter = func(c *cli.Context) {
fmt.Print(version.String())
}
app := &cli.App{
Name: "gofun",
// TODO@zc: kernel version
Usage: "bpf(2)-based ftrace(1)-like function graph tracer for Go! \n(only non-stripped non-PIE-built Golang ELF on x86-64 little-endian Linux is supported for now)",
UsageText: `See https://github.com/jschwinger233/gofuncgraph for usage examples`,
Version: version.VERSION,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "debug",
Value: false,
Usage: "enable debug logging",
},
&cli.BoolFlag{
Name: "exclude-vendor",
Value: true,
},
&cli.StringSliceFlag{
Name: "uprobe-wildcards",
Required: true,
},
},
Before: func(c *cli.Context) error {
if c.Bool("debug") {
log.SetLevel(log.DebugLevel)
}
return nil
},
Action: func(ctx *cli.Context) (err error) {
bin := ctx.Args().First()
args := ctx.Args().Tail()
if bin == "" || ctx.Bool("help") {
return cli.ShowAppHelp(ctx)
}
tracer, err := NewTracer(bin, ctx.Bool("exclude-vendor"), ctx.StringSlice("uprobe-wildcards"), args)
if err != nil {
return
}
return tracer.Start()
},
}
if err := app.Run(os.Args); err != nil {
log.Fatalf("%+v", err)
}
}