Skip to content

Zero-check PDH counter and instance lists, add English index lookup#988

Merged
matthiasblaesing merged 2 commits into
java-native-access:masterfrom
dbwiddis:pdhutil
Jul 21, 2018
Merged

Zero-check PDH counter and instance lists, add English index lookup#988
matthiasblaesing merged 2 commits into
java-native-access:masterfrom
dbwiddis:pdhutil

Conversation

@dbwiddis

Copy link
Copy Markdown
Contributor

The util methods I submitted in #973 do not handle zero-length results (e.g., no counters or instances) well, throwing an IllegalArgumentException when attempting to instantiate Memory. I've added checks to return sane values.

Also I've added a Util method that looks up the counter index from the English name using the registry, to permit easier localization of counter strings.

@dbwiddis
dbwiddis force-pushed the pdhutil branch 5 times, most recently from 3bbfe7e to 53e5993 Compare July 14, 2018 17:14
// Can't allocate 0 memory
if (pcchCounterListLength.getValue().intValue() < 1 || pcchInstanceListLength.getValue().intValue() < 1) {
return counters;
}

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.

Is it possible, that only one of the lists has content? I would special case the 0-elements case and replace the memory with a null pointer. From my experience that is the expected usage of the API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. If it's 0 you can null it and it works; but if it's nonzero you can't null it. I decided to go the route of just setting the "other" value to 0 and not asking for data I won't use.

@dbwiddis
dbwiddis force-pushed the pdhutil branch 2 times, most recently from d318e62 to f937b4c Compare July 19, 2018 04:24
@matthiasblaesing
matthiasblaesing merged commit 57a9dd0 into java-native-access:master Jul 21, 2018
@dbwiddis
dbwiddis deleted the pdhutil branch July 21, 2018 16:34
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.

2 participants