Skip to content

Commit

Permalink
Use proper timing method in step timing
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Sep 22, 2021
1 parent a3d319c commit 152d46d
Showing 1 changed file with 9 additions and 5 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);
}
}

0 comments on commit 152d46d

Please sign in to comment.