aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-07-01 17:46:24 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-07-04 11:58:13 +0200
commit49cbc42b322e562807add4faaebd649445ee1bce (patch)
tree57cb651c8571e31351e8d091405a2d40b5e91d73 /sonar-scanner-engine
parent5112fc0bc1bc9c1725235ffcf3031060a44e3567 (diff)
downloadsonarqube-49cbc42b322e562807add4faaebd649445ee1bce.tar.gz
sonarqube-49cbc42b322e562807add4faaebd649445ee1bce.zip
SONAR-7354 Display total analysis time in scanners
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java24
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java8
2 files changed, 31 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index 0578a3b144d..606b3d9a29d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -21,10 +21,13 @@ package org.sonar.batch.bootstrap;
import java.util.List;
import java.util.Map;
+
import org.sonar.api.Plugin;
import org.sonar.api.internal.SonarQubeVersionFactory;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.index.CachesManager;
import org.sonar.batch.platform.DefaultServer;
import org.sonar.batch.repository.DefaultGlobalRepositoriesLoader;
@@ -40,7 +43,7 @@ import org.sonar.core.util.DefaultHttpDownloader;
import org.sonar.core.util.UuidFactoryImpl;
public class GlobalContainer extends ComponentContainer {
-
+ private static final Logger LOG = Loggers.get(GlobalContainer.class);
private final Map<String, String> bootstrapProperties;
private GlobalContainer(Map<String, String> bootstrapProperties) {
@@ -103,7 +106,26 @@ public class GlobalContainer extends ComponentContainer {
}
public void executeTask(Map<String, String> taskProperties, Object... components) {
+ long startTime = System.currentTimeMillis();
new TaskContainer(this, taskProperties, components).execute();
+
+ LOG.info("Task total time: {}", formatTime(System.currentTimeMillis() - startTime));
+ }
+
+ 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;
+ final String format;
+ if (h > 0) {
+ format = "%1$d:%2$02d:%3$02d.%4$03ds";
+ } else if (m > 0) {
+ format = "%2$d:%3$02d.%4$03ds";
+ } else {
+ format = "%3$d.%4$03ds";
+ }
+ return String.format(format, h, m, s, ms);
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
index 0019d8adc18..168ebd6a844 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
@@ -63,6 +63,14 @@ public class GlobalContainerTest {
assertThat(container.getComponentByType(Bar.class)).isNotNull();
}
+ @Test
+ public void shouldFormatTime() {
+ assertThat(GlobalContainer.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400s");
+ assertThat(GlobalContainer.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400s");
+ assertThat(GlobalContainer.formatTime(3 * 1000 + 400)).isEqualTo("3.400s");
+ assertThat(GlobalContainer.formatTime(400)).isEqualTo("0.400s");
+ }
+
@BatchSide
public static class Foo {