diff options
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/AbstractCriticalPathComponent.java | 42 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java | 5 |
2 files changed, 29 insertions, 18 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 15fb47eca1..1508be60bf 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 @@ -28,6 +28,25 @@ import javax.annotation.Nullable; */ @ThreadCompatible public class AbstractCriticalPathComponent<C extends AbstractCriticalPathComponent<C>> { + /** + * Converts from nanos to millis since the epoch. In particular, note that {@link System#nanoTime} + * does not specify any particular time reference but only notes that returned values are only + * meaningful when taking in relation to each other. + */ + public interface NanosToEpochConverter { + /** Converts from nanos to millis since the epoch. */ + long toEpoch(long timeNanos); + } + + /** + * Creates a {@link NanosToEpochConverter} from clock by taking the current time in millis and the + * current time in nanos to compute the appropriate offset. + */ + public static NanosToEpochConverter fromClock(Clock clock) { + long nowInMillis = clock.currentTimeMillis(); + long nowInNanos = clock.nanoTime(); + return (startNanos) -> nowInMillis - TimeUnit.NANOSECONDS.toMillis((nowInNanos - startNanos)); + } // These two fields are values of BlazeClock.nanoTime() at the relevant points in time. private long startNanos; @@ -113,12 +132,16 @@ public class AbstractCriticalPathComponent<C extends AbstractCriticalPathCompone } } - public long getElapsedTimeMillis() { - return TimeUnit.NANOSECONDS.toMillis(getElapsedTimeNanos()); + public long getStartTimeNanos() { + return startNanos; } - long getStartNanos() { - return startNanos; + public long getStartTimeMillisSinceEpoch(NanosToEpochConverter converter) { + return converter.toEpoch(startNanos); + } + + public Duration getElapsedTime() { + return Duration.ofNanos(getElapsedTimeNanos()); } long getElapsedTimeNanos() { @@ -176,16 +199,5 @@ public class AbstractCriticalPathComponent<C extends AbstractCriticalPathCompone } return currentTime + getActionString(); } - - /** - * When {@code clock} is the same {@link Clock} that was used for computing - * {@link #relativeStartNanos}, it returns the wall time since epoch representing when - * the action was started. - */ - public long getStartWallTimeMillis(Clock clock) { - long millis = clock.currentTimeMillis(); - long nanoElapsed = clock.nanoTime(); - return millis - TimeUnit.NANOSECONDS.toMillis((nanoElapsed - startNanos)); - } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java index 86f11476ee..85c1a47b87 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java @@ -33,7 +33,6 @@ import com.google.devtools.build.lib.profiler.ProfilerTask; import com.google.devtools.build.lib.profiler.SilentCloseable; import com.google.devtools.build.lib.util.Pair; import com.google.protobuf.ByteString; -import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; @@ -119,8 +118,8 @@ public class BuildSummaryStatsModule extends BlazeModule { for (SimpleCriticalPathComponent stat : criticalPath.components().reverse()) { Profiler.instance() .logSimpleTaskDuration( - stat.getStartNanos(), - Duration.ofNanos(stat.getElapsedTimeNanos()), + stat.getStartTimeNanos(), + stat.getElapsedTime(), ProfilerTask.CRITICAL_PATH_COMPONENT, stat.prettyPrintAction()); } |