diff options
author | ruperts <ruperts@google.com> | 2017-12-08 14:19:30 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-12-08 14:21:52 -0800 |
commit | f35c8a0dfb74f7b0d7b292d5a23eb7ce10723954 (patch) | |
tree | d4a0a3409e975fa5d12c5d58b78b805cfe1aa52f | |
parent | d899ad535b43b027112213b1ecd7bc0b18938b6e (diff) |
Add fields to record block I/O and involuntary context switch execution statistics to SpawnResults, and add cumulative getters for these in ActionResults.
RELNOTES: None.
PiperOrigin-RevId: 178426142
3 files changed, 145 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionResult.java b/src/main/java/com/google/devtools/build/lib/actions/ActionResult.java index c2fd3490d9..1db348d9f2 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionResult.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionResult.java @@ -43,6 +43,7 @@ public abstract class ActionResult { * * @param getSpawnResultExecutionTime a selector that returns either the wall, user or system time * for each {@link SpawnResult} being considered + * @return the cumulative time, or empty if no spawn results contained this time */ private Optional<Duration> getCumulativeTime( Function<SpawnResult, Optional<Duration>> getSpawnResultExecutionTime) { @@ -65,6 +66,33 @@ public abstract class ActionResult { } /** + * Returns the cumulative total of long values taken from a series of {@link SpawnResult}s. + * + * @param getSpawnResultLongValue a selector that returns a long value for each {@link + * SpawnResult} being considered + * @return the total, or empty if no spawn results contained this long value + */ + private Optional<Long> getCumulativeLong( + Function<SpawnResult, Optional<Long>> getSpawnResultLongValue) { + Long longTotal = null; + for (SpawnResult spawnResult : spawnResults()) { + Optional<Long> longValue = getSpawnResultLongValue.apply(spawnResult); + if (longValue.isPresent()) { + if (longTotal == null) { + longTotal = longValue.get(); + } else { + longTotal += longValue.get(); + } + } + } + if (longTotal == null) { + return Optional.empty(); + } else { + return Optional.of(longTotal); + } + } + + /** * Returns the cumulative command execution wall time for the {@link Action}. * * @return the cumulative measurement, or empty in case of execution errors or when the @@ -95,6 +123,36 @@ public abstract class ActionResult { } /** + * Returns the cumulative number of block input operations for the {@link Action}. + * + * @return the cumulative measurement, or empty in case of execution errors or when the + * measurement is not implemented for the current platform + */ + public Optional<Long> cumulativeCommandExecutionBlockInputOperations() { + return getCumulativeLong(spawnResult -> spawnResult.getNumBlockInputOperations()); + } + + /** + * Returns the cumulative number of block output operations for the {@link Action}. + * + * @return the cumulative measurement, or empty in case of execution errors or when the + * measurement is not implemented for the current platform + */ + public Optional<Long> cumulativeCommandExecutionBlockOutputOperations() { + return getCumulativeLong(spawnResult -> spawnResult.getNumBlockOutputOperations()); + } + + /** + * Returns the cumulative number of involuntary context switches for the {@link Action}. + * + * @return the cumulative measurement, or empty in case of execution errors or when the + * measurement is not implemented for the current platform + */ + public Optional<Long> cumulativeCommandExecutionInvoluntaryContextSwitches() { + return getCumulativeLong(spawnResult -> spawnResult.getNumInvoluntaryContextSwitches()); + } + + /** * Returns the cumulative command execution CPU time for the {@link Action}. * * @return the cumulative measurement, or empty in case of execution errors or when the diff --git a/src/main/java/com/google/devtools/build/lib/actions/SpawnResult.java b/src/main/java/com/google/devtools/build/lib/actions/SpawnResult.java index 8d8ed46978..51d8d3b645 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/SpawnResult.java +++ b/src/main/java/com/google/devtools/build/lib/actions/SpawnResult.java @@ -151,6 +151,30 @@ public interface SpawnResult { */ Optional<Duration> getSystemTime(); + /** + * Returns the number of block output operations during the {@link Spawn}'s execution. + * + * @return the measurement, or empty in case of execution errors or when the measurement is not + * implemented for the current platform + */ + Optional<Long> getNumBlockOutputOperations(); + + /** + * Returns the number of block input operations during the {@link Spawn}'s execution. + * + * @return the measurement, or empty in case of execution errors or when the measurement is not + * implemented for the current platform + */ + Optional<Long> getNumBlockInputOperations(); + + /** + * Returns the number of involuntary context switches during the {@link Spawn}'s execution. + * + * @return the measurement, or empty in case of execution errors or when the measurement is not + * implemented for the current platform + */ + Optional<Long> getNumInvoluntaryContextSwitches(); + /** Whether the spawn result was a cache hit. */ boolean isCacheHit(); @@ -168,6 +192,9 @@ public interface SpawnResult { private final Optional<Duration> wallTime; private final Optional<Duration> userTime; private final Optional<Duration> systemTime; + private final Optional<Long> numBlockOutputOperations; + private final Optional<Long> numBlockInputOperations; + private final Optional<Long> numInvoluntaryContextSwitches; private final boolean cacheHit; SimpleSpawnResult(Builder builder) { @@ -177,6 +204,9 @@ public interface SpawnResult { this.wallTime = builder.wallTime; this.userTime = builder.userTime; this.systemTime = builder.systemTime; + this.numBlockOutputOperations = builder.numBlockOutputOperations; + this.numBlockInputOperations = builder.numBlockInputOperations; + this.numInvoluntaryContextSwitches = builder.numInvoluntaryContextSwitches; this.cacheHit = builder.cacheHit; } @@ -224,6 +254,21 @@ public interface SpawnResult { } @Override + public Optional<Long> getNumBlockOutputOperations() { + return numBlockOutputOperations; + } + + @Override + public Optional<Long> getNumBlockInputOperations() { + return numBlockInputOperations; + } + + @Override + public Optional<Long> getNumInvoluntaryContextSwitches() { + return numInvoluntaryContextSwitches; + } + + @Override public boolean isCacheHit() { return cacheHit; } @@ -269,6 +314,9 @@ public interface SpawnResult { private Optional<Duration> wallTime = Optional.empty(); private Optional<Duration> userTime = Optional.empty(); private Optional<Duration> systemTime = Optional.empty(); + private Optional<Long> numBlockOutputOperations = Optional.empty(); + private Optional<Long> numBlockInputOperations = Optional.empty(); + private Optional<Long> numInvoluntaryContextSwitches = Optional.empty(); private boolean cacheHit; public SpawnResult build() { @@ -313,6 +361,21 @@ public interface SpawnResult { return this; } + public Builder setNumBlockOutputOperations(long numBlockOutputOperations) { + this.numBlockOutputOperations = Optional.of(numBlockOutputOperations); + return this; + } + + public Builder setNumBlockInputOperations(long numBlockInputOperations) { + this.numBlockInputOperations = Optional.of(numBlockInputOperations); + return this; + } + + public Builder setNumInvoluntaryContextSwitches(long numInvoluntaryContextSwitches) { + this.numInvoluntaryContextSwitches = Optional.of(numInvoluntaryContextSwitches); + return this; + } + public Builder setWallTime(Optional<Duration> wallTime) { this.wallTime = wallTime; return this; diff --git a/src/test/java/com/google/devtools/build/lib/actions/ActionResultTest.java b/src/test/java/com/google/devtools/build/lib/actions/ActionResultTest.java index a5b186aa82..207df55f47 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ActionResultTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ActionResultTest.java @@ -34,6 +34,9 @@ public final class ActionResultTest { assertThat(actionResult.cumulativeCommandExecutionCpuTime()).isEmpty(); assertThat(actionResult.cumulativeCommandExecutionUserTime()).isEmpty(); assertThat(actionResult.cumulativeCommandExecutionSystemTime()).isEmpty(); + assertThat(actionResult.cumulativeCommandExecutionBlockOutputOperations()).isEmpty(); + assertThat(actionResult.cumulativeCommandExecutionBlockInputOperations()).isEmpty(); + assertThat(actionResult.cumulativeCommandExecutionInvoluntaryContextSwitches()).isEmpty(); } @Test @@ -43,6 +46,9 @@ public final class ActionResultTest { .setWallTime(Duration.ofMillis(1984)) .setUserTime(Duration.ofMillis(225)) .setSystemTime(Duration.ofMillis(42)) + .setNumBlockOutputOperations(10) + .setNumBlockInputOperations(20) + .setNumInvoluntaryContextSwitches(30) .setStatus(SpawnResult.Status.SUCCESS) .build(); List<SpawnResult> spawnResults = ImmutableList.of(spawnResult); @@ -51,6 +57,9 @@ public final class ActionResultTest { assertThat(actionResult.cumulativeCommandExecutionCpuTime()).hasValue(Duration.ofMillis(267)); assertThat(actionResult.cumulativeCommandExecutionUserTime()).hasValue(Duration.ofMillis(225)); assertThat(actionResult.cumulativeCommandExecutionSystemTime()).hasValue(Duration.ofMillis(42)); + assertThat(actionResult.cumulativeCommandExecutionBlockOutputOperations()).hasValue(10L); + assertThat(actionResult.cumulativeCommandExecutionBlockInputOperations()).hasValue(20L); + assertThat(actionResult.cumulativeCommandExecutionInvoluntaryContextSwitches()).hasValue(30L); } @Test @@ -60,6 +69,9 @@ public final class ActionResultTest { .setWallTime(Duration.ofMillis(1979)) .setUserTime(Duration.ofMillis(1)) .setSystemTime(Duration.ofMillis(33)) + .setNumBlockOutputOperations(10) + .setNumBlockInputOperations(20) + .setNumInvoluntaryContextSwitches(30) .setStatus(SpawnResult.Status.SUCCESS) .build(); SpawnResult spawnResult2 = @@ -67,6 +79,9 @@ public final class ActionResultTest { .setWallTime(Duration.ofMillis(4)) .setUserTime(Duration.ofMillis(1)) .setSystemTime(Duration.ofMillis(7)) + .setNumBlockOutputOperations(100) + .setNumBlockInputOperations(200) + .setNumInvoluntaryContextSwitches(300) .setStatus(SpawnResult.Status.SUCCESS) .build(); SpawnResult spawnResult3 = @@ -74,6 +89,9 @@ public final class ActionResultTest { .setWallTime(Duration.ofMillis(1)) .setUserTime(Duration.ofMillis(2)) .setSystemTime(Duration.ofMillis(2)) + .setNumBlockOutputOperations(1000) + .setNumBlockInputOperations(2000) + .setNumInvoluntaryContextSwitches(3000) .setStatus(SpawnResult.Status.SUCCESS) .build(); List<SpawnResult> spawnResults = ImmutableList.of(spawnResult1, spawnResult2, spawnResult3); @@ -82,6 +100,9 @@ public final class ActionResultTest { assertThat(actionResult.cumulativeCommandExecutionCpuTime()).hasValue(Duration.ofMillis(46)); assertThat(actionResult.cumulativeCommandExecutionUserTime()).hasValue(Duration.ofMillis(4)); assertThat(actionResult.cumulativeCommandExecutionSystemTime()).hasValue(Duration.ofMillis(42)); + assertThat(actionResult.cumulativeCommandExecutionBlockOutputOperations()).hasValue(1110L); + assertThat(actionResult.cumulativeCommandExecutionBlockInputOperations()).hasValue(2220L); + assertThat(actionResult.cumulativeCommandExecutionInvoluntaryContextSwitches()).hasValue(3330L); } @Test @@ -98,6 +119,9 @@ public final class ActionResultTest { assertThat(actionResult.cumulativeCommandExecutionCpuTime()).isEmpty(); assertThat(actionResult.cumulativeCommandExecutionUserTime()).isEmpty(); assertThat(actionResult.cumulativeCommandExecutionSystemTime()).isEmpty(); + assertThat(actionResult.cumulativeCommandExecutionBlockOutputOperations()).isEmpty(); + assertThat(actionResult.cumulativeCommandExecutionBlockInputOperations()).isEmpty(); + assertThat(actionResult.cumulativeCommandExecutionInvoluntaryContextSwitches()).isEmpty(); } @Test |