Skip to content

Commit

Permalink
Add part number to Global Memory for macOS, AIX (#2625)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Apr 13, 2024
1 parent e7efd02 commit 8f4c08d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# 6.5.1 (in progress)

##### New Features
* [#2603](https://github.com/oshi/oshi/pull/2603): Add part number to Global Memory - [@BartekDziurowicz](https://github.com/BartekDziurowicz).
* [#2603](https://github.com/oshi/oshi/pull/2603),
[#2603](https://github.com/oshi/oshi/pull/2625): Add part number to Physical Memory - [@BartekDziurowicz](https://github.com/BartekDziurowicz), [@dbwiddis](https://github.com/dbwiddis).

##### Bug fixes / Improvements
* [#2605](https://github.com/oshi/oshi/pull/2605): Reduce CpuStat.getSystemCpuLoadticks memory allocation pressure - [@chrisribble](https://github.com/chrisribble).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2022 The OSHI Project Contributors
* Copyright 2020-2024 The OSHI Project Contributors
* SPDX-License-Identifier: MIT
*/
package oshi.driver.windows.wmi;
Expand Down
5 changes: 3 additions & 2 deletions oshi-core/src/main/java/oshi/hardware/PhysicalMemory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 The OSHI Project Contributors
* Copyright 2019-2024 The OSHI Project Contributors
* SPDX-License-Identifier: MIT
*/
package oshi.hardware;
Expand All @@ -21,7 +21,8 @@ public class PhysicalMemory {
private final String memoryType;
private final String partNumber;

public PhysicalMemory(String bankLabel, long capacity, long clockSpeed, String manufacturer, String memoryType, String partNumber) {
public PhysicalMemory(String bankLabel, long capacity, long clockSpeed, String manufacturer, String memoryType,
String partNumber) {
this.bankLabel = bankLabel;
this.capacity = capacity;
this.clockSpeed = clockSpeed;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 The OSHI Project Contributors
* Copyright 2016-2024 The OSHI Project Contributors
* SPDX-License-Identifier: MIT
*/
package oshi.hardware.common;
Expand Down Expand Up @@ -40,7 +40,8 @@ public List<PhysicalMemory> getPhysicalMemory() {
// Save previous bank
if (bank++ > 0) {
if (capacity > 0) {
pmList.add(new PhysicalMemory(bankLabel + locator, capacity, speed, manufacturer, memoryType, partNumber));
pmList.add(new PhysicalMemory(bankLabel + locator, capacity, speed, manufacturer, memoryType,
partNumber));
}
bankLabel = Constants.UNKNOWN;
locator = "";
Expand Down Expand Up @@ -70,6 +71,7 @@ public List<PhysicalMemory> getPhysicalMemory() {
manufacturer = split[1].trim();
break;
case "PartNumber":
case "Part Number":
partNumber = split[1].trim();
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 The OSHI Project Contributors
* Copyright 2016-2024 The OSHI Project Contributors
* SPDX-License-Identifier: MIT
*/
package oshi.hardware.platform.mac;
Expand Down Expand Up @@ -75,11 +75,13 @@ public List<PhysicalMemory> getPhysicalMemory() {
long speed = 0L;
String manufacturer = Constants.UNKNOWN;
String memoryType = Constants.UNKNOWN;
String partNumber = Constants.UNKNOWN;
for (String line : sp) {
if (line.trim().startsWith("BANK")) {
// Save previous bank
if (bank++ > 0) {
pmList.add(new PhysicalMemory(bankLabel, capacity, speed, manufacturer, memoryType, Constants.UNKNOWN));
pmList.add(new PhysicalMemory(bankLabel, capacity, speed, manufacturer, memoryType,
Constants.UNKNOWN));
}
bankLabel = line.trim();
int colon = bankLabel.lastIndexOf(':');
Expand All @@ -102,13 +104,16 @@ public List<PhysicalMemory> getPhysicalMemory() {
case "Manufacturer":
manufacturer = split[1].trim();
break;
case "Part Number":
partNumber = split[1].trim();
break;
default:
break;
}
}
}
}
pmList.add(new PhysicalMemory(bankLabel, capacity, speed, manufacturer, memoryType, Constants.UNKNOWN));
pmList.add(new PhysicalMemory(bankLabel, capacity, speed, manufacturer, memoryType, partNumber));

return pmList;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2022 The OSHI Project Contributors
* Copyright 2020-2024 The OSHI Project Contributors
* SPDX-License-Identifier: MIT
*/
package oshi.hardware.platform.unix.aix;
Expand Down Expand Up @@ -65,13 +65,17 @@ public VirtualMemory getVirtualMemory() {
public List<PhysicalMemory> getPhysicalMemory() {
List<PhysicalMemory> pmList = new ArrayList<>();
boolean isMemModule = false;
boolean isMemoryDIMM = false;
String bankLabel = Constants.UNKNOWN;
String locator = "";
String partNumber = Constants.UNKNOWN;
long capacity = 0L;
for (String line : lscfg.get()) {
String s = line.trim();
if (s.endsWith("memory-module")) {
isMemModule = true;
} else if (s.startsWith("Memory DIMM")) {
isMemoryDIMM = true;
} else if (isMemModule) {
if (s.startsWith("Node:")) {
bankLabel = s.substring(5).trim();
Expand All @@ -86,13 +90,32 @@ public List<PhysicalMemory> getPhysicalMemory() {
} else if (s.startsWith("Hardware Location Code")) {
// Save previous bank
if (capacity > 0) {
pmList.add(new PhysicalMemory(bankLabel + locator, capacity, 0L, "IBM", Constants.UNKNOWN, Constants.UNKNOWN));
pmList.add(new PhysicalMemory(bankLabel + locator, capacity, 0L, "IBM", Constants.UNKNOWN,
Constants.UNKNOWN));
}
bankLabel = Constants.UNKNOWN;
locator = "";
capacity = 0L;
isMemModule = false;
}
} else if (isMemoryDIMM) {
if (s.startsWith("Hardware Location Code")) {
locator = ParseUtil.removeLeadingDots(s.substring(23).trim());
} else if (s.startsWith("Size")) {
capacity = ParseUtil.parseLongOrDefault(ParseUtil.removeLeadingDots(s.substring(4).trim()),
0L) << 20;
} else if (s.startsWith("Part Number") || s.startsWith("FRU Number")) {
partNumber = ParseUtil.removeLeadingDots(s.substring(11).trim());
} else if (s.startsWith("Physical Location:")) {
// Save previous bank
if (capacity > 0) {
pmList.add(new PhysicalMemory(locator, capacity, 0L, "IBM", Constants.UNKNOWN, partNumber));
}
partNumber = Constants.UNKNOWN;
locator = "";
capacity = 0L;
isMemoryDIMM = false;
}
}
}
return pmList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 The OSHI Project Contributors
* Copyright 2016-2024 The OSHI Project Contributors
* SPDX-License-Identifier: MIT
*/
package oshi.hardware.platform.windows;
Expand Down Expand Up @@ -82,7 +82,8 @@ public List<PhysicalMemory> getPhysicalMemory() {
String memoryType = smBiosMemoryType(
WmiUtil.getUint32(bankMap, PhysicalMemoryProperty.SMBIOSMEMORYTYPE, index));
String partNumber = WmiUtil.getString(bankMap, PhysicalMemoryProperty.PARTNUMBER, index);
physicalMemoryList.add(new PhysicalMemory(bankLabel, capacity, speed, manufacturer, memoryType, partNumber));
physicalMemoryList
.add(new PhysicalMemory(bankLabel, capacity, speed, manufacturer, memoryType, partNumber));
}
} else {
WmiResult<PhysicalMemoryPropertyWin8> bankMap = Win32PhysicalMemory.queryphysicalMemoryWin8();
Expand All @@ -94,7 +95,8 @@ public List<PhysicalMemory> getPhysicalMemory() {
String memoryType = memoryType(
WmiUtil.getUint16(bankMap, PhysicalMemoryPropertyWin8.MEMORYTYPE, index));
String partNumber = WmiUtil.getString(bankMap, PhysicalMemoryPropertyWin8.PARTNUMBER, index);
physicalMemoryList.add(new PhysicalMemory(bankLabel, capacity, speed, manufacturer, memoryType, partNumber));
physicalMemoryList
.add(new PhysicalMemory(bankLabel, capacity, speed, manufacturer, memoryType, partNumber));
}
}
return physicalMemoryList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 The OSHI Project Contributors
* Copyright 2016-2024 The OSHI Project Contributors
* SPDX-License-Identifier: MIT
*/
package oshi.hardware;
Expand Down

0 comments on commit 8f4c08d

Please sign in to comment.