mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
wait until background activity finishes before measuring performance in tests
This commit is contained in:
@@ -66,6 +66,12 @@ public class CpuUsageData {
|
||||
return indent + "GC: " + getGcStats() + "\n" + indent + "Threads: " + getThreadStats() + "\n" + indent + "JIT: " + myCompilationTime + "ms";
|
||||
}
|
||||
|
||||
boolean hasAnyActivityBesides(Thread thread) {
|
||||
return myCompilationTime > 0 ||
|
||||
myThreadTimes.stream().anyMatch(pair -> pair.first > 0 && !pair.second.equals(thread.getName())) ||
|
||||
myGcTimes.stream().anyMatch(pair -> pair.first > 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String printLongestNames(List<Pair<Long, String>> times) {
|
||||
String stats = StreamEx.of(times)
|
||||
|
||||
@@ -583,11 +583,16 @@ public class PlatformTestUtil {
|
||||
if (COVERAGE_ENABLED_BUILD) return;
|
||||
Timings.getStatistics(); // warm-up, measure
|
||||
|
||||
if (attempts == 1) {
|
||||
System.gc();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
attempts--;
|
||||
CpuUsageData data;
|
||||
try {
|
||||
if (setup != null) setup.run();
|
||||
waitForAllBackgroundActivityToCalmDown();
|
||||
data = CpuUsageData.measureCpuUsage(test);
|
||||
}
|
||||
catch (RuntimeException|Error throwable) {
|
||||
@@ -691,12 +696,22 @@ public class PlatformTestUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForAllBackgroundActivityToCalmDown() {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
CpuUsageData data = CpuUsageData.measureCpuUsage(() -> TimeoutUtil.sleep(100));
|
||||
if (!data.hasAnyActivityBesides(Thread.currentThread())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void assertTiming(String message, long expected, @NotNull Runnable actionToMeasure) {
|
||||
assertTiming(message, expected, 4, actionToMeasure);
|
||||
}
|
||||
|
||||
public static long measure(@NotNull Runnable actionToMeasure) {
|
||||
private static long measure(@NotNull Runnable actionToMeasure) {
|
||||
waitForAllBackgroundActivityToCalmDown();
|
||||
long start = System.currentTimeMillis();
|
||||
actionToMeasure.run();
|
||||
long finish = System.currentTimeMillis();
|
||||
|
||||
Reference in New Issue
Block a user