@@ -10,8 +10,6 @@ package main
10
10
11
11
import (
12
12
"fmt"
13
- "github.com/martian-lang/martian/martian/core"
14
- "github.com/martian-lang/martian/martian/util"
15
13
"os"
16
14
"os/exec"
17
15
"path"
@@ -20,6 +18,10 @@ import (
20
18
"strings"
21
19
"syscall"
22
20
"time"
21
+
22
+ "github.com/google/shlex"
23
+ "github.com/martian-lang/martian/martian/core"
24
+ "github.com/martian-lang/martian/martian/util"
23
25
)
24
26
25
27
const HeartbeatInterval = time .Minute * 2
@@ -280,28 +282,42 @@ func (self *runner) startProfile() error {
280
282
strconv .Itoa (self .job .Process .Pid ),
281
283
)
282
284
case core .PerfRecordProfile :
283
- events := os .Getenv ("MRO_PERF_EVENTS" )
284
- if events == "" {
285
- events = "task-clock"
286
- }
287
- freq := os .Getenv ("MRO_PERF_FREQ" )
288
- if freq == "" {
289
- freq = "200"
290
- }
291
- duration := os .Getenv ("MRO_PERF_DURATION" )
292
- if duration == "" {
293
- duration = "2400"
294
- }
295
285
journaledFiles = []core.MetadataFileName {core .PerfData }
296
- // Running perf record for 2400 seconds (40 minutes) with these default
297
- // settings will produce about 26MB per thread/process.
298
- cmd = exec .Command ("perf" ,
299
- "record" , "-g" , "-F" , freq ,
300
- "-o" , self .metadata .MetadataFilePath (journaledFiles [0 ]),
301
- "-e" , events ,
302
- "-p" , strconv .Itoa (self .job .Process .Pid ),
303
- "sleep" , duration ,
304
- )
286
+ if perfArgs := os .Getenv ("MRO_PERF_ARGS" ); perfArgs != "" {
287
+ if args , err := shlex .Split (perfArgs ); err != nil {
288
+ util .PrintError (err , "profile" , "Error parsing perf args" )
289
+ return nil
290
+ } else {
291
+ baseArgs := []string {
292
+ "record" ,
293
+ "-p" , strconv .Itoa (self .job .Process .Pid ),
294
+ "-o" , self .metadata .MetadataFilePath (journaledFiles [0 ]),
295
+ }
296
+ cmd = exec .Command ("perf" , append (baseArgs , args ... )... )
297
+ }
298
+ } else {
299
+ events := os .Getenv ("MRO_PERF_EVENTS" )
300
+ if events == "" {
301
+ events = "task-clock"
302
+ }
303
+ freq := os .Getenv ("MRO_PERF_FREQ" )
304
+ if freq == "" {
305
+ freq = "200"
306
+ }
307
+ duration := os .Getenv ("MRO_PERF_DURATION" )
308
+ if duration == "" {
309
+ duration = "2400"
310
+ }
311
+ // Running perf record for 2400 seconds (40 minutes) with these default
312
+ // settings will produce about 26MB per thread/process.
313
+ cmd = exec .Command ("perf" ,
314
+ "record" , "-g" , "-F" , freq ,
315
+ "-o" , self .metadata .MetadataFilePath (journaledFiles [0 ]),
316
+ "-e" , events ,
317
+ "-p" , strconv .Itoa (self .job .Process .Pid ),
318
+ "sleep" , duration ,
319
+ )
320
+ }
305
321
default :
306
322
return nil
307
323
}
0 commit comments