aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar ruperts <ruperts@google.com>2017-12-08 14:19:30 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-08 14:21:52 -0800
commitf35c8a0dfb74f7b0d7b292d5a23eb7ce10723954 (patch)
treed4a0a3409e975fa5d12c5d58b78b805cfe1aa52f /src/main/java
parentd899ad535b43b027112213b1ecd7bc0b18938b6e (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
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/ActionResult.java58
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/SpawnResult.java63
2 files changed, 121 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;