public final class Main {
public static void main(String[] args) {
+ long startTime = System.currentTimeMillis();
try {
Properties props = loadProperties(args);
Runner runner = Runner.create(props);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
- printMemoryUsage();
+ printStats(startTime);
}
}
- private static final long MB = 1024 * 1024;
+ private static void printStats(long startTime) {
+ long time = System.currentTimeMillis() - startTime;
+ log("Total time: " + formatTime(time));
- private static void printMemoryUsage() {
+ System.gc();
Runtime r = Runtime.getRuntime();
- log("Final Memory: " + (r.totalMemory() - r.freeMemory()) / MB + "M/" + r.totalMemory() / MB + "M");
+ long mb = 1024 * 1024;
+ log("Final Memory: " + (r.totalMemory() - r.freeMemory()) / mb + "M/" + r.totalMemory() / mb + "M");
+ }
+
+ static String formatTime(long time) {
+ long h = time / (60 * 60 * 1000);
+ long m = (time - h * 60 * 60 * 1000) / (60 * 1000);
+ long s = (time - h * 60 * 60 * 1000 - m * 60 * 1000) / 1000;
+ long ms = time % 1000;
+ return String.format("%1$d:%2$02d:%3$02d.%4$03ds", h, m, s, ms);
}
static Properties loadProperties(String[] args) {
assertThat(props.getProperty("overridden.prop"), is("project scope"));
assertThat(props.getProperty("global.prop"), is("jdbc:mysql:localhost/sonar"));
}
+
+ @Test
+ public void shouldFormatTime() {
+ assertThat(Main.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400), is("1:02:03.400s"));
+ assertThat(Main.formatTime(2 * 60 * 1000 + 3 * 1000 + 400), is("0:02:03.400s"));
+ assertThat(Main.formatTime(3 * 1000 + 400), is("0:00:03.400s"));
+ assertThat(Main.formatTime(400), is("0:00:00.400s"));
+ }
}