Skip to content

Commit c42ba24

Browse files
committed
spawn log optimize
1 parent c4f4bbe commit c42ba24

4 files changed

Lines changed: 55 additions & 36 deletions

File tree

src/main/java/com/google/devtools/build/lib/analysis/RunfilesSupport.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ public RunfilesTreeImpl(PathFragment execPath, Runfiles runfiles) {
141141
RunfileSymlinksMode.CREATE);
142142
}
143143

144+
@VisibleForTesting
145+
public RunfilesTreeImpl(PathFragment execPath, Runfiles runfiles, boolean cacheMapping) {
146+
this(
147+
execPath,
148+
runfiles,
149+
/* repoMappingManifest= */ null,
150+
/* buildRunfileLinks= */ false,
151+
cacheMapping,
152+
RunfileSymlinksMode.CREATE);
153+
}
154+
144155
@Override
145156
public PathFragment getExecPath() {
146157
return execPath;

src/main/java/com/google/devtools/build/lib/exec/CompactSpawnLogContext.java

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,6 @@ public void logSymlinkAction(AbstractAction action) throws IOException, Interrup
324324
}
325325
}
326326

327-
private static boolean isTestRunnerSpawnMnemonic(String mnemonic) {
328-
return TEST_RUNNER_MNEMONIC.equals(mnemonic)
329-
|| TEST_COVERAGE_POST_PROCESSING_MNEMONIC.equals(mnemonic);
330-
}
331-
332327
/**
333328
* Logs the inputs.
334329
*
@@ -340,11 +335,7 @@ private int logInputs(
340335
throws IOException, InterruptedException {
341336

342337
return logInputSet(
343-
spawn.getInputFiles(),
344-
inputMetadataProvider,
345-
fileSystem,
346-
/* shared= */ false,
347-
isTestRunnerSpawnMnemonic(spawn.getMnemonic()));
338+
spawn.getInputFiles(), inputMetadataProvider, fileSystem, /* shared= */ false);
348339
}
349340

350341
/**
@@ -356,29 +347,22 @@ private int logInputs(
356347
private int logTools(
357348
Spawn spawn, InputMetadataProvider inputMetadataProvider, FileSystem fileSystem)
358349
throws IOException, InterruptedException {
359-
return logInputSet(
360-
spawn.getToolFiles(),
361-
inputMetadataProvider,
362-
fileSystem,
363-
/* shared= */ true,
364-
isTestRunnerSpawnMnemonic(spawn.getMnemonic()));
350+
return logInputSet(spawn.getToolFiles(), inputMetadataProvider, fileSystem, /* shared= */ true);
365351
}
366352

367353
/**
368354
* Logs a nested set.
369355
*
370356
* @param set the nested set
371357
* @param shared whether this nested set is likely to be a transitive member of other sets
372-
* @param isTestRunnerSpawn whether this nested set is logged for a test runner spawn
373358
* @return the entry ID of the {@link ExecLogEntry.InputSet} describing the nested set, or 0 if
374359
* the nested set is empty.
375360
*/
376361
private int logInputSet(
377362
NestedSet<? extends ActionInput> set,
378363
InputMetadataProvider inputMetadataProvider,
379364
FileSystem fileSystem,
380-
boolean shared,
381-
boolean isTestRunnerSpawn)
365+
boolean shared)
382366
throws IOException, InterruptedException {
383367
if (set.isEmpty()) {
384368
return 0;
@@ -392,12 +376,7 @@ private int logInputSet(
392376
for (NestedSet<? extends ActionInput> transitive : set.getNonLeaves()) {
393377
checkState(!transitive.isEmpty());
394378
builder.addTransitiveSetIds(
395-
logInputSet(
396-
transitive,
397-
inputMetadataProvider,
398-
fileSystem,
399-
/* shared= */ true,
400-
isTestRunnerSpawn));
379+
logInputSet(transitive, inputMetadataProvider, fileSystem, /* shared= */ true));
401380
}
402381

403382
for (ActionInput input : set.getLeaves()) {
@@ -409,11 +388,9 @@ private int logInputSet(
409388
runfilesTree,
410389
inputMetadataProvider,
411390
fileSystem,
412-
// Runfiles of non-test spawns are tool inputs and thus potentially reused
413-
// between spawns. Runfiles of test spawns are reused if the test is attempted
414-
// multiple times in the same build; in this case, the runfiles tree caches
415-
// its mapping.
416-
!isTestRunnerSpawn || runfilesTree.isMappingCached()));
391+
// Only share runfiles trees when their mapping is cached; otherwise the
392+
// mapping can vary per spawn and should be treated as unique.
393+
runfilesTree.isMappingCached()));
417394
continue;
418395
}
419396

@@ -583,10 +560,7 @@ private int logRunfilesTree(
583560
fileSystem,
584561
// The runfiles tree itself is shared, but the nested set is unique to the tree as
585562
// it contains the executable.
586-
/* shared= */ false,
587-
// This value only matters for nested sets that may contain runfiles trees, but
588-
// these are never nested.
589-
/* isTestRunnerSpawn= */ false));
563+
/* shared= */ false));
590564
builder.setSymlinksId(
591565
logSymlinkEntries(
592566
runfilesTree.getSymlinksForLogging(), inputMetadataProvider, fileSystem));

src/test/java/com/google/devtools/build/lib/exec/CompactSpawnLogContextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void testRunfilesTreeReusedForTool() throws Exception {
166166
Artifact toolRunfiles = ActionsTestUtil.createRunfilesArtifact(outputDir, "tool.runfiles");
167167

168168
PathFragment runfilesRoot = outputDir.getExecPath().getRelative("foo.runfiles");
169-
RunfilesTree runfilesTree = createRunfilesTree(runfilesRoot, tool);
169+
RunfilesTree runfilesTree = createCachedRunfilesTree(runfilesRoot, tool);
170170

171171
Artifact firstInput = ActionsTestUtil.createArtifact(rootDir, "first_input");
172172
writeFile(firstInput, "def");

src/test/java/com/google/devtools/build/lib/exec/SpawnLogContextTestBase.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,10 +2168,29 @@ protected static RunfilesTree createRunfilesTree(PathFragment root, Artifact...
21682168
return createRunfilesTree(root, ImmutableMap.of(), ImmutableMap.of(), artifacts);
21692169
}
21702170

2171+
protected static RunfilesTree createCachedRunfilesTree(PathFragment root, Artifact... artifacts) {
2172+
return createRunfilesTree(
2173+
root, ImmutableMap.of(), ImmutableMap.of(), /* cacheMapping= */ true, artifacts);
2174+
}
2175+
2176+
protected static RunfilesTree createRunfilesTree(
2177+
PathFragment root, boolean cacheMapping, Artifact... artifacts) {
2178+
return createRunfilesTree(root, ImmutableMap.of(), ImmutableMap.of(), cacheMapping, artifacts);
2179+
}
2180+
2181+
protected static RunfilesTree createRunfilesTree(
2182+
PathFragment root,
2183+
Map<String, Artifact> symlinks,
2184+
Map<String, Artifact> rootSymlinks,
2185+
NestedSet<Artifact> artifacts) {
2186+
return createRunfilesTree(root, symlinks, rootSymlinks, /* cacheMapping= */ false, artifacts);
2187+
}
2188+
21712189
protected static RunfilesTree createRunfilesTree(
21722190
PathFragment root,
21732191
Map<String, Artifact> symlinks,
21742192
Map<String, Artifact> rootSymlinks,
2193+
boolean cacheMapping,
21752194
NestedSet<Artifact> artifacts) {
21762195
Runfiles.Builder runfiles = new Runfiles.Builder(WORKSPACE_NAME);
21772196
runfiles.addTransitiveArtifacts(artifacts);
@@ -2182,18 +2201,33 @@ protected static RunfilesTree createRunfilesTree(
21822201
runfiles.addRootSymlink(PathFragment.create(entry.getKey()), entry.getValue());
21832202
}
21842203
runfiles.setEmptyFilesSupplier(BazelPyBuiltins.GET_INIT_PY_FILES);
2185-
return new RunfilesSupport.RunfilesTreeImpl(root, runfiles.build());
2204+
return new RunfilesSupport.RunfilesTreeImpl(root, runfiles.build(), cacheMapping);
2205+
}
2206+
2207+
protected static RunfilesTree createRunfilesTree(
2208+
PathFragment root,
2209+
Map<String, Artifact> symlinks,
2210+
Map<String, Artifact> rootSymlinks,
2211+
Artifact... artifacts) {
2212+
return createRunfilesTree(
2213+
root,
2214+
symlinks,
2215+
rootSymlinks,
2216+
/* cacheMapping= */ false,
2217+
NestedSetBuilder.wrap(Order.COMPILE_ORDER, Arrays.asList(artifacts)));
21862218
}
21872219

21882220
protected static RunfilesTree createRunfilesTree(
21892221
PathFragment root,
21902222
Map<String, Artifact> symlinks,
21912223
Map<String, Artifact> rootSymlinks,
2224+
boolean cacheMapping,
21922225
Artifact... artifacts) {
21932226
return createRunfilesTree(
21942227
root,
21952228
symlinks,
21962229
rootSymlinks,
2230+
cacheMapping,
21972231
NestedSetBuilder.wrap(Order.COMPILE_ORDER, Arrays.asList(artifacts)));
21982232
}
21992233

0 commit comments

Comments
 (0)