-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
147 lines (141 loc) · 4.13 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"fmt"
"os"
"os/user"
"github.com/geckoboard/prism/cmd"
"gopkg.in/urfave/cli.v1"
)
func main() {
app := cli.NewApp()
app.Name = "prism"
app.Usage = "profiler injector and analysis tool"
app.Version = "0.0.1"
app.Commands = []cli.Command{
{
Name: "profile",
Usage: "clone go project and inject profiler",
Description: `Create a temp copy of a go project, attach profiler, build and run it.`,
ArgsUsage: "path_to_project",
Action: cmd.ProfileProject,
Flags: []cli.Flag{
cli.StringFlag{
Name: "build-cmd",
Value: "",
Usage: "project build command",
},
cli.StringFlag{
Name: "run-cmd",
Value: `find . -d 1 -type f -name *\.go ! -name *_test\.go -exec go run {} +`,
Usage: "project run command",
},
cli.StringFlag{
Name: "output-dir, o",
Value: os.TempDir(),
Usage: "path for storing patched project version",
},
cli.BoolFlag{
Name: "preserve-output",
Usage: "preserve patched project post build",
},
cli.StringSliceFlag{
Name: "profile-target, t",
Value: &cli.StringSlice{},
Usage: "fully qualified function name to profile",
},
cli.StringFlag{
Name: "profile-dir",
Usage: "specify the output dir for captured profiles",
Value: defaultOutputDir(),
},
cli.StringFlag{
Name: "profile-label",
Usage: `specify a label to be attached to captured profiles and displayed when using the "print" or "diff" commands`,
},
cli.StringSliceFlag{
Name: "profile-vendored-pkg",
Usage: "inject profile hooks to any vendored packages matching this regex. If left unspecified, no vendored packages will be hooked",
Value: &cli.StringSlice{},
},
cli.BoolFlag{
Name: "no-ansi",
Usage: "disable ansi output",
},
},
},
{
Name: "print",
Usage: "pretty-print profile",
Description: ``,
ArgsUsage: "profile",
Action: cmd.PrintProfile,
Flags: []cli.Flag{
cli.StringFlag{
Name: "display-columns, dc",
Value: "total,min,mean,max,invocations",
Usage: fmt.Sprintf("columns to include in the output; supported options: %s", cmd.SupportedColumnNames()),
},
cli.StringFlag{
Name: "display-format, df",
Value: "time",
Usage: "set the format for the output columns containing time values; supported options: time, percent",
},
cli.StringFlag{
Name: "display-unit, du",
Value: "ms",
Usage: "set the unit for the output columns containing time values; supported options: auto, ms, us, ns",
},
cli.Float64Flag{
Name: "display-threshold",
Value: 0.0,
Usage: "only show measurements for entries whose time exceeds the threshold. Unit is the same as --display-unit unless --display-format is set to percent in which case the threshold is applied to the percent value",
},
cli.BoolFlag{
Name: "no-ansi",
Usage: "disable ansi output",
},
},
},
{
Name: "diff",
Usage: "visually compare profiles",
Description: ``,
ArgsUsage: "profile1 profile2 [...profile_n]",
Action: cmd.DiffProfiles,
Flags: []cli.Flag{
cli.StringFlag{
Name: "display-columns,dc",
Value: "total,min,mean,max,invocations",
Usage: fmt.Sprintf("columns to include in the diff output; supported options: %s", cmd.SupportedColumnNames()),
},
cli.StringFlag{
Name: "display-unit, du",
Value: "ms",
Usage: "set the unit for the output columns containing time values; supported options: auto, ms, us, ns",
},
cli.Float64Flag{
Name: "display-threshold",
Value: 0.0,
Usage: "only show measurements for entries whose delta time exceeds the threshold. Unit is the same as --display-unit",
},
cli.BoolFlag{
Name: "no-ansi",
Usage: "disable ansi output",
},
},
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err.Error())
os.Exit(1)
}
}
// Get default output dir for profiles.
func defaultOutputDir() string {
usr, err := user.Current()
if err != nil {
panic(err)
}
return usr.HomeDir + "/prism"
}