diff --git a/core/runtime/src/main/java/io/quarkus/runtime/util/StepTiming.java b/core/runtime/src/main/java/io/quarkus/runtime/util/StepTiming.java index 7d4f4b5c65d22..43142f2f39fc1 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/util/StepTiming.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/util/StepTiming.java @@ -3,6 +3,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.concurrent.TimeUnit; import io.quarkus.runtime.StartupContext; @@ -18,19 +19,22 @@ public static void configureEnabled() { } public static void configureStart() { - stepTimingStart = System.currentTimeMillis(); + stepTimingStart = System.nanoTime(); } public static void printStepTime(StartupContext startupContext) { if (!stepTimingEnabled) { return; } - long stepTimingStop = System.currentTimeMillis(); String currentBuildStepName = startupContext.getCurrentBuildStepName(); System.out.printf("%1$tF %1$tT,%1$tL Build step %2$s completed in: %3$sms%n", - LocalDateTime.ofInstant(Instant.ofEpochMilli(stepTimingStop), ZoneId.systemDefault()), + LocalDateTime.ofInstant(Instant.ofEpochMilli(System.currentTimeMillis()), ZoneId.systemDefault()), currentBuildStepName, - stepTimingStop - stepTimingStart); - stepTimingStart = System.currentTimeMillis(); + duration(System.nanoTime(), stepTimingStart)); + stepTimingStart = System.nanoTime(); + } + + private static long duration(long ended, long started) { + return TimeUnit.MILLISECONDS.convert(ended - started, TimeUnit.NANOSECONDS); } } diff --git a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/Timing.java b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/Timing.java index 0b49df0aed47d..9295104cca85a 100644 --- a/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/Timing.java +++ b/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/Timing.java @@ -3,6 +3,7 @@ import io.quarkus.bootstrap.graal.ImageInfo; import io.quarkus.bootstrap.logging.InitialConfigurator; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.logging.Handler; import org.jboss.logging.Logger; @@ -133,8 +134,8 @@ public static void printStopTime(String name, boolean auxiliaryApplication) { public static BigDecimal convertToBigDecimalSeconds(final long timeNanoSeconds) { final BigDecimal secondsRepresentation = BigDecimal.valueOf(timeNanoSeconds) // As nanoseconds - .divide(BigDecimal.valueOf(1_000_000), BigDecimal.ROUND_HALF_UP) // Convert to milliseconds, discard remaining digits while rounding - .divide(BigDecimal.valueOf(1_000), 3, BigDecimal.ROUND_HALF_UP); // Convert to seconds, while preserving 3 digits + .divide(BigDecimal.valueOf(1_000_000), RoundingMode.HALF_UP) // Convert to milliseconds, discard remaining digits while rounding + .divide(BigDecimal.valueOf(1_000), 3, RoundingMode.HALF_UP); // Convert to seconds, while preserving 3 digits return secondsRepresentation; }