aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-04-18 16:41:58 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-04-18 16:41:58 +0200
commit7b273ad672cd7237e731ba054963f324f28094b0 (patch)
tree12761d548439a02ef2cd81018c1b982154e5225f /sonar-batch
parent4e318cf3a6d736ab44583559bef9b9e73a19a2b0 (diff)
downloadsonarqube-7b273ad672cd7237e731ba054963f324f28094b0.tar.gz
sonarqube-7b273ad672cd7237e731ba054963f324f28094b0.zip
SONAR-4147 Add breakdown by module to profiling
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java19
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java33
4 files changed, 54 insertions, 27 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java
index 51a5d263702..f0b8057703d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/AbstractTimeProfiling.java
@@ -64,7 +64,7 @@ public abstract class AbstractTimeProfiling {
this.setTotalTime(this.totalTime() + other.totalTime());
}
- protected <G extends AbstractTimeProfiling> List<G> sortByDescendingTotalTime(Collection<G> unsorted) {
+ static <G extends AbstractTimeProfiling> List<G> sortByDescendingTotalTime(Collection<G> unsorted) {
List<G> result = new ArrayList<G>(unsorted.size());
result.addAll(unsorted);
Collections.sort(result, new Comparator<G>() {
@@ -76,4 +76,19 @@ public abstract class AbstractTimeProfiling {
return result;
}
+ static <G extends AbstractTimeProfiling> List<G> truncate(Collection<G> sortedList) {
+ int maxSize = 10;
+ List<G> result = new ArrayList<G>(maxSize);
+ int i = 0;
+ for (G item : sortedList) {
+ if (i++ >= maxSize || item.totalTime() == 0) {
+ return result;
+ }
+ else {
+ result.add(item);
+ }
+ }
+ return result;
+ }
+
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java
index 895624b9db5..cb656d07ac8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/ModuleProfiling.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.profiling;
+import org.sonar.api.resources.Project;
import org.sonar.api.utils.TimeUtils;
import org.sonar.batch.phases.Phases;
import org.sonar.batch.phases.Phases.Phase;
@@ -31,12 +32,21 @@ public class ModuleProfiling extends AbstractTimeProfiling {
private Map<Phases.Phase, PhaseProfiling> profilingPerPhase = new HashMap<Phases.Phase, PhaseProfiling>();
private Clock clock;
+ private Project module;
- public ModuleProfiling(Clock clock) {
+ public ModuleProfiling(Project module, Clock clock) {
super(clock);
+ this.module = module;
this.clock = clock;
}
+ public String moduleName() {
+ if (module != null) {
+ return module.getName();
+ }
+ return null;
+ }
+
public PhaseProfiling getProfilingPerPhase(Phase phase) {
return profilingPerPhase.get(phase);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java
index 46566b70991..cb9d4d7dd25 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhaseProfiling.java
@@ -21,9 +21,7 @@ package org.sonar.batch.profiling;
import org.sonar.batch.phases.Phases.Phase;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -75,7 +73,7 @@ public class PhaseProfiling extends AbstractTimeProfiling {
public void dump() {
double percent = this.totalTime() / 100.0;
- for (ItemProfiling itemProfiling : truncateList(sortByDescendingTotalTime(profilingPerItem.values()))) {
+ for (ItemProfiling itemProfiling : truncate(sortByDescendingTotalTime(profilingPerItem.values()))) {
StringBuilder sb = new StringBuilder();
sb.append(" o ").append(itemProfiling.itemName()).append(": ").append(itemProfiling.totalTimeAsString())
.append(" (").append((int) (itemProfiling.totalTime() / percent)).append("%)");
@@ -96,19 +94,4 @@ public class PhaseProfiling extends AbstractTimeProfiling {
return toString;
}
- private List<ItemProfiling> truncateList(List<ItemProfiling> sortedFullList) {
- int maxSize = 10;
- List<ItemProfiling> result = new ArrayList<ItemProfiling>(maxSize);
- int i = 0;
- for (ItemProfiling item : sortedFullList) {
- if (i++ >= maxSize || item.totalTime() == 0) {
- return result;
- }
- else {
- result.add(item);
- }
- }
- return result;
- }
-
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java
index 2690aff2cd0..e2ca60cb7cf 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java
@@ -33,10 +33,14 @@ import org.sonar.api.resources.Project;
import org.sonar.api.utils.TimeUtils;
import org.sonar.batch.phases.Phases;
+import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
+import static org.sonar.batch.profiling.AbstractTimeProfiling.sortByDescendingTotalTime;
+import static org.sonar.batch.profiling.AbstractTimeProfiling.truncate;
+
public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorExecutionHandler, DecoratorExecutionHandler, PostJobExecutionHandler, DecoratorsPhaseHandler,
SensorsPhaseHandler, PostJobsPhaseHandler {
@@ -44,6 +48,7 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx
ModuleProfiling currentModuleProfiling;
@VisibleForTesting
ModuleProfiling totalProfiling;
+ private List<ModuleProfiling> modulesProfilings = new ArrayList<ModuleProfiling>();
private DecoratorsProfiler decoratorsProfiler;
private Clock clock;
@@ -55,7 +60,7 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx
@VisibleForTesting
PhasesSumUpTimeProfiler(Clock clock) {
this.clock = clock;
- totalProfiling = new ModuleProfiling(clock);
+ totalProfiling = new ModuleProfiling(null, clock);
}
@Override
@@ -63,25 +68,39 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx
Project module = event.getProject();
if (event.isStart()) {
decoratorsProfiler = new DecoratorsProfiler();
- currentModuleProfiling = new ModuleProfiling(clock);
+ currentModuleProfiling = new ModuleProfiling(module, clock);
}
else {
currentModuleProfiling.stop();
+ modulesProfilings.add(currentModuleProfiling);
long moduleTotalTime = currentModuleProfiling.totalTime();
System.out.println("\n -------- Profiling of module " + module.getName() + ": " + TimeUtils.formatDuration(moduleTotalTime) + " --------\n");
currentModuleProfiling.dump();
System.out.println("\n -------- End of profiling of module " + module.getName() + " --------\n");
totalProfiling.merge(currentModuleProfiling);
if (module.isRoot() && !module.getModules().isEmpty()) {
- totalProfiling.stop();
- long totalTime = totalProfiling.totalTime();
- System.out.println("\n ======== Profiling of total execution: " + TimeUtils.formatDuration(totalTime) + " ========\n");
- totalProfiling.dump();
- System.out.println("\n ======== End of profiling of total execution ========\n");
+ dumpTotalExecutionSummary();
}
}
}
+ private void dumpTotalExecutionSummary() {
+ totalProfiling.stop();
+ long totalTime = totalProfiling.totalTime();
+ System.out.println("\n ======== Profiling of total execution: " + TimeUtils.formatDuration(totalTime) + " ========\n");
+ System.out.println(" * Module execution time breakdown: ");
+ double percent = totalTime / 100.0;
+ for (ModuleProfiling modulesProfiling : truncate(sortByDescendingTotalTime(modulesProfilings))) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(" o ").append(modulesProfiling.moduleName()).append(" execution time: ").append(modulesProfiling.totalTimeAsString())
+ .append(" (").append((int) (modulesProfiling.totalTime() / percent)).append("%)");
+ System.out.println(sb.toString());
+ }
+ System.out.println();
+ totalProfiling.dump();
+ System.out.println("\n ======== End of profiling of total execution ========\n");
+ }
+
public void onSensorsPhase(SensorsPhaseEvent event) {
if (event.isStart()) {
currentModuleProfiling.addPhaseProfiling(Phases.Phase.SENSOR);