aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-02-18 12:13:34 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-02-19 12:08:25 +0100
commitd5a8ab383c56026165e995d62fbbeb0bed790d53 (patch)
tree81085987cadbaca5d1ed3bba4fe8a62e6fdf5ab0 /sonar-batch/src
parent6adb553ddc2711cb88632be9bd96b4e91c51082e (diff)
downloadsonarqube-d5a8ab383c56026165e995d62fbbeb0bed790d53.tar.gz
sonarqube-d5a8ab383c56026165e995d62fbbeb0bed790d53.zip
SONAR-6194 SONAR-5009 profiling api + unique property sonar.log.level
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/PreviousIssueRepository.java47
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/LastLineHashes.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java19
6 files changed, 36 insertions, 70 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java
index b8350757ad3..a3c42a7efa1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java
@@ -19,9 +19,6 @@
*/
package org.sonar.batch.bootstrapper;
-import org.sonar.core.profiling.Profiling.Level;
-
-import org.sonar.core.profiling.Profiling;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
@@ -69,8 +66,8 @@ public final class LoggingConfiguration {
}
public LoggingConfiguration setProperties(Map<String, String> properties) {
- Profiling.Level profilingLevel = Profiling.Level.fromConfigString(properties.get("sonar.log.profilingLevel"));
- setShowSqlResults(profilingLevel == Level.FULL);
+ //TODO
+ setShowSqlResults(false);
setVerbose("true".equals(properties.get("sonar.verbose")));
return this;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java
index bb434c22737..7ce8c610ba5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java
@@ -27,27 +27,23 @@ import org.sonar.api.batch.debt.DebtCharacteristic;
import org.sonar.api.batch.debt.DebtModel;
import org.sonar.api.batch.debt.internal.DefaultDebtCharacteristic;
import org.sonar.api.batch.debt.internal.DefaultDebtModel;
-import org.sonar.api.utils.TimeProfiler;
-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.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
import javax.annotation.Nullable;
-
import java.util.List;
public class DebtModelProvider extends ProviderAdapter {
- private static final Logger LOG = Loggers.get(DebtModelProvider.class);
-
private DebtModel model;
public DebtModel provide(CharacteristicDao dao) {
if (model == null) {
- TimeProfiler profiler = new TimeProfiler(LOG).start("Loading technical debt model");
+ Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Load technical debt model");
model = load(dao);
- profiler.stop();
+ profiler.stopDebug();
}
return model;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/PreviousIssueRepository.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/PreviousIssueRepository.java
index dc19f79818a..ce9ff46803f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/PreviousIssueRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/PreviousIssueRepository.java
@@ -20,12 +20,12 @@
package org.sonar.batch.issue.tracking;
import com.google.common.base.Function;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.utils.TimeProfiler;
+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.index.BatchResource;
import org.sonar.batch.index.Cache;
import org.sonar.batch.index.Caches;
@@ -38,7 +38,7 @@ import javax.annotation.Nullable;
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public class PreviousIssueRepository implements BatchComponent {
- private static final Logger LOG = LoggerFactory.getLogger(PreviousIssueRepository.class);
+ private static final Logger LOG = Loggers.get(PreviousIssueRepository.class);
private final Caches caches;
private Cache<PreviousIssue> issuesCache;
@@ -54,30 +54,27 @@ public class PreviousIssueRepository implements BatchComponent {
}
public void load() {
- TimeProfiler profiler = new TimeProfiler(LOG).start("Load previous issues");
- try {
- this.issuesCache = caches.createCache("previousIssues");
- previousIssuesLoader.load(reactor, new Function<PreviousIssue, Void>() {
+ Profiler profiler = Profiler.create(LOG).startInfo("Load previous issues");
+ this.issuesCache = caches.createCache("previousIssues");
+ previousIssuesLoader.load(reactor, new Function<PreviousIssue, Void>() {
- @Override
- public Void apply(@Nullable PreviousIssue issue) {
- if (issue == null) {
- return null;
- }
- String componentKey = issue.componentKey();
- BatchResource r = resourceCache.get(componentKey);
- if (r == null) {
- // Deleted resource
- issuesCache.put(0, issue.key(), issue);
- } else {
- issuesCache.put(r.batchId(), issue.key(), issue);
- }
+ @Override
+ public Void apply(@Nullable PreviousIssue issue) {
+ if (issue == null) {
return null;
}
- });
- } finally {
- profiler.stop();
- }
+ String componentKey = issue.componentKey();
+ BatchResource r = resourceCache.get(componentKey);
+ if (r == null) {
+ // Deleted resource
+ issuesCache.put(0, issue.key(), issue);
+ } else {
+ issuesCache.put(r.batchId(), issue.key(), issue);
+ }
+ return null;
+ }
+ });
+ profiler.stopDebug();
}
public Iterable<PreviousIssue> byComponent(BatchResource component) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
index e5125616e9c..c886d93bf51 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
@@ -32,15 +32,13 @@ import org.sonar.api.batch.rule.internal.NewRule;
import org.sonar.api.batch.rule.internal.RulesBuilder;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.Durations;
-import org.sonar.api.utils.TimeProfiler;
-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.rule.RuleDao;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleParamDto;
import javax.annotation.Nullable;
-
import java.util.List;
/**
@@ -48,15 +46,13 @@ import java.util.List;
*/
public class RulesProvider extends ProviderAdapter {
- private static final Logger LOG = Loggers.get(RulesProvider.class);
-
private Rules singleton = null;
public Rules provide(RuleDao ruleDao, DebtModel debtModel, Durations durations) {
if (singleton == null) {
- TimeProfiler profiler = new TimeProfiler(LOG).start("Loading rules");
+ Profiler profiler = Profiler.create(Loggers.get(getClass())).startInfo("Load rules");
singleton = load(ruleDao, (DefaultDebtModel) debtModel, durations);
- profiler.stop();
+ profiler.stopDebug();
}
return singleton;
}
@@ -125,7 +121,7 @@ public class RulesProvider extends ProviderAdapter {
* Return true is the characteristic has not been overridden and a default characteristic is existing or
* if the characteristic has been overridden but is not disabled
*/
- private boolean hasCharacteristic(RuleDto ruleDto){
+ private boolean hasCharacteristic(RuleDto ruleDto) {
Integer subCharacteristicId = ruleDto.getSubCharacteristicId();
return (subCharacteristicId == null && ruleDto.getDefaultSubCharacteristicId() != null) ||
(subCharacteristicId != null && !RuleDto.DISABLED_CHARACTERISTIC_ID.equals(subCharacteristicId));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/LastLineHashes.java b/sonar-batch/src/main/java/org/sonar/batch/scan/LastLineHashes.java
index 5dc690a9da6..ed359265713 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/LastLineHashes.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/LastLineHashes.java
@@ -22,15 +22,12 @@ package org.sonar.batch.scan;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterators;
import org.sonar.api.BatchComponent;
-import org.sonar.api.utils.TimeProfiler;
-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.ServerClient;
public class LastLineHashes implements BatchComponent {
- private static final Logger LOG = Loggers.get(LastLineHashes.class);
-
private final ServerClient server;
public LastLineHashes(ServerClient server) {
@@ -43,11 +40,13 @@ public class LastLineHashes implements BatchComponent {
}
private String loadHashesFromWs(String fileKey) {
- TimeProfiler profiler = new TimeProfiler(LOG).setLevelToDebug().start("Load previous line hashes of: " + fileKey);
+ Profiler profiler = Profiler.createIfDebug(Loggers.get(getClass()))
+ .addContext("file", fileKey)
+ .startDebug("Load line hashes");
try {
return server.request("/api/sources/hash?key=" + ServerClient.encodeForUrl(fileKey));
} finally {
- profiler.stop();
+ profiler.stopDebug();
}
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java
index f8783192273..0da23d622c6 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrapper/LoggingConfigurationTest.java
@@ -62,25 +62,6 @@ public class LoggingConfigurationTest {
}
@Test
- public void testSetShowSqlProperty() {
- Map<String, String> properties = Maps.newHashMap();
- assertThat(LoggingConfiguration.create(null).setProperties(properties)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_RESULTS_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
-
- properties.put("sonar.log.profilingLevel", "FULL");
- assertThat(LoggingConfiguration.create(null).setProperties(properties)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_RESULTS_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_VERBOSE);
-
- properties.put("sonar.log.profilingLevel", "BASIC");
- assertThat(LoggingConfiguration.create(null).setProperties(properties)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_RESULTS_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
-
- properties.put("sonar.log.profilingLevel", "NONE");
- assertThat(LoggingConfiguration.create(null).setProperties(properties)
- .getSubstitutionVariable(LoggingConfiguration.PROPERTY_SQL_RESULTS_LOGGER_LEVEL)).isEqualTo(LoggingConfiguration.LEVEL_SQL_DEFAULT);
- }
-
- @Test
public void testDefaultFormat() {
assertThat(LoggingConfiguration.create(null)
.getSubstitutionVariable(LoggingConfiguration.PROPERTY_FORMAT)).isEqualTo(LoggingConfiguration.FORMAT_DEFAULT);