|
31 | 31 | import com.google.devtools.build.lib.actions.ActionMiddlemanEvent; |
32 | 32 | import com.google.devtools.build.lib.actions.Artifact; |
33 | 33 | import com.google.devtools.build.lib.actions.CachedActionEvent; |
| 34 | +import com.google.devtools.build.lib.actions.DiscoveredInputsEvent; |
34 | 35 | import com.google.devtools.build.lib.actions.ExecutionGraph; |
35 | 36 | import com.google.devtools.build.lib.actions.RunfilesSupplier; |
36 | 37 | import com.google.devtools.build.lib.actions.Spawn; |
@@ -263,6 +264,17 @@ public void buildComplete(BuildCompleteEvent event) { |
263 | 264 | } |
264 | 265 | } |
265 | 266 | } |
| 267 | + |
| 268 | + /** Records the input discovery time. */ |
| 269 | + @Subscribe |
| 270 | + @AllowConcurrentEvents |
| 271 | + public void discoverInputs(DiscoveredInputsEvent event) { |
| 272 | + ActionDumpWriter localWriter = writer; |
| 273 | + if (localWriter != null) { |
| 274 | + localWriter.enqueue(event); |
| 275 | + } |
| 276 | + } |
| 277 | + |
266 | 278 | /** Record an action that didn't publish any SpawnExecutedEvents. */ |
267 | 279 | @Subscribe |
268 | 280 | @AllowConcurrentEvents |
@@ -401,11 +413,23 @@ private ExecutionGraph.Node toProto(SpawnExecutedEvent event) { |
401 | 413 | SpawnMetrics metrics = spawnResult.getMetrics(); |
402 | 414 | spawnResult = null; |
403 | 415 | long totalMillis = metrics.totalTime().toMillis(); |
| 416 | + |
| 417 | + long discoverInputsMillis = 0; |
| 418 | + ActionInput firstOutput = getFirstOutput(spawn.getResourceOwner(), spawn.getOutputFiles()); |
| 419 | + Duration discoverInputsTime = outputToDiscoverInputsTime.get(firstOutput); |
| 420 | + if (discoverInputsTime != null) { |
| 421 | + // Remove this so we don't count it again later, if an action has multiple spawns. |
| 422 | + outputToDiscoverInputsTime.remove(firstOutput); |
| 423 | + discoverInputsMillis = discoverInputsTime.toMillis(); |
| 424 | + totalMillis += discoverInputsMillis; |
| 425 | + } |
| 426 | + |
404 | 427 | ExecutionGraph.Metrics.Builder metricsBuilder = |
405 | 428 | ExecutionGraph.Metrics.newBuilder() |
406 | 429 | .setStartTimestampMillis(startMillis) |
407 | 430 | .setDurationMillis((int) totalMillis) |
408 | 431 | .setFetchMillis((int) metrics.fetchTime().toMillis()) |
| 432 | + .setDiscoverInputsMillis((int) discoverInputsMillis) |
409 | 433 | .setParseMillis((int) metrics.parseTime().toMillis()) |
410 | 434 | .setProcessMillis((int) metrics.executionWallTime().toMillis()) |
411 | 435 | .setQueueMillis((int) metrics.queueTime().toMillis()) |
@@ -544,6 +568,7 @@ private NodeInfo(int index, long finishMs) { |
544 | 568 | private final BugReporter bugReporter; |
545 | 569 | private final boolean localLockFreeOutputEnabled; |
546 | 570 | private final Map<ActionInput, NodeInfo> outputToNode = new ConcurrentHashMap<>(); |
| 571 | + private final Map<ActionInput, Duration> outputToDiscoverInputsTime = new ConcurrentHashMap<>(); |
547 | 572 | private final DependencyInfo depType; |
548 | 573 | private final AtomicInteger nextIndex = new AtomicInteger(0); |
549 | 574 |
|
@@ -607,6 +632,20 @@ void enqueue(byte[] entry) { |
607 | 632 | blockedMillis.addAndGet(sw.elapsed().toMillis()); |
608 | 633 | } |
609 | 634 |
|
| 635 | + void enqueue(DiscoveredInputsEvent event) { |
| 636 | + // The other times from SpawnMetrics are not needed. The only instance of |
| 637 | + // DiscoveredInputsEvent sets only total and parse time, and to the same value. |
| 638 | + var totalTime = event.getMetrics().totalTime(); |
| 639 | + var firstOutput = getFirstOutput(event.getAction(), event.getAction().getOutputs()); |
| 640 | + var sum = outputToDiscoverInputsTime.get(firstOutput); |
| 641 | + if (sum != null) { |
| 642 | + sum = sum.plus(totalTime); |
| 643 | + } else { |
| 644 | + sum = totalTime; |
| 645 | + } |
| 646 | + outputToDiscoverInputsTime.put(firstOutput, sum); |
| 647 | + } |
| 648 | + |
610 | 649 | void enqueue(Action action, long startMillis) { |
611 | 650 | // This is here just to capture actions which don't have spawns. If we already know about |
612 | 651 | // an output, don't also include it again. |
|
0 commit comments