aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main
diff options
context:
space:
mode:
authorPaint_Ninja <PaintNinja@users.noreply.github.com>2022-08-07 19:03:02 +0100
committerGitHub <noreply@github.com>2022-08-07 19:03:02 +0100
commitf9c898caf921c47f9c6d94f9c1e7d19905b55c07 (patch)
tree6e0a67ec1dc9bc9a80237bb89083fa5da4665315 /spark-common/src/main
parent768bf7a338da8e5daaebc9580ff3b289092c28ee (diff)
downloadspark-f9c898caf921c47f9c6d94f9c1e7d19905b55c07.tar.gz
spark-f9c898caf921c47f9c6d94f9c1e7d19905b55c07.tar.bz2
spark-f9c898caf921c47f9c6d94f9c1e7d19905b55c07.zip
Support getting the CPU model name on Windows (#237)
Diffstat (limited to 'spark-common/src/main')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuInfo.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuInfo.java b/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuInfo.java
index 9bbe0f8..fcb70c0 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuInfo.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/monitor/cpu/CpuInfo.java
@@ -22,10 +22,13 @@ package me.lucko.spark.common.monitor.cpu;
import me.lucko.spark.common.util.LinuxProc;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.regex.Pattern;
/**
- * Small utility to query the CPU model on Linux systems.
+ * Small utility to query the CPU model on Linux and Windows systems.
*/
public enum CpuInfo {
;
@@ -38,11 +41,25 @@ public enum CpuInfo {
* @return the cpu model
*/
public static String queryCpuModel() {
- for (String line : LinuxProc.CPUINFO.read()) {
- String[] splitLine = SPACE_COLON_SPACE_PATTERN.split(line);
+ if (System.getProperty("os.name").startsWith("Windows")) {
+ final String[] args = { "wmic", "cpu", "get", "name", "/FORMAT:list" };
+ try (final BufferedReader buf = new BufferedReader(new InputStreamReader(new ProcessBuilder(args).redirectErrorStream(true).start().getInputStream()))) {
+ String line;
+ while ((line = buf.readLine()) != null) {
+ if (line.startsWith("Name")) {
+ return line.substring(5).trim();
+ }
+ }
+ } catch (final IOException e) {
+ return "";
+ }
+ } else {
+ for (String line : LinuxProc.CPUINFO.read()) {
+ String[] splitLine = SPACE_COLON_SPACE_PATTERN.split(line);
- if (splitLine[0].equals("model name") || splitLine[0].equals("Processor")) {
- return splitLine[1];
+ if (splitLine[0].equals("model name") || splitLine[0].equals("Processor")) {
+ return splitLine[1];
+ }
}
}
return "";