diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-12-15 17:04:21 +0000 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-12-15 17:04:21 +0000 |
commit | 2e43ee159277eaeecd3a7b265d0f5c3badfc8954 (patch) | |
tree | 422fa50a0f82d0058f85bcc0407dd8ccf096faa3 /src/main | |
parent | c05d78d7f9c062e0ca012fba274c17b88469a975 (diff) | |
download | sonar-scanner-cli-2e43ee159277eaeecd3a7b265d0f5c3badfc8954.tar.gz sonar-scanner-cli-2e43ee159277eaeecd3a7b265d0f5c3badfc8954.zip |
SONARPLUGINS-1023 Display total running time at the end of analysis
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/sonar/runner/Main.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/java/org/sonar/runner/Main.java b/src/main/java/org/sonar/runner/Main.java index aba4a10..8ee7ccb 100644 --- a/src/main/java/org/sonar/runner/Main.java +++ b/src/main/java/org/sonar/runner/Main.java @@ -44,6 +44,7 @@ import java.util.Properties; public final class Main { public static void main(String[] args) { + long startTime = System.currentTimeMillis(); try { Properties props = loadProperties(args); Runner runner = Runner.create(props); @@ -56,15 +57,26 @@ public final class Main { } 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) { |