}
return null;
}
-
- /**
- * 2015.09.29 16:57:45 INFO web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms
- */
- public static Long extractComputationTotalTime(List<String> logs) {
- Pattern pattern = Pattern.compile(".*INFO.*Executed task.* \\| time=(\\d+)ms.*");
- for (int i = logs.size() - 1; i >= 0; i--) {
- String line = logs.get(i);
- Matcher matcher = pattern.matcher(line);
- if (matcher.matches()) {
- String duration = matcher.group(1);
- return Long.parseLong(duration);
- }
- }
-
- return null;
- }
}
package org.sonarsource.sonarqube.perf;
import com.sonar.orchestrator.Orchestrator;
-import org.apache.commons.io.FileUtils;
-
+import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.FileUtils;
public class ServerLogs {
}
}
+ /**
+ * 2015.09.29 16:57:45 INFO ce[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms
+ */
+ public static Long extractComputationTotalTime(Orchestrator orchestrator) throws IOException {
+ File report = new File(orchestrator.getServer().getLogs().getParent(), "ce_activity.log");
+ List<String> logsLines = FileUtils.readLines(report, Charsets.UTF_8);
+ return extractComputationTotalTime(logsLines);
+ }
+
+ static Long extractComputationTotalTime(List<String> logs) {
+ Pattern pattern = Pattern.compile(".*INFO.*Executed task.* \\| time=(\\d+)ms.*");
+ for (int i = logs.size() - 1; i >= 0; i--) {
+ String line = logs.get(i);
+ Matcher matcher = pattern.matcher(line);
+ if (matcher.matches()) {
+ String duration = matcher.group(1);
+ return Long.parseLong(duration);
+ }
+ }
+
+ return null;
+ }
+
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonarsource.sonarqube.perf;
+
+import com.google.common.collect.Lists;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ServerLogsTest {
+ @Test
+ public void logs_with_different_computations_take_the_last_one() throws Exception {
+ assertThat(ServerLogs.extractComputationTotalTime(Lists.newArrayList(
+ "2015.09.29 16:57:45 INFO web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms",
+ "2015.09.29 16:57:45 INFO web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=1234ms")))
+ .isEqualTo(1234L);
+ }
+
+}
*/
package org.sonarsource.sonarqube.perf.computation;
-import com.google.common.base.Charsets;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import com.sonar.orchestrator.locator.FileLocation;
import java.io.File;
import java.io.IOException;
-import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonarsource.sonarqube.perf.MavenLogs;
import org.sonarsource.sonarqube.perf.PerfTestCase;
+import org.sonarsource.sonarqube.perf.ServerLogs;
public class ComputationTest extends PerfTestCase {
private static int MAX_HEAP_SIZE_IN_MEGA = 600;
}
private void assertComputationDurationAround(long expectedDuration) throws IOException {
- File report = new File(orchestrator.getServer().getLogs().getParent(), "sonar.log");
- List<String> logsLines = FileUtils.readLines(report, Charsets.UTF_8);
- Long duration = MavenLogs.extractComputationTotalTime(logsLines);
+ Long duration = ServerLogs.extractComputationTotalTime(orchestrator);
assertDurationAround(duration, expectedDuration);
}
*/
package org.sonarsource.sonarqube.perf.scanner;
-import com.google.common.collect.Lists;
-import org.sonarsource.sonarqube.perf.MavenLogs;
import org.junit.Test;
+import org.sonarsource.sonarqube.perf.MavenLogs;
import static org.fest.assertions.Assertions.assertThat;
public void testEndMemory() throws Exception {
assertThat(MavenLogs.extractEndMemory(" Final Memory: 68M/190M ")).isEqualTo(68);
}
-
- @Test
- public void logs_with_different_computations_take_the_last_one() throws Exception {
- assertThat(MavenLogs.extractComputationTotalTime(Lists.newArrayList(
- "2015.09.29 16:57:45 INFO web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=2283ms",
- "2015.09.29 16:57:45 INFO web[o.s.s.c.q.CeWorkerRunnableImpl] Executed task | project=com.github.kevinsawicki:http-request-parent | id=AVAZm9oHIXrp54OmOeQe | time=1234ms")))
- .isEqualTo(1234L);
- }
}