]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13699 Purge profiling is missing
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 29 Jul 2020 15:01:53 +0000 (10:01 -0500)
committersonartech <sonartech@sonarsource.com>
Fri, 31 Jul 2020 20:06:11 +0000 (20:06 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleanerTest.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index 3643f501c5ab703244ddda3a3c2d93ddc750a0c3..2939c826f004870167b2c4cf1a3a475636efec04 100644 (file)
 package org.sonar.ce.task.projectanalysis.purge;
 
 import java.util.Set;
+import org.sonar.api.CoreProperties;
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.TimeUtils;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.DbSession;
 import org.sonar.db.purge.PurgeConfiguration;
 import org.sonar.db.purge.PurgeDao;
@@ -35,6 +39,8 @@ import static org.sonar.db.purge.PurgeConfiguration.newDefaultPurgeConfiguration
 @ServerSide
 @ComputeEngineSide
 public class ProjectCleaner {
+  private static final Logger LOG = Loggers.get(ProjectCleaner.class);
+
   private final PurgeProfiler profiler;
   private final PurgeListener purgeListener;
   private final PurgeDao purgeDao;
@@ -48,6 +54,7 @@ public class ProjectCleaner {
   }
 
   public ProjectCleaner purge(DbSession session, String rootUuid, String projectUuid, Configuration projectConfig, Set<String> disabledComponentUuids) {
+    long start = System.currentTimeMillis();
     profiler.reset();
 
     periodCleaner.clean(session, rootUuid, projectConfig);
@@ -56,6 +63,20 @@ public class ProjectCleaner {
     purgeDao.purge(session, configuration, purgeListener, profiler);
 
     session.commit();
+    logProfiling(start, projectConfig);
     return this;
   }
+
+  private void logProfiling(long start, Configuration config) {
+    if (config.getBoolean(CoreProperties.PROFILING_LOG_PROPERTY).orElse(false)) {
+      long duration = System.currentTimeMillis() - start;
+      LOG.info("");
+      LOG.info(" -------- Profiling for purge: " + TimeUtils.formatDuration(duration) + " --------");
+      LOG.info("");
+      profiler.dump(duration, LOG);
+      LOG.info("");
+      LOG.info(" -------- End of profiling for purge --------");
+      LOG.info("");
+    }
+  }
 }
index f725b0056fa5ea0a082dba051d9c922df3004d72..47fa5ca99ca5306e928bcc8ea4855568c58a648f 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.ce.task.projectanalysis.purge;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.CoreProperties;
 import org.sonar.api.config.PropertyDefinitions;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
@@ -34,7 +35,9 @@ import org.sonar.db.purge.period.DefaultPeriodCleaner;
 
 import static java.util.Collections.emptySet;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 
 public class ProjectCleanerTest {
@@ -60,4 +63,22 @@ public class ProjectCleanerTest {
     verify(periodCleaner).clean(any(), any(), any());
     verify(dao).purge(any(), any(), any(), any());
   }
+
+  @Test
+  public void no_profiling_when_property_is_false() {
+    settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, false);
+
+    underTest.purge(mock(DbSession.class), "root", "project", settings.asConfig(), emptySet());
+
+    verify(profiler, never()).dump(anyLong(), any());
+  }
+
+  @Test
+  public void profiling_when_property_is_true() {
+    settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true);
+
+    underTest.purge(mock(DbSession.class), "root", "project", settings.asConfig(), emptySet());
+
+    verify(profiler).dump(anyLong(), any());
+  }
 }
index d09cc16053188ed213e2499b2a3dcbd625ad8c80..b2ba5b2618b7f07cf2c7393d6502f8bec6fce398 100644 (file)
@@ -308,6 +308,12 @@ public interface CoreProperties {
   @Deprecated
   String SCAN_TASK = "scan";
 
+  /**
+   * @since 3.6
+   * Removed in 8.4 by mistake and reintroduced in 8.5
+   */
+  String PROFILING_LOG_PROPERTY = "sonar.showProfiling";
+
   /**
    * @since 4.0
    */