Skip to content

Commit

Permalink
better formatting for execution times
Browse files Browse the repository at this point in the history
- now using default Guava Stopwatch formatting when calculating
execution times for several operations
  • Loading branch information
ayld committed Jul 13, 2016
1 parent 1ff0083 commit 0bbe8a2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/org/codarama/diet/api/reporting/ReportBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
}
Expand All @@ -30,7 +31,7 @@ private ReportBuilder() {
*/
public static ReportBuilder startClock() {
ReportBuilder builder = new ReportBuilder();
builder.startTime = System.currentTimeMillis();
builder.stopwatch = Stopwatch.createStarted();
return builder;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Set<ClassName> 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;
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/codarama/diet/api/MinimizerUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import static org.junit.Assert.*;

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;
import java.util.jar.JarFile;

import org.codarama.diet.api.reporting.MinimizationReport;
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}.
Expand All @@ -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");
Expand Down

0 comments on commit 0bbe8a2

Please sign in to comment.