diff options
author | 2017-05-08 17:15:57 -0400 | |
---|---|---|
committer | 2017-05-09 10:52:40 -0400 | |
commit | 467973903769c14136dbf545c51a96bda2559449 (patch) | |
tree | c03ac4299cba9ccb49311453b648a63d3971ea42 | |
parent | 69044c06ff876f62faecef90a37d0b0a0b2eae40 (diff) |
Avoid Preconditions failures when formatting messages for Preconditions failures.
PiperOrigin-RevId: 155425839
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/AbstractCriticalPathComponent.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/AbstractCriticalPathComponent.java b/src/main/java/com/google/devtools/build/lib/runtime/AbstractCriticalPathComponent.java index 8c383b2292..6dd019ed26 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/AbstractCriticalPathComponent.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/AbstractCriticalPathComponent.java @@ -122,6 +122,15 @@ public class AbstractCriticalPathComponent<C extends AbstractCriticalPathCompone long getElapsedTimeNanos() { Preconditions.checkState(!isRunning, "Still running %s", this); + return getElapsedTimeNanosNoCheck(); + } + + /** To be used only in debugging: skips state invariance checks to avoid crash-looping. */ + protected long getElapsedTimeMillisNoCheck() { + return TimeUnit.NANOSECONDS.toMillis(getElapsedTimeNanosNoCheck()); + } + + private long getElapsedTimeNanosNoCheck() { return finishNanos - startNanos; } @@ -149,6 +158,12 @@ public class AbstractCriticalPathComponent<C extends AbstractCriticalPathCompone return child; } + /** Returns a string representation of the action. Only for use in crash messages and the like. */ + protected String getActionString() { + Action action = maybeGetAction(); + return (action == null ? "(null action)" : action.prettyPrint()); + } + /** * Returns a human readable representation of the critical path stats with all the details. */ @@ -156,9 +171,9 @@ public class AbstractCriticalPathComponent<C extends AbstractCriticalPathCompone public String toString() { String currentTime = "still running "; if (!isRunning) { - currentTime = String.format("%.2f", getElapsedTimeMillis() / 1000.0) + "s "; + currentTime = String.format("%.2f", getElapsedTimeMillisNoCheck() / 1000.0) + "s "; } - return currentTime + prettyPrintAction(); + return currentTime + getActionString(); } /** |