aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/actions
diff options
context:
space:
mode:
authorGravatar ruperts <ruperts@google.com>2017-12-01 15:55:38 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-01 15:57:50 -0800
commit26bc282dab0cee2c42836e202fcd6643c95e370c (patch)
tree6fc5e624c1dbb21b2c691b96b64ae4b3537bd3f3 /src/main/java/com/google/devtools/build/lib/actions
parentdec03295e7e65c6a86fb60f02358c98cf499eefb (diff)
Add user and system execution time to provide total CPU execution time for each Action.
RELNOTES: None. PiperOrigin-RevId: 177652741
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/actions')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/ActionResult.java24
1 files changed, 24 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 0b8fa0143d..c2fd3490d9 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
@@ -14,6 +14,8 @@
package com.google.devtools.build.lib.actions;
+import static com.google.common.base.Preconditions.checkState;
+
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import java.time.Duration;
@@ -92,6 +94,28 @@ public abstract class ActionResult {
return getCumulativeTime(spawnResult -> spawnResult.getSystemTime());
}
+ /**
+ * 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
+ * measurement is not implemented for the current platform
+ */
+ public Optional<Duration> cumulativeCommandExecutionCpuTime() {
+ Optional<Duration> userTime = cumulativeCommandExecutionUserTime();
+ Optional<Duration> systemTime = cumulativeCommandExecutionSystemTime();
+
+ if (!userTime.isPresent() && !systemTime.isPresent()) {
+ return Optional.empty();
+ } else if (userTime.isPresent() && !systemTime.isPresent()) {
+ return userTime;
+ } else if (!userTime.isPresent() && systemTime.isPresent()) {
+ return systemTime;
+ } else {
+ checkState(userTime.isPresent() && systemTime.isPresent());
+ return Optional.of(userTime.get().plus(systemTime.get()));
+ }
+ }
+
/** Creates an ActionResult given a list of SpawnResults. */
public static ActionResult create(List<SpawnResult> spawnResults) {
if (spawnResults == null) {