diff --git a/src/main/java/org/codarama/diet/api/reporting/MinimizationStatistics.java b/src/main/java/org/codarama/diet/api/reporting/MinimizationStatistics.java index bffcc2e..6a4167b 100644 --- a/src/main/java/org/codarama/diet/api/reporting/MinimizationStatistics.java +++ b/src/main/java/org/codarama/diet/api/reporting/MinimizationStatistics.java @@ -7,9 +7,9 @@ public interface MinimizationStatistics { /** - * @return the total time it took to finish the minimization process (in milliseconds) + * @return a formatted message telling the total time it took to finish the minimization process */ - long getTotalExecutionTime(); + String getFormattedExecutionTime(); /** * @return the number of sources that were considered by the minimization engine diff --git a/src/main/java/org/codarama/diet/api/reporting/ReportBuilder.java b/src/main/java/org/codarama/diet/api/reporting/ReportBuilder.java index a5e3377..e15dbe4 100644 --- a/src/main/java/org/codarama/diet/api/reporting/ReportBuilder.java +++ b/src/main/java/org/codarama/diet/api/reporting/ReportBuilder.java @@ -5,6 +5,7 @@ import java.util.Set; import java.util.jar.JarFile; +import com.google.common.base.Stopwatch; import org.codarama.diet.model.ClassFile; import org.codarama.diet.model.SourceFile; @@ -13,11 +14,11 @@ */ public class ReportBuilder { - private long startTime; - private MinimizationStatisticsImplementation statistics = new MinimizationStatisticsImplementation(); private MinimizationReportImplementation report = new MinimizationReportImplementation(statistics); + private Stopwatch stopwatch; + private ReportBuilder() { // Disable class instantiation from other classes } @@ -30,7 +31,7 @@ private ReportBuilder() { */ public static ReportBuilder startClock() { ReportBuilder builder = new ReportBuilder(); - builder.startTime = System.currentTimeMillis(); + builder.stopwatch = Stopwatch.createStarted(); return builder; } @@ -101,8 +102,8 @@ public ReportBuilder minimizedLibs(Set foundDependencies) { * @return the instance of the {@link ReportBuilder} for chaining purposes */ public ReportBuilder stopClock() { - long endTime = System.currentTimeMillis(); - this.statistics.totalTime = endTime - startTime; + this.stopwatch.stop(); + this.statistics.totalTimeMsg = stopwatch.toString(); return this; } @@ -139,11 +140,11 @@ private class MinimizationStatisticsImplementation implements MinimizationStatis private int minimizedDependenciesCount; private int totalDependenciesCount; private int sourcesCount; - private long totalTime; + private String totalTimeMsg; @Override - public long getTotalExecutionTime() { - return this.totalTime; + public String getFormattedExecutionTime() { + return this.totalTimeMsg; } @Override diff --git a/src/main/java/org/codarama/diet/dependency/resolver/impl/ClassStreamDependencyResolver.java b/src/main/java/org/codarama/diet/dependency/resolver/impl/ClassStreamDependencyResolver.java index 01ed210..8d0fcc4 100644 --- a/src/main/java/org/codarama/diet/dependency/resolver/impl/ClassStreamDependencyResolver.java +++ b/src/main/java/org/codarama/diet/dependency/resolver/impl/ClassStreamDependencyResolver.java @@ -50,7 +50,7 @@ public Set resolve(ClassStream classStream) throws IOException { stopwatch.stop(); eventBus.post( new ClassDependencyResolutionEndEvent("Class dependency resolution took: " - + stopwatch.elapsed(TimeUnit.SECONDS), this.getClass()) + + stopwatch.toString(), this.getClass()) ); return result; diff --git a/src/test/java/org/codarama/diet/api/MinimizerUnitTest.java b/src/test/java/org/codarama/diet/api/MinimizerUnitTest.java index e252eef..5c14cc3 100644 --- a/src/test/java/org/codarama/diet/api/MinimizerUnitTest.java +++ b/src/test/java/org/codarama/diet/api/MinimizerUnitTest.java @@ -4,7 +4,6 @@ import static org.junit.Assert.*; import java.io.IOException; -import java.util.Iterator; import java.util.Set; import java.util.jar.JarFile; @@ -12,7 +11,6 @@ import org.codarama.diet.api.reporting.MinimizationStatistics; import org.codarama.diet.model.ClassName; import org.junit.Before; -import org.junit.Test; /** * Unit tests for the {@link DefaultMinimizer}. @@ -32,7 +30,7 @@ public void init() throws IOException { when(mockStatistics.getMinimizedDependenciesCount()).thenReturn(10); when(mockStatistics.getSourceFilesCount()).thenReturn(200); when(mockStatistics.getTotalDependenciesCount()).thenReturn(1000); - when(mockStatistics.getTotalExecutionTime()).thenReturn(5L * 60L * 1000L); + when(mockStatistics.getFormattedExecutionTime()).thenReturn(String.valueOf(5L * 60L * 1000L)); final JarFile minimizationResult = mock(JarFile.class); when(minimizationResult.getName()).thenReturn("diet.jar");