Skip to content

Commit

Permalink
Apply minor polish to BuildAnalyticsProvider
Browse files Browse the repository at this point in the history
* Use final fields
* Simplify map population of data
* Use nanoTime instead of currentTimeMillis
  • Loading branch information
geoand authored and holly-cummins committed Jul 31, 2024
1 parent 0c5f92a commit ec82dcf
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -41,18 +42,21 @@ public void sendAnalytics(TrackEventType trackEventType,
ApplicationModel applicationModel,
Map<String, String> graalVMInfo,
File localBuildDir) {
final long start = System.currentTimeMillis();
final long start = System.nanoTime();

final Map<String, Object> buildInfo = new HashMap<>();
buildInfo.putAll(graalVMInfo);
final Map<String, Object> 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<String, String> analyticsEnabledSupplier) {
analyticsService.buildAnalyticsUserInput(analyticsEnabledSupplier);
}
Expand Down

0 comments on commit ec82dcf

Please sign in to comment.