]> source.dussan.org Git - sonarqube.git/commitdiff
improve batch logging and performance
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 9 Sep 2015 14:48:49 +0000 (16:48 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 14 Sep 2015 15:29:40 +0000 (17:29 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndexer.java
sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java
sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java

index 6b06a999a32851d0e6bc4d5a7ceafecb452e09a9..90bada354ecf2cf0a750ac75d05d003839f1878e 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.batch.scan.filesystem;
 
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
 import org.apache.commons.io.filefilter.HiddenFileFilter;
@@ -89,7 +91,8 @@ public class FileIndexer {
     Progress progress = new Progress();
 
     InputFileBuilder inputFileBuilder = inputFileBuilderFactory.create(fileSystem);
-    executorService = Executors.newFixedThreadPool(Math.max(1, Runtime.getRuntime().availableProcessors() - 1));
+    int threads = Math.max(1, Runtime.getRuntime().availableProcessors() - 1);
+    executorService = Executors.newFixedThreadPool(threads, new ThreadFactoryBuilder().setNameFormat("FileIndexer-%d").build());
     tasks = new ArrayList<>();
     indexFiles(fileSystem, progress, inputFileBuilder, fileSystem.sources(), InputFile.Type.MAIN);
     indexFiles(fileSystem, progress, inputFileBuilder, fileSystem.tests(), InputFile.Type.TEST);
index 5d2176b6b182fc05761d1ed56b8ba4207eaaff1a..daff30e89822cadef4b0fbb426658d338359323a 100644 (file)
 package org.sonar.batch.scan.measure;
 
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import org.sonar.api.batch.measure.Metric;
 import org.sonar.api.batch.measure.MetricFinder;
 import org.sonar.api.measures.Metric.ValueType;
 import org.sonar.batch.protocol.input.GlobalRepositories;
 
 import java.util.Collection;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 public class DefaultMetricFinder implements MetricFinder {
 
-  private Map<String, Metric> metricsByKey = Maps.newLinkedHashMap();
+  private Map<String, Metric> metricsByKey = new LinkedHashMap<>();
 
   public DefaultMetricFinder(GlobalRepositories globalReferentials) {
     for (org.sonar.batch.protocol.input.Metric metric : globalReferentials.metrics()) {
index 2b32c65b7f970ca774667d44b308e32e5b5d79d0..3122d9a6fd00150ee4c49def33e9047e67679874 100644 (file)
@@ -44,7 +44,7 @@ import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
 import static java.nio.file.StandardOpenOption.WRITE;
 
 public class PersistentCache {
-
+  private static final char[] hexArray = "0123456789ABCDEF".toCharArray();
   private static final Charset ENCODING = StandardCharsets.UTF_8;
   private static final String DIGEST_ALGO = "MD5";
   private static final String LOCK_FNAME = ".lock";
@@ -133,7 +133,7 @@ public class PersistentCache {
 
     return null;
   }
-  
+
   public synchronized void put(@Nonnull String obj, @Nonnull InputStream stream) throws IOException {
     String key = getKey(obj);
     try {
@@ -293,10 +293,10 @@ public class PersistentCache {
     Path cachePath = getCacheEntryPath(key);
     Files.write(cachePath, value, CREATE, WRITE, TRUNCATE_EXISTING);
   }
-  
+
   private void putCache(String key, InputStream stream) throws IOException {
     Path cachePath = getCacheEntryPath(key);
-    Files.copy(stream,  cachePath, StandardCopyOption.REPLACE_EXISTING);
+    Files.copy(stream, cachePath, StandardCopyOption.REPLACE_EXISTING);
   }
 
   private byte[] getCache(String key) throws IOException {
@@ -377,11 +377,13 @@ public class PersistentCache {
     return baseDir.resolve(key);
   }
 
-  private static String byteArrayToHex(byte[] a) {
-    StringBuilder sb = new StringBuilder(a.length * 2);
-    for (byte b : a) {
-      sb.append(String.format("%02x", b & 0xff));
+  public static String byteArrayToHex(byte[] bytes) {
+    char[] hexChars = new char[bytes.length * 2];
+    for (int j = 0; j < bytes.length; j++) {
+      int v = bytes[j] & 0xFF;
+      hexChars[j * 2] = hexArray[v >>> 4];
+      hexChars[j * 2 + 1] = hexArray[v & 0x0F];
     }
-    return sb.toString();
+    return new String(hexChars);
   }
 }
index e9f71cc17d1ebbff4e772c957dcaf96e8e5f697e..8b6af71cf3c83e618a598940dd0cd6f85ee300c3 100644 (file)
@@ -78,13 +78,13 @@ public class ProjectClasspath implements BatchComponent {
   }
 
   protected List<File> createElements() {
-    List<File> elements = Lists.newArrayList();
+    List<File> e = Lists.newArrayList();
     for (String path : def.getBinaries()) {
-      elements.add(projectFileSystem.resolvePath(path));
+      e.add(projectFileSystem.resolvePath(path));
     }
     for (String path : def.getLibraries()) {
-      elements.add(projectFileSystem.resolvePath(path));
+      e.add(projectFileSystem.resolvePath(path));
     }
-    return elements;
+    return e;
   }
 }