From: Julien HENRY Date: Thu, 28 May 2015 09:30:17 +0000 (+0200) Subject: SONAR-6463 Add logs to better profile execution time X-Git-Tag: 5.2-RC1~1793 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ce08670ea0a72be3420b1366602e6339c4f5e11b;p=sonarqube.git SONAR-6463 Add logs to better profile execution time --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java index 190ad8a5e82..55cec2910ed 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java @@ -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 installRemotes() { Map infosByKey = new HashMap<>(); - for (RemotePlugin remotePlugin : listRemotePlugins()) { + List 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 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 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); } } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java index fd1020ef74f..2cb75cf6b34 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java @@ -20,22 +20,25 @@ 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) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java index 861600fdba9..8a88312ff81 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java @@ -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> propertiesByModuleId = extractPropertiesByModule("", taskProps.properties()); ProjectDefinition rootProject = defineRootProject(propertiesByModuleId.get(""), null); rootProjectWorkDir = rootProject.getWorkDir(); @@ -121,6 +121,7 @@ public class ProjectReactorBuilder { for (Map.Entry entry : propertiesByModuleId.get("").entrySet()) { taskProps.properties().put((String) entry.getKey(), (String) entry.getValue()); } + profiler.stopInfo(); return new ProjectReactor(rootProject); }