]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6463 Add logs to better profile execution time
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 28 May 2015 09:30:17 +0000 (11:30 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 28 May 2015 09:31:38 +0000 (11:31 +0200)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java
sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java

index 190ad8a5e8267be7b734dd331a73f8504fe30972..55cec2910ed96364e5ffd1ac47b961e46a473653 100644 (file)
@@ -21,23 +21,23 @@ package org.sonar.batch.bootstrap;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import org.apache.commons.lang.CharUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.Plugin;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
 import org.sonar.core.platform.PluginInfo;
 import org.sonar.core.plugins.RemotePlugin;
 import org.sonar.core.plugins.RemotePluginFile;
 import org.sonar.home.cache.FileCache;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Downloads the plugins installed on server and stores them in a local user cache
  * (see {@link FileCacheProvider}).
@@ -60,13 +60,16 @@ public class BatchPluginInstaller implements PluginInstaller {
   @Override
   public Map<String, PluginInfo> installRemotes() {
     Map<String, PluginInfo> infosByKey = new HashMap<>();
-    for (RemotePlugin remotePlugin : listRemotePlugins()) {
+    List<RemotePlugin> remotePlugins = listRemotePlugins();
+    Profiler profiler = Profiler.create(LOG).startDebug("Load plugins");
+    for (RemotePlugin remotePlugin : remotePlugins) {
       if (pluginPredicate.apply(remotePlugin.getKey())) {
         File jarFile = download(remotePlugin);
         PluginInfo info = PluginInfo.create(jarFile);
         infosByKey.put(info.getKey(), info);
       }
     }
+    profiler.stopDebug();
     return infosByKey;
   }
 
@@ -107,8 +110,9 @@ public class BatchPluginInstaller implements PluginInstaller {
   @VisibleForTesting
   List<RemotePlugin> listRemotePlugins() {
     try {
-      LOG.debug("Download index of plugins");
+      Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index");
       String indexContent = server.request(PLUGINS_INDEX_URL);
+      profiler.stopInfo();
       String[] rows = StringUtils.split(indexContent, CharUtils.LF);
       List<RemotePlugin> result = Lists.newArrayList();
       for (String row : rows) {
@@ -117,7 +121,7 @@ public class BatchPluginInstaller implements PluginInstaller {
       return result;
 
     } catch (Exception e) {
-      throw new IllegalStateException("Fail to download list of plugins: " + PLUGINS_INDEX_URL, e);
+      throw new IllegalStateException("Fail to load plugin index: " + PLUGINS_INDEX_URL, e);
     }
   }
 }
index fd1020ef74fb0f0c7d9cb8d2cb66e0be7461029f..2cb75cf6b348a540ef307279a22c4f4bab019489 100644 (file)
 package org.sonar.batch.scan;
 
 import com.google.common.collect.Lists;
-import org.slf4j.LoggerFactory;
+import java.util.List;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
 import org.sonar.batch.bootstrap.DefaultAnalysisMode;
 import org.sonar.batch.bootstrap.GlobalSettings;
 import org.sonar.batch.protocol.input.ProjectRepositories;
 
-import java.util.List;
-
 /**
  * @since 2.12
  */
 public class ModuleSettings extends Settings {
 
+  private static final Logger LOG = Loggers.get(ModuleSettings.class);
+
   private final ProjectRepositories projectReferentials;
   private DefaultAnalysisMode analysisMode;
 
@@ -46,8 +49,9 @@ public class ModuleSettings extends Settings {
     this.analysisMode = analysisMode;
     getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
 
-    LoggerFactory.getLogger(ModuleSettings.class).info("Load module settings");
+    Profiler profiler = Profiler.create(LOG).startInfo("Load module settings");
     init(moduleDefinition, batchSettings);
+    profiler.stopDebug();
   }
 
   private ModuleSettings init(ProjectDefinition moduleDefinition, GlobalSettings batchSettings) {
index 861600fdba94d11d9a4b42943a13d8b917081bbd..8a88312ff81b999befd518b2e2561f90c14c628c 100644 (file)
@@ -21,23 +21,6 @@ package org.sonar.batch.scan;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
-import org.apache.commons.io.filefilter.AndFileFilter;
-import org.apache.commons.io.filefilter.FileFileFilter;
-import org.apache.commons.io.filefilter.IOFileFilter;
-import org.apache.commons.io.filefilter.WildcardFileFilter;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.batch.bootstrap.AnalysisProperties;
-import org.sonar.batch.util.BatchUtils;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileInputStream;
@@ -50,6 +33,22 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.apache.commons.io.filefilter.AndFileFilter;
+import org.apache.commons.io.filefilter.FileFileFilter;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
+import org.sonar.batch.bootstrap.AnalysisProperties;
+import org.sonar.batch.util.BatchUtils;
 
 /**
  * Class that creates a project definition based on a set of properties.
@@ -58,7 +57,7 @@ public class ProjectReactorBuilder {
 
   private static final String INVALID_VALUE_OF_X_FOR_Y = "Invalid value of {0} for {1}";
 
-  private static final Logger LOG = LoggerFactory.getLogger(ProjectReactorBuilder.class);
+  private static final Logger LOG = Loggers.get(ProjectReactorBuilder.class);
 
   /**
    * @since 4.1 but not yet exposed in {@link CoreProperties}
@@ -112,6 +111,7 @@ public class ProjectReactorBuilder {
   }
 
   public ProjectReactor execute() {
+    Profiler profiler = Profiler.create(LOG).startInfo("Process project properties");
     Map<String, Map<String, String>> propertiesByModuleId = extractPropertiesByModule("", taskProps.properties());
     ProjectDefinition rootProject = defineRootProject(propertiesByModuleId.get(""), null);
     rootProjectWorkDir = rootProject.getWorkDir();
@@ -121,6 +121,7 @@ public class ProjectReactorBuilder {
     for (Map.Entry<String, String> entry : propertiesByModuleId.get("").entrySet()) {
       taskProps.properties().put((String) entry.getKey(), (String) entry.getValue());
     }
+    profiler.stopInfo();
     return new ProjectReactor(rootProject);
   }