aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/sandbox
diff options
context:
space:
mode:
authorGravatar ruperts <ruperts@google.com>2017-12-22 18:20:36 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-22 18:22:36 -0800
commita5006998675ef0e4e83b1b938b0f73c112372d93 (patch)
tree2d6eedc6d15924bc2ab572d977a6fbc35e0c0d23 /src/main/java/com/google/devtools/build/lib/sandbox
parentda00941ea78e75cdad15df7fe041bc4de6e1dcfe (diff)
Enable local action execution statistics collection for sandboxed actions that use the DarwinSandboxedSpawnRunner.
In particular, record metrics for user and system CPU execution time, block I/O and involuntary context switches. This feature is guarded behind a new option, --experimental_collect_local_sandbox_action_metrics. RELNOTES: None. PiperOrigin-RevId: 179980734
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/sandbox')
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java84
1 files changed, 50 insertions, 34 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java
index 0e6db5dd92..91b3f2370b 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.sandbox;
import static java.nio.charset.StandardCharsets.UTF_8;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
@@ -233,53 +234,65 @@ final class DarwinSandboxedSpawnRunner extends AbstractSandboxSpawnRunner {
final Path sandboxConfigPath = sandboxPath.getRelative("sandbox.sb");
Duration timeout = policy.getTimeout();
- List<String> arguments = computeCommandLine(spawn, timeout, sandboxConfigPath);
- // TODO(b/62588075): Add execution statistics support for the DarwinSandboxedSpawnRunner.
- Optional<String> statisticsPath = Optional.empty();
-
- Map<String, String> environment =
- localEnvProvider.rewriteLocalEnv(spawn.getEnvironment(), execRoot, tmpDir, productName);
-
- boolean allowNetworkForThisSpawn = allowNetwork || Spawns.requiresNetwork(spawn);
- SandboxedSpawn sandbox = new SymlinkedSandboxedSpawn(
- sandboxPath,
- sandboxExecRoot,
- arguments,
- environment,
- SandboxHelpers.getInputFiles(spawn, policy, execRoot),
- outputs,
- writableDirs) {
- @Override
- public void createFileSystem() throws IOException {
- super.createFileSystem();
- writeConfig(
- sandboxConfigPath, writableDirs, getInaccessiblePaths(), allowNetworkForThisSpawn);
- }
- };
- return runSpawn(spawn, sandbox, policy, execRoot, tmpDir, timeout, statisticsPath);
- }
-
- private List<String> computeCommandLine(Spawn spawn, Duration timeout, Path sandboxConfigPath) {
- List<String> commandLineArgs = new ArrayList<>();
- commandLineArgs.add(SANDBOX_EXEC);
- commandLineArgs.add("-f");
- commandLineArgs.add(sandboxConfigPath.getPathString());
ProcessWrapperUtil.CommandLineBuilder processWrapperCommandLineBuilder =
ProcessWrapperUtil.commandLineBuilder(processWrapper.getPathString(), spawn.getArguments())
.setTimeout(timeout);
+
if (timeoutKillDelay.isPresent()) {
processWrapperCommandLineBuilder.setKillDelay(timeoutKillDelay.get());
}
- commandLineArgs.addAll(processWrapperCommandLineBuilder.build());
- return commandLineArgs;
+
+ final Optional<String> statisticsPath;
+ if (getSandboxOptions().collectLocalSandboxExecutionStatistics) {
+ statisticsPath = Optional.of(sandboxPath.getRelative("stats.out").getPathString());
+ processWrapperCommandLineBuilder.setStatisticsPath(statisticsPath.get());
+ } else {
+ statisticsPath = Optional.empty();
+ }
+
+ ImmutableList<String> commandLine =
+ ImmutableList.<String>builder()
+ .add(SANDBOX_EXEC)
+ .add("-f")
+ .add(sandboxConfigPath.getPathString())
+ .addAll(processWrapperCommandLineBuilder.build())
+ .build();
+
+ Map<String, String> environment =
+ localEnvProvider.rewriteLocalEnv(spawn.getEnvironment(), execRoot, tmpDir, productName);
+
+ boolean allowNetworkForThisSpawn = allowNetwork || Spawns.requiresNetwork(spawn);
+ SandboxedSpawn sandbox =
+ new SymlinkedSandboxedSpawn(
+ sandboxPath,
+ sandboxExecRoot,
+ commandLine,
+ environment,
+ SandboxHelpers.getInputFiles(spawn, policy, execRoot),
+ outputs,
+ writableDirs) {
+ @Override
+ public void createFileSystem() throws IOException {
+ super.createFileSystem();
+ writeConfig(
+ sandboxConfigPath,
+ writableDirs,
+ getInaccessiblePaths(),
+ allowNetworkForThisSpawn,
+ statisticsPath);
+ }
+ };
+ return runSpawn(spawn, sandbox, policy, execRoot, tmpDir, timeout, statisticsPath);
}
private void writeConfig(
Path sandboxConfigPath,
Set<Path> writableDirs,
Set<Path> inaccessiblePaths,
- boolean allowNetwork) throws IOException {
+ boolean allowNetwork,
+ Optional<String> statisticsPath)
+ throws IOException {
try (PrintWriter out =
new PrintWriter(
new BufferedWriter(
@@ -303,6 +316,9 @@ final class DarwinSandboxedSpawnRunner extends AbstractSandboxSpawnRunner {
for (Path path : writableDirs) {
out.println(" (subpath \"" + path.getPathString() + "\")");
}
+ if (statisticsPath.isPresent()) {
+ out.println(" (subpath \"" + statisticsPath + "\")");
+ }
out.println(")");
if (!inaccessiblePaths.isEmpty()) {