6
6
"os"
7
7
"os/exec"
8
8
"os/signal"
9
+ "os/user"
9
10
"path"
11
+ "runtime"
10
12
"strings"
11
13
"syscall"
12
14
"time"
@@ -33,20 +35,21 @@ func Cli(cfg *config.Config, args []string) error {
33
35
supportedSpies := supportedSpiesWithoutGospy ()
34
36
suggestedCommand := fmt .Sprintf ("pyroscope exec -spy-name %s %s" , supportedSpies [0 ], strings .Join (args , " " ))
35
37
return fmt .Errorf (
36
- "could not automatically find a spy for program \" %s\" . Pass spy name via %s argument, for example: \n %s\n \n Available spies are: %s\n \n If you believe this is a mistake, please submit an issue at %s" ,
38
+ "could not automatically find a spy for program \" %s\" . Pass spy name via %s argument, for example: \n %s\n \n Available spies are: %s\n %s \n If you believe this is a mistake, please submit an issue at %s" ,
37
39
baseName ,
38
40
color .YellowString ("-spy-name" ),
39
41
color .YellowString (suggestedCommand ),
40
42
strings .Join (supportedSpies , "," ),
43
+ armMessage (),
41
44
color .BlueString ("https://github.com/pyroscope-io/pyroscope/issues" ),
42
45
)
43
46
}
44
47
}
45
48
46
49
logrus .Info ("to disable logging from pyroscope, pass " + color .YellowString ("-no-logging" ) + " argument to pyroscope exec" )
47
50
48
- if spyName == "gospy" {
49
- return fmt . Errorf ( "gospy can not profile other processes. See our documentation on using gospy: %s" , color . BlueString ( "https://pyroscope.io/docs/" ))
51
+ if err := performChecks ( spyName ); err != nil {
52
+ return err
50
53
}
51
54
52
55
signal .Ignore (syscall .SIGCHLD )
@@ -97,3 +100,48 @@ func supportedSpiesWithoutGospy() []string {
97
100
98
101
return supportedSpies
99
102
}
103
+
104
+ func performChecks (spyName string ) error {
105
+ if spyName == "gospy" {
106
+ return fmt .Errorf ("gospy can not profile other processes. See our documentation on using gospy: %s" , color .BlueString ("https://pyroscope.io/docs/" ))
107
+ }
108
+
109
+ if runtime .GOOS == "darwin" {
110
+ if ! isRoot () {
111
+ logrus .Error ("on macOS you're required to run the agent with sudo" )
112
+ }
113
+ }
114
+
115
+ if stringsContains (spy .SupportedSpies , spyName ) {
116
+ supportedSpies := supportedSpiesWithoutGospy ()
117
+ return fmt .Errorf (
118
+ "Spy \" %s\" is not supported. Available spies are: %s\n %s" ,
119
+ color .BlueString ("spyName" ),
120
+ strings .Join (supportedSpies , "," ),
121
+ armMessage (),
122
+ )
123
+ }
124
+
125
+ return nil
126
+ }
127
+
128
+ func stringsContains (arr []string , element string ) bool {
129
+ for _ , v := range arr {
130
+ if v == element {
131
+ return true
132
+ }
133
+ }
134
+ return false
135
+ }
136
+
137
+ func isRoot () bool {
138
+ u , err := user .Current ()
139
+ return err == nil && u .Username == "root"
140
+ }
141
+
142
+ func armMessage () string {
143
+ if runtime .GOARCH == "arm64" {
144
+ return "Note that rbspy is not available on arm64 platform"
145
+ }
146
+ return ""
147
+ }
0 commit comments