Skip to content

Commit 5fa248c

Browse files
Add physical and logical cores to the platform description
1 parent b08f439 commit 5fa248c

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

pom.xml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -554,22 +554,6 @@
554554
</dependency>
555555
<!-- JMonkeyEngine end -->
556556

557-
<!-- Joystick begin -->
558-
<dependency>
559-
<groupId>net.java.jinput</groupId>
560-
<artifactId>jinput</artifactId>
561-
<version>2.0.9</version>
562-
<scope>provided</scope>
563-
</dependency>
564-
<dependency>
565-
<groupId>jinput-natives</groupId>
566-
<artifactId>jinput-natives</artifactId>
567-
<version>2.0.7</version>
568-
<scope>provided</scope>
569-
<type>zip</type>
570-
</dependency>
571-
<!-- Joystick end -->
572-
573557
<!-- KafkaConnector begin -->
574558
<dependency>
575559
<groupId>org.apache.kafka</groupId>
@@ -1395,6 +1379,11 @@
13951379
<version>3.9.0</version>
13961380
</dependency>
13971381
<!-- Duplicate entry for io.netty-netty-all-4.1.82.Final skipping -->
1382+
<dependency>
1383+
<groupId>com.github.oshi</groupId>
1384+
<artifactId>oshi-core</artifactId>
1385+
<version>6.4.5</version>
1386+
</dependency>
13981387
<!-- Runtime end -->
13991388

14001389
<!-- Serial begin -->

src/main/java/org/myrobotlab/framework/Platform.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.myrobotlab.logging.LoggerFactory;
2020
import org.myrobotlab.logging.LoggingFactory;
2121
import org.slf4j.Logger;
22+
import oshi.SystemInfo;
2223

2324
/**
2425
* The purpose of this class is to retrieve all the detailed information
@@ -85,6 +86,10 @@ public class Platform implements Serializable {
8586

8687
String shortCommit;
8788

89+
int numLogicalProcessors;
90+
91+
int numPhysicalProcessors;
92+
8893
static Platform localInstance;
8994

9095
/**
@@ -108,11 +113,11 @@ public static Platform getLocalInstance() {
108113

109114
// === OS ===
110115
platform.os = System.getProperty("os.name").toLowerCase();
111-
if (platform.os.indexOf("win") >= 0) {
116+
if (platform.os.contains("win")) {
112117
platform.os = OS_WINDOWS;
113-
} else if (platform.os.indexOf("mac") >= 0) {
118+
} else if (platform.os.contains("mac")) {
114119
platform.os = OS_MAC;
115-
} else if (platform.os.indexOf("linux") >= 0) {
120+
} else if (platform.os.contains("linux")) {
116121
platform.os = OS_LINUX;
117122
}
118123

@@ -248,6 +253,13 @@ public static Platform getLocalInstance() {
248253
} catch (Exception e) {
249254
}
250255

256+
// Logical and physical processor detection
257+
258+
// availableProcessors returns the number of logical cores dedicated to the JVM
259+
platform.numLogicalProcessors = java.lang.Runtime.getRuntime().availableProcessors();
260+
261+
platform.numPhysicalProcessors = new SystemInfo().getHardware().getProcessor().getPhysicalProcessorCount();
262+
251263
localInstance = platform;
252264
}
253265
return localInstance;
@@ -497,6 +509,29 @@ public Date getStartTime() {
497509
return startTime;
498510
}
499511

512+
/**
513+
* Get the number of logical cores
514+
* available to the VM. May be different
515+
* from the number of logical cores in the
516+
* system if the user only allocates
517+
* some of them to the VM.
518+
* @return The number of available logical cores
519+
*/
520+
public int getNumLogicalProcessors() {
521+
return numLogicalProcessors;
522+
}
523+
524+
/**
525+
* Get the number of physical cores in the system.
526+
* This may be different from the number of cores allocated
527+
* to the JVM, and on x86 will usually be different from
528+
* the number of logical cores in the system.
529+
* @return The number of physical cores in the system.
530+
*/
531+
public int getNumPhysicalProcessors() {
532+
return numPhysicalProcessors;
533+
}
534+
500535
/**
501536
* @return true if running in virtual mode
502537
*

src/main/java/org/myrobotlab/service/meta/RuntimeMeta.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public RuntimeMeta() {
5454
// force correct version of netty - needed for Vertx but not for Runtime ?
5555
addDependency("io.netty", "netty-all", "4.1.82.Final");
5656

57+
58+
// Allows us to get much more detailed info about the system hardware
59+
// MIT license
60+
addDependency("com.github.oshi", "oshi-core", "6.4.5");
5761
}
5862

5963
}

0 commit comments

Comments
 (0)