Skip to content

Commit

Permalink
Merge pull request #20320 from geoand/timing-polish
Browse files Browse the repository at this point in the history
Apply minor timing related polish
  • Loading branch information
Sanne authored Sep 22, 2021
2 parents 8181ed2 + 152d46d commit b97c6a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b97c6a0

Please sign in to comment.