From b5a39e4ef21697d87c073f8437709390a72c1d15 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 23 Jul 2024 12:14:39 +0300 Subject: [PATCH] Apply minor polish to BuildAnalyticsProvider * Use final fields * Simplify map population of data * Use nanoTime instead of currentTimeMillis --- .../io/quarkus/maven/BuildAnalyticsProvider.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/BuildAnalyticsProvider.java b/devtools/maven/src/main/java/io/quarkus/maven/BuildAnalyticsProvider.java index ee33134dacba8..8ed5a399f7fcb 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/BuildAnalyticsProvider.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/BuildAnalyticsProvider.java @@ -5,6 +5,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.function.Function; import javax.inject.Inject; @@ -25,9 +26,9 @@ @Named public class BuildAnalyticsProvider { - private RuntimeInformation runtimeInformation; + private final RuntimeInformation runtimeInformation; - private AnalyticsService analyticsService; + private final AnalyticsService analyticsService; private Log log; @@ -41,18 +42,21 @@ public void sendAnalytics(TrackEventType trackEventType, ApplicationModel applicationModel, Map graalVMInfo, File localBuildDir) { - final long start = System.currentTimeMillis(); + final long start = System.nanoTime(); - final Map buildInfo = new HashMap<>(); - buildInfo.putAll(graalVMInfo); + final Map buildInfo = new HashMap<>(graalVMInfo); buildInfo.put(MAVEN_VERSION, runtimeInformation.getMavenVersion()); analyticsService.sendAnalytics(trackEventType, applicationModel, buildInfo, localBuildDir); if (getLog().isDebugEnabled()) { - getLog().debug("Analytics took " + (System.currentTimeMillis() - start) + "ms"); + getLog().debug("Analytics took " + (duration(System.nanoTime(), start)) + "ms"); } } + private long duration(long end, long start) { + return TimeUnit.MILLISECONDS.convert(end - start, TimeUnit.NANOSECONDS); + } + public void buildAnalyticsUserInput(Function analyticsEnabledSupplier) { analyticsService.buildAnalyticsUserInput(analyticsEnabledSupplier); }