|
8 | 8 | package org.elasticsearch.gradle.internal.info; |
9 | 9 |
|
10 | 10 | import org.apache.commons.io.IOUtils; |
11 | | -import org.elasticsearch.gradle.OS; |
12 | 11 | import org.elasticsearch.gradle.internal.BwcVersions; |
13 | 12 | import org.elasticsearch.gradle.internal.conventions.info.GitInfo; |
14 | 13 | import org.elasticsearch.gradle.internal.conventions.info.ParallelDetector; |
|
30 | 29 | import org.gradle.util.GradleVersion; |
31 | 30 |
|
32 | 31 | import java.io.BufferedReader; |
33 | | -import java.io.ByteArrayOutputStream; |
34 | 32 | import java.io.File; |
35 | 33 | import java.io.FileInputStream; |
36 | | -import java.io.FileReader; |
37 | 34 | import java.io.IOException; |
38 | 35 | import java.io.InputStreamReader; |
39 | 36 | import java.io.UncheckedIOException; |
40 | 37 | import java.nio.file.Files; |
41 | 38 | import java.time.ZoneOffset; |
42 | 39 | import java.time.ZonedDateTime; |
43 | 40 | import java.util.Arrays; |
44 | | -import java.util.HashMap; |
45 | 41 | import java.util.List; |
46 | 42 | import java.util.Locale; |
47 | | -import java.util.Map; |
48 | 43 | import java.util.Random; |
49 | 44 | import java.util.concurrent.atomic.AtomicReference; |
50 | 45 | import java.util.stream.Collectors; |
|
55 | 50 | public class GlobalBuildInfoPlugin implements Plugin<Project> { |
56 | 51 | private static final Logger LOGGER = Logging.getLogger(GlobalBuildInfoPlugin.class); |
57 | 52 | private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/elasticsearch/Version.java"; |
58 | | - private static Integer _defaultParallel = null; |
59 | 53 |
|
60 | 54 | private final JavaInstallationRegistry javaInstallationRegistry; |
61 | 55 | private final JvmMetadataDetector metadataDetector; |
@@ -305,56 +299,6 @@ private static String getJavaHomeEnvVarName(String version) { |
305 | 299 | return "JAVA" + version + "_HOME"; |
306 | 300 | } |
307 | 301 |
|
308 | | - private static int findDefaultParallel(Project project) { |
309 | | - // Since it costs IO to compute this, and is done at configuration time we want to cache this if possible |
310 | | - // It's safe to store this in a static variable since it's just a primitive so leaking memory isn't an issue |
311 | | - if (_defaultParallel == null) { |
312 | | - File cpuInfoFile = new File("/proc/cpuinfo"); |
313 | | - if (cpuInfoFile.exists()) { |
314 | | - // Count physical cores on any Linux distro ( don't count hyper-threading ) |
315 | | - Map<String, Integer> socketToCore = new HashMap<>(); |
316 | | - String currentID = ""; |
317 | | - |
318 | | - try (BufferedReader reader = new BufferedReader(new FileReader(cpuInfoFile))) { |
319 | | - for (String line = reader.readLine(); line != null; line = reader.readLine()) { |
320 | | - if (line.contains(":")) { |
321 | | - List<String> parts = Arrays.stream(line.split(":", 2)).map(String::trim).collect(Collectors.toList()); |
322 | | - String name = parts.get(0); |
323 | | - String value = parts.get(1); |
324 | | - // the ID of the CPU socket |
325 | | - if (name.equals("physical id")) { |
326 | | - currentID = value; |
327 | | - } |
328 | | - // Number of cores not including hyper-threading |
329 | | - if (name.equals("cpu cores")) { |
330 | | - assert currentID.isEmpty() == false; |
331 | | - socketToCore.put("currentID", Integer.valueOf(value)); |
332 | | - currentID = ""; |
333 | | - } |
334 | | - } |
335 | | - } |
336 | | - } catch (IOException e) { |
337 | | - throw new UncheckedIOException(e); |
338 | | - } |
339 | | - _defaultParallel = socketToCore.values().stream().mapToInt(i -> i).sum(); |
340 | | - } else if (OS.current() == OS.MAC) { |
341 | | - // Ask macOS to count physical CPUs for us |
342 | | - ByteArrayOutputStream stdout = new ByteArrayOutputStream(); |
343 | | - project.exec(spec -> { |
344 | | - spec.setExecutable("sysctl"); |
345 | | - spec.args("-n", "hw.physicalcpu"); |
346 | | - spec.setStandardOutput(stdout); |
347 | | - }); |
348 | | - |
349 | | - _defaultParallel = Integer.parseInt(stdout.toString().trim()); |
350 | | - } |
351 | | - |
352 | | - _defaultParallel = Runtime.getRuntime().availableProcessors() / 2; |
353 | | - } |
354 | | - |
355 | | - return _defaultParallel; |
356 | | - } |
357 | | - |
358 | 302 | public static String getResourceContents(String resourcePath) { |
359 | 303 | try ( |
360 | 304 | BufferedReader reader = new BufferedReader(new InputStreamReader(GlobalBuildInfoPlugin.class.getResourceAsStream(resourcePath))) |
|
0 commit comments