Skip to content

Commit 049a182

Browse files
committed
Add MRO_PERF_ARGS environement variable.
This is a mutually-exclusive alternative to MRO_PERF_EVENTS, MRO_PERF_FREQ, and MRO_PERF_DURATION which gives full control over the perf command line (except for -p and -o). Setting MRO_PERF_ARGS="-e <event> -F <freq> sleep <dur>" is equivalent to using the previous options and setting MRO_PERF_EVENTS=<event>, MRO_PERF_FREQ=<freq>, and MRO_PERF_DURATION=<dur>.
1 parent f1167be commit 049a182

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
[submodule "src/vendor/golang.org/x/sys"]
1717
path = vendor/golang.org/x/sys
1818
url = https://github.com/golang/sys
19+
[submodule "vendor/github.com/google/shlex"]
20+
path = vendor/github.com/google/shlex
21+
url = https://github.com/google/shlex.git

cmd/mrjob/mrjob.go

+39-23
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ package main
1010

1111
import (
1212
"fmt"
13-
"github.com/martian-lang/martian/martian/core"
14-
"github.com/martian-lang/martian/martian/util"
1513
"os"
1614
"os/exec"
1715
"path"
@@ -20,6 +18,10 @@ import (
2018
"strings"
2119
"syscall"
2220
"time"
21+
22+
"github.com/google/shlex"
23+
"github.com/martian-lang/martian/martian/core"
24+
"github.com/martian-lang/martian/martian/util"
2325
)
2426

2527
const HeartbeatInterval = time.Minute * 2
@@ -280,28 +282,42 @@ func (self *runner) startProfile() error {
280282
strconv.Itoa(self.job.Process.Pid),
281283
)
282284
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-
}
295285
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+
}
305321
default:
306322
return nil
307323
}

vendor/github.com/google/shlex

Submodule shlex added at 6f45313

0 commit comments

Comments
 (0)