Skip to content

Add Processor Cache Information#2198

Merged
dbwiddis merged 20 commits into
oshi:masterfrom
dbwiddis:cache
Oct 4, 2022
Merged

Add Processor Cache Information#2198
dbwiddis merged 20 commits into
oshi:masterfrom
dbwiddis:cache

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Sep 28, 2022

Copy link
Copy Markdown
Member

Fixes #2190

@dbwiddis dbwiddis mentioned this pull request Sep 28, 2022
Comment thread oshi-core/src/main/java/oshi/driver/windows/LogicalProcessorInformation.java Outdated
@sonatype-lift

sonatype-lift Bot commented Sep 28, 2022

Copy link
Copy Markdown
Contributor

⚠️ 25 God Classes were detected by Lift in this project. Visit the Lift web console for more details.

private static Triplet<List<LogicalProcessor>, Map<Integer, Integer>, Map<Integer, String>> readTopologyFromUdev() {
private static Quartet<List<LogicalProcessor>, List<ProcessorCache>, Map<Integer, Integer>, Map<Integer, String>> readTopologyFromUdev() {
List<LogicalProcessor> logProcs = new ArrayList<>();
List<Pair<Triplet<List<Integer>, Integer, Type>, Triplet<Integer, Integer, Long>>> caches = new ArrayList<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadImport: Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer. Here we recommend using qualified class: ProcessorCache.


Suggested change
List<Pair<Triplet<List<Integer>, Integer, Type>, Triplet<Integer, Integer, Long>>> caches = new ArrayList<>();
List<Pair<Triplet<List<Integer>, Integer, ProcessorCache.Type>, Triplet<Integer, Integer, Long>>> caches = new ArrayList<>();

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

List<ProcessorCache> caches = new ArrayList<>();
int cacheSizeL2 = ParseUtil.parseIntOrDefault(ExecutingCommand.getAnswerAt("lsattr -l L2cache0 -E -O", 2), 0);
for (int i = 0; i < physProcs; i++) {
caches.add(new ProcessorCache(i, 2, 0, 64, cacheSizeL2, Type.UNIFIED));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadImport: Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer. Here we recommend using qualified class: ProcessorCache.


Suggested change
caches.add(new ProcessorCache(i, 2, 0, 64, cacheSizeL2, Type.UNIFIED));
caches.add(new ProcessorCache(i, 2, 0, 64, cacheSizeL2, ProcessorCache.Type.UNIFIED));

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

}
int lpPerPp = lcpus / physProcs;
// Get L2 caches, one per physical processor
List<ProcessorCache> caches = new ArrayList<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModifiedButNotUsed: A collection or proto builder was created, but its values were never accessed.


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@lgtm-com

lgtm-com Bot commented Oct 2, 2022

Copy link
Copy Markdown

This pull request introduces 1 alert when merging d0b04e8 into 9e1bf98 - view on LGTM.com

new alerts:

  • 1 for Container contents are never accessed

int cacheSizeL2 = ParseUtil.parseIntOrDefault(ExecutingCommand.getAnswerAt("lsattr -l L2cache0 -E -O", 2), 0);
if (cacheSizeL2 > 0) {
for (int i = 0; i < physProcs; i++) {
caches.add(new ProcessorCache(i, 2, 0, 64, cacheSizeL2, Type.UNIFIED));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadImport: Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer. Here we recommend using qualified class: ProcessorCache.


Suggested change
caches.add(new ProcessorCache(i, 2, 0, 64, cacheSizeL2, Type.UNIFIED));
caches.add(new ProcessorCache(i, 2, 0, 64, cacheSizeL2, ProcessorCache.Type.UNIFIED));

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

}
break;
case 1:
if (cache.getType() == Type.DATA && level1d == null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadImport: Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer. Here we recommend using qualified class: ProcessorCache.


Suggested change
if (cache.getType() == Type.DATA && level1d == null) {
if (cache.getType() == ProcessorCache.Type.DATA && level1d == null) {

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

int powerVersion = ParseUtil.getFirstIntValue(ExecutingCommand.getFirstAnswer("uname -n"));
switch (powerVersion) {
case 7:
caches.add(new ProcessorCache(3, 8, 128, (2 * 32) << 20, Type.UNIFIED));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadImport: Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer. Here we recommend using qualified class: ProcessorCache.


Suggested change
caches.add(new ProcessorCache(3, 8, 128, (2 * 32) << 20, Type.UNIFIED));
caches.add(new ProcessorCache(3, 8, 128, (2 * 32) << 20, ProcessorCache.Type.UNIFIED));

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

try (Stream<Path> path = Files.list(Paths.get(cachePath))) {
path.filter(p -> p.toString().startsWith(indexPrefix)).forEach(c -> {
int level = FileUtil.getIntFromFile(c + "/level"); // 1
Type type = parseCacheType(FileUtil.getStringFromFile(c + "/type")); // Data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadImport: Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer. Here we recommend using qualified class: ProcessorCache.


Suggested change
Type type = parseCacheType(FileUtil.getStringFromFile(c + "/type")); // Data
ProcessorCache.Type type = parseCacheType(FileUtil.getStringFromFile(c + "/type"));

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Map<Integer, String> processorIdMap = new HashMap<>();
WmiResult<ProcessorIdProperty> processorId = Win32Processor.queryProcessorId();
// One entry for each package/socket
WmiResult<ProcessorIdProperty> processorId = Win32Processor.queryProcessorId();// One entry for each

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INTERFACE_NOT_THREAD_SAFE: Unprotected call to method Ole32.CoInitializeEx(...) of un-annotated interface com.sun.jna.platform.win32.Ole32. Consider annotating the interface with @ThreadSafe or adding a lock.
Reporting because the current class is annotated @ThreadSafe.


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

switch (split[split.length - 1]) {
case "I-cache":
return new ProcessorCache(1, ParseUtil.getFirstIntValue(split[2]), ParseUtil.getFirstIntValue(split[1]),
ParseUtil.parseDecimalMemorySizeToBinary(split[0]), Type.INSTRUCTION);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadImport: Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer. Here we recommend using qualified class: ProcessorCache.


Suggested change
ParseUtil.parseDecimalMemorySizeToBinary(split[0]), Type.INSTRUCTION);
ParseUtil.parseDecimalMemorySizeToBinary(split[0]), ProcessorCache.Type.INSTRUCTION);

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Comment thread oshi-core/src/main/java/oshi/hardware/CentralProcessor.java
}

private ProcessorCache parseCacheStr(String cacheStr) {
String[] split = ParseUtil.whitespaces.split(cacheStr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringSplitter: String.split(String) has surprising behavior


Suggested change
String[] split = ParseUtil.whitespaces.split(cacheStr);
List<String> split = Splitter.on(ParseUtil.whitespaces).splitToList(cacheStr);

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

} else {
Matcher n = q.matcher(s);
if (n.matches()) {
for (String cacheStr : n.group(1).split(",")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringSplitter: String.split(String) has surprising behavior


Suggested change
for (String cacheStr : n.group(1).split(",")) {
for (String cacheStr : Splitter.on(',').split(n.group(1))) {

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@lgtm-com

lgtm-com Bot commented Oct 4, 2022

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 853a697 into 4a46741 - view on LGTM.com

new alerts:

  • 1 for Array index out of bounds

for (String checkLine : ExecutingCommand.runNative("lscpu")) {
if (checkLine.contains("L1d cache:")) {
caches.add(new ProcessorCache(1, 0, 0,
ParseUtil.parseDecimalMemorySizeToBinary(checkLine.split(":")[1].trim()), Type.DATA));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadImport: Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer. Here we recommend using qualified class: ProcessorCache.


Suggested change
ParseUtil.parseDecimalMemorySizeToBinary(checkLine.split(":")[1].trim()), Type.DATA));
ParseUtil.parseDecimalMemorySizeToBinary(checkLine.split(":")[1].trim()), ProcessorCache.Type.DATA));

ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@lgtm-com

lgtm-com Bot commented Oct 4, 2022

Copy link
Copy Markdown

This pull request introduces 1 alert when merging c9e272a into 4a46741 - view on LGTM.com

new alerts:

  • 1 for Array index out of bounds

Comment thread oshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.java
Comment thread oshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.java
Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com>
@dbwiddis dbwiddis changed the title Add Cache Information Add Processor Cache Information Oct 4, 2022
@dbwiddis dbwiddis merged commit 1594b97 into oshi:master Oct 4, 2022
@dbwiddis dbwiddis deleted the cache branch October 4, 2022 07:23
if (lcpus < 1) {
lcpus = 1;
}
int lpPerPp = lcpus / physProcs;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that lpPerPp can become 0... eg. 1/2, 1/3... and then cause a divide by zero on line 132.

see #2228
explainer https://stackoverflow.com/questions/4685450/int-division-why-is-the-result-of-1-3-0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CPU Cache

2 participants