diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ExecutionGraphModule.java b/src/main/java/com/google/devtools/build/lib/runtime/ExecutionGraphModule.java index d3bf5d9a5d923c..222dcfcbc1998d 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/ExecutionGraphModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/ExecutionGraphModule.java @@ -187,8 +187,7 @@ public DependencyInfoConverter() { private ActionDumpWriter writer; private CommandEnvironment env; private WalkableGraph graph; - private NanosToMillisSinceEpochConverter nanosToMillis = - BlazeClock.createNanosToMillisSinceEpochConverter(); + private NanosToMillisSinceEpochConverter nanosToMillis; // Only relevant for Skymeld: there may be multiple events and we only count the first one. private final AtomicBoolean executionStarted = new AtomicBoolean(); @@ -210,13 +209,20 @@ void setGraph(WalkableGraph graph) { } @VisibleForTesting - void setNanosToMillis(NanosToMillisSinceEpochConverter nanosToMillis) { - this.nanosToMillis = nanosToMillis; + void resetNanosToMillis() { + this.nanosToMillis = BlazeClock.createNanosToMillisSinceEpochConverter(); + } + + @VisibleForTesting + NanosToMillisSinceEpochConverter getNanosToMillis() { + return nanosToMillis; } @Override public void beforeCommand(CommandEnvironment env) { this.env = env; + // The offset between monotonic and wall clock time may change between commands. + resetNanosToMillis(); if (env.getCommand().buildPhase().executes()) { ExecutionGraphOptions options = diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ExecutionGraphModuleTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ExecutionGraphModuleTest.java index 4d55603a8bdff6..8a263b900e80d0 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/ExecutionGraphModuleTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/ExecutionGraphModuleTest.java @@ -54,7 +54,6 @@ import com.google.devtools.build.lib.buildtool.BuildResult; import com.google.devtools.build.lib.buildtool.BuildResult.BuildToolLogCollection; import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent; -import com.google.devtools.build.lib.clock.BlazeClock; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.exec.util.FakeActionInputFileCache; @@ -96,6 +95,7 @@ public class ExecutionGraphModuleTest extends FoundationTestCase { @Before public void createModule() { module = new ExecutionGraphModule(); + module.resetNanosToMillis(); } @Before @@ -671,8 +671,6 @@ public void spawnAndAction_withSameOutputs() throws Exception { public void spawnAndAction_withDifferentOutputs() throws Exception { var buffer = new ByteArrayOutputStream(); startLogging(eventBus, UUID.randomUUID(), buffer, DependencyInfo.ALL); - var nanosToMillis = BlazeClock.createNanosToMillisSinceEpochConverter(); - module.setNanosToMillis(nanosToMillis); module.spawnExecuted( new SpawnExecutedEvent( @@ -705,7 +703,7 @@ public void spawnAndAction_withDifferentOutputs() throws Exception { .setIndex(1) .setMetrics( ExecutionGraph.Metrics.newBuilder() - .setStartTimestampMillis(nanosToMillis.toEpochMillis(0))) + .setStartTimestampMillis(module.getNanosToMillis().toEpochMillis(0))) .setRuleClass("dummy-kind") .build()); } @@ -714,8 +712,6 @@ public void spawnAndAction_withDifferentOutputs() throws Exception { public void noSpawnAction_hasCorrectDuration() throws Exception { var buffer = new ByteArrayOutputStream(); startLogging(eventBus, UUID.randomUUID(), buffer, DependencyInfo.ALL); - var nanosToMillis = BlazeClock.createNanosToMillisSinceEpochConverter(); - module.setNanosToMillis(nanosToMillis); var action = new ActionsTestUtil.NullAction(createOutputArtifact("foo/out")); module.actionComplete( @@ -727,7 +723,7 @@ public void noSpawnAction_hasCorrectDuration() throws Exception { executionGraphNodeBuilderForAction(action) .setMetrics( ExecutionGraph.Metrics.newBuilder() - .setStartTimestampMillis(nanosToMillis.toEpochMillis(1000000)) + .setStartTimestampMillis(module.getNanosToMillis().toEpochMillis(1000000)) .setDurationMillis(1) .setProcessMillis(1)) .setRuleClass("dummy-kind")