Performance tests: use try-with-resources for dir child stream

GitOrigin-RevId: e8567eccbac8a043c3e0433f9fa85bf100f12264
This commit is contained in:
Max Medvedev
2025-02-15 14:32:22 +01:00
committed by intellij-monorepo-bot
parent f1733d6305
commit ad18944e3e

View File

@@ -32,13 +32,11 @@ import java.lang.reflect.Method;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Locale;
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream;
public class BenchmarkTestInfoImpl implements BenchmarkTestInfo { public class BenchmarkTestInfoImpl implements BenchmarkTestInfo {
private enum IterationMode { private enum IterationMode {
@@ -115,11 +113,20 @@ public class BenchmarkTestInfoImpl implements BenchmarkTestInfo {
// remove content of the previous tests from the idea.log // remove content of the previous tests from the idea.log
IJPerfBenchmarksMetricsPublisher.Companion.truncateTestLog(); IJPerfBenchmarksMetricsPublisher.Companion.truncateTestLog();
var filesWithMetrics = Files.list(PathManager.getLogDir()).filter((it) -> try (Stream<Path> logDirChildren = Files.list(PathManager.getLogDir())) {
it.toString().contains("-metrics") || logDirChildren.filter(child -> {
it.toString().contains("-meters")).toList(); String name = child.toString();
for (Path file : filesWithMetrics) { return name.contains("-metrics")
Files.deleteIfExists(file); || name.contains("-meters");
})
.forEach(childToRemove -> {
try {
Files.deleteIfExists(childToRemove);
}
catch (IOException e) {
// ignore deletion errors for individual files
}
});
} }
} }
catch (Exception e) { catch (Exception e) {