diff options
author | 2018-03-28 16:49:14 -0700 | |
---|---|---|
committer | 2018-03-28 16:51:30 -0700 | |
commit | cccd7185384764a9ad4cd22ff18212602e765c22 (patch) | |
tree | 370c991f187a6cab7f4229b72ced502eaee613fa /src/main/java | |
parent | 81cc4132547d00c2dd3af86537cfb5ffd602b06e (diff) |
Use SpawnResult.getWallTime for test duration if available
Note that the wall time is not always set, especially for cached or remotely executed actions, so we keep the current code around for now.
Progress on #4808.
PiperOrigin-RevId: 190857756
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java index aa83718d33..06cda21feb 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.exec; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.EnvironmentalExecException; @@ -48,6 +49,7 @@ import com.google.devtools.build.lib.view.test.TestStatus.TestResultData; import com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder; import java.io.Closeable; import java.io.IOException; +import java.time.Duration; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -360,7 +362,16 @@ public class StandaloneTestStrategy extends TestStrategy { .addFailedLogs(testLogPath.getPathString()); spawnResults = ImmutableList.of(e.getSpawnResult()); } finally { - long duration = actionExecutionContext.getClock().currentTimeMillis() - startTime; + long endTime = actionExecutionContext.getClock().currentTimeMillis(); + long duration = endTime - startTime; + // If execution fails with an exception other SpawnExecException, there is no result here. + if (!spawnResults.isEmpty()) { + // The SpawnResult of a remotely cached or remotely executed action may not have walltime + // set. We fall back to the time measured here for backwards compatibility. + SpawnResult primaryResult = Iterables.getOnlyElement(spawnResults); + duration = primaryResult.getWallTime().orElse(Duration.ofMillis(duration)).toMillis(); + } + builder.setStartTimeMillisEpoch(startTime); builder.addTestTimes(duration); builder.addTestProcessTimes(duration); |