Skip to content

Commit 36c9e62

Browse files
committed
SONARPY-2456 meassure how long each project takes to analyze
1 parent ec2df8b commit 36c9e62

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

its/ruling/src/test/java/org/sonar/python/it/PythonRulingTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.jupiter.api.BeforeAll;
3030
import org.junit.jupiter.api.Tag;
3131
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.extension.ExtendWith;
3233
import org.junit.jupiter.api.extension.RegisterExtension;
3334
import org.junit.jupiter.api.parallel.Execution;
3435
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -39,6 +40,7 @@
3940
import static org.sonar.python.it.RulingHelper.getOrchestrator;
4041

4142
@Execution(ExecutionMode.CONCURRENT)
43+
@ExtendWith(TestDurationMeasureExtension.class)
4244
class PythonRulingTest {
4345

4446
@RegisterExtension
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* SonarQube Python Plugin
3+
* Copyright (C) 2012-2024 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the Sonar Source-Available License for more details.
13+
*
14+
* You should have received a copy of the Sonar Source-Available License
15+
* along with this program; if not, see https://sonarsource.com/license/ssal/
16+
*/
17+
package org.sonar.python.it;
18+
19+
import java.time.Duration;
20+
import java.time.Instant;
21+
import java.util.ArrayList;
22+
import java.util.Comparator;
23+
import java.util.HashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
import org.junit.jupiter.api.extension.AfterAllCallback;
27+
import org.junit.jupiter.api.extension.AfterEachCallback;
28+
import org.junit.jupiter.api.extension.BeforeEachCallback;
29+
import org.junit.jupiter.api.extension.ExtensionContext;
30+
31+
public class TestDurationMeasureExtension implements BeforeEachCallback, AfterEachCallback, AfterAllCallback {
32+
record TestDuration(String test, Duration duration) {
33+
}
34+
35+
private final Map<String, Instant> startTimeMap = new HashMap<>();
36+
private final List<TestDuration> durationList = new ArrayList<>();
37+
38+
private void start(String uuid) {
39+
startTimeMap.put(uuid, Instant.now());
40+
}
41+
42+
private void stop(String uuid, String name) {
43+
Instant start = startTimeMap.get(uuid);
44+
if (start != null) {
45+
Duration duration = Duration.between(start, Instant.now());
46+
durationList.add(new TestDuration(name, duration));
47+
}
48+
}
49+
50+
@Override
51+
public void beforeEach(ExtensionContext context) {
52+
start(context.getUniqueId());
53+
}
54+
55+
@Override
56+
public void afterEach(ExtensionContext context) {
57+
stop(context.getUniqueId(), context.getDisplayName());
58+
}
59+
60+
@Override
61+
public void afterAll(ExtensionContext context) {
62+
System.out.println("Test durations:");
63+
durationList.sort(Comparator.comparing(TestDuration::duration).reversed());
64+
for (TestDuration duration : durationList) {
65+
System.out.println(duration.test() + ": " + duration.duration().toSeconds() + " sec");
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)