Skip to content

Commit

Permalink
Add physical and logical cores to the platform description
Browse files Browse the repository at this point in the history
  • Loading branch information
AutonomicPerfectionist committed Sep 10, 2023
1 parent b08f439 commit 5fa248c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
21 changes: 5 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -554,22 +554,6 @@
</dependency>
<!-- JMonkeyEngine end -->

<!-- Joystick begin -->
<dependency>
<groupId>net.java.jinput</groupId>
<artifactId>jinput</artifactId>
<version>2.0.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jinput-natives</groupId>
<artifactId>jinput-natives</artifactId>
<version>2.0.7</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
<!-- Joystick end -->

<!-- KafkaConnector begin -->
<dependency>
<groupId>org.apache.kafka</groupId>
Expand Down Expand Up @@ -1395,6 +1379,11 @@
<version>3.9.0</version>
</dependency>
<!-- Duplicate entry for io.netty-netty-all-4.1.82.Final skipping -->
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.4.5</version>
</dependency>
<!-- Runtime end -->

<!-- Serial begin -->
Expand Down
41 changes: 38 additions & 3 deletions src/main/java/org/myrobotlab/framework/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.logging.LoggingFactory;
import org.slf4j.Logger;
import oshi.SystemInfo;

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

String shortCommit;

int numLogicalProcessors;

int numPhysicalProcessors;

static Platform localInstance;

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

// === OS ===
platform.os = System.getProperty("os.name").toLowerCase();
if (platform.os.indexOf("win") >= 0) {
if (platform.os.contains("win")) {
platform.os = OS_WINDOWS;
} else if (platform.os.indexOf("mac") >= 0) {
} else if (platform.os.contains("mac")) {
platform.os = OS_MAC;
} else if (platform.os.indexOf("linux") >= 0) {
} else if (platform.os.contains("linux")) {
platform.os = OS_LINUX;
}

Expand Down Expand Up @@ -248,6 +253,13 @@ public static Platform getLocalInstance() {
} catch (Exception e) {
}

// Logical and physical processor detection

// availableProcessors returns the number of logical cores dedicated to the JVM
platform.numLogicalProcessors = java.lang.Runtime.getRuntime().availableProcessors();

platform.numPhysicalProcessors = new SystemInfo().getHardware().getProcessor().getPhysicalProcessorCount();

localInstance = platform;
}
return localInstance;
Expand Down Expand Up @@ -497,6 +509,29 @@ public Date getStartTime() {
return startTime;
}

/**
* Get the number of logical cores
* available to the VM. May be different
* from the number of logical cores in the
* system if the user only allocates
* some of them to the VM.
* @return The number of available logical cores
*/
public int getNumLogicalProcessors() {
return numLogicalProcessors;
}

/**
* Get the number of physical cores in the system.
* This may be different from the number of cores allocated
* to the JVM, and on x86 will usually be different from
* the number of logical cores in the system.
* @return The number of physical cores in the system.
*/
public int getNumPhysicalProcessors() {
return numPhysicalProcessors;
}

/**
* @return true if running in virtual mode
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/myrobotlab/service/meta/RuntimeMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public RuntimeMeta() {
// force correct version of netty - needed for Vertx but not for Runtime ?
addDependency("io.netty", "netty-all", "4.1.82.Final");


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

}

0 comments on commit 5fa248c

Please sign in to comment.