From 72925a4496687170954683a485be5cd0b4b916d0 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Wed, 27 Jun 2018 21:11:31 -0700 Subject: [PATCH] Tabs are evil. --- CHANGES.md | 2 +- .../com/sun/jna/platform/win32/PdhUtil.java | 152 +++++++++--------- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 65e66e1991..c03c1be504 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,7 +19,7 @@ Features * [#954](https://github.com/java-native-access/jna/pull/954): Add `c.s.j.Structure.FieldOrder` annotation to define the field order of a structures without implementing `Structure#getFieldOrder()` - [@idosu](https://github.com/idosu). * [#959](https://github.com/java-native-access/jna/pull/959): Added `GetProcessTimes` and `GetProcessIoCounters` to `com.sun.jna.platform.win32.Kernel32` - [@dbwiddis](https://github.com/dbwiddis). * [#952](https://github.com/java-native-access/jna/issues/952): Added `CreateMutex`, `OpenMutex` and `ReleaseMutex` to `com.sun.jna.platform.win32.Kernel32` - [@matthiasblaesing](https://github.com/matthiasblaesing). -* [#973](https://github.com/java-native-access/jna/issues/973): Added `PdhLookupPerfNameByIndex`, `PdhLookupPerfIndexByName`, and `PdhEnumObjectItems` to `com.sun.jna.platform.win32.Pdh` - [@dbwiddis](https://github.com/dbwiddis). +* [#973](https://github.com/java-native-access/jna/issues/973): Added `PdhLookupPerfNameByIndex`, `PdhLookupPerfIndexByName`, and `PdhEnumObjectItems` to `c.s.j.platform.win32.Pdh` and a `c.s.j.platform.win32.PdhUtil` class to access them - [@dbwiddis](https://github.com/dbwiddis). Bug Fixes --------- diff --git a/contrib/platform/src/com/sun/jna/platform/win32/PdhUtil.java b/contrib/platform/src/com/sun/jna/platform/win32/PdhUtil.java index 1e929c74e5..7b8788d038 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/PdhUtil.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/PdhUtil.java @@ -72,32 +72,32 @@ public static String PdhLookupPerfNameByIndex(String szMachineName, int dwNameIn } /** - * Utility method to call Pdh's PdhEnumObjectItems that allocates the - * required memory for the mszCounterList parameter based on the type - * mapping used, calls to PdhEnumObjectItems, and returns the received lists - * of strings. - * - * @param szDataSource - * String that specifies the name of the log file used to - * enumerate the counter and instance names. If NULL, the - * function uses the computer specified in the szMachineName - * parameter to enumerate the names. - * @param szMachineName - * String that specifies the name of the computer that contains - * the counter and instance names that you want to enumerate. - * Include the leading slashes in the computer name, for example, - * \\computername. If the szDataSource parameter is NULL, you can - * set szMachineName to NULL to specify the local computer. - * @param szObjectName - * String that specifies the name of the object whose counter and - * instance names you want to enumerate. - * @param dwDetailLevel - * Detail level of the performance items to return. All items - * that are of the specified detail level or less will be - * returned. - * @return Returns a List of Strings of the counters for the object. - */ - public static List PdhEnumObjectItemCounters(String szDataSource, String szMachineName, String szObjectName, + * Utility method to call Pdh's PdhEnumObjectItems that allocates the + * required memory for the mszCounterList parameter based on the type + * mapping used, calls to PdhEnumObjectItems, and returns the received lists + * of strings. + * + * @param szDataSource + * String that specifies the name of the log file used to + * enumerate the counter and instance names. If NULL, the + * function uses the computer specified in the szMachineName + * parameter to enumerate the names. + * @param szMachineName + * String that specifies the name of the computer that contains + * the counter and instance names that you want to enumerate. + * Include the leading slashes in the computer name, for example, + * \\computername. If the szDataSource parameter is NULL, you can + * set szMachineName to NULL to specify the local computer. + * @param szObjectName + * String that specifies the name of the object whose counter and + * instance names you want to enumerate. + * @param dwDetailLevel + * Detail level of the performance items to return. All items + * that are of the specified detail level or less will be + * returned. + * @return Returns a List of Strings of the counters for the object. + */ + public static List PdhEnumObjectItemCounters(String szDataSource, String szMachineName, String szObjectName, int dwDetailLevel) { int charToBytes = Boolean.getBoolean("w32.ascii") ? 1 : Native.WCHAR_SIZE; @@ -114,7 +114,7 @@ public static List PdhEnumObjectItemCounters(String szDataSource, String pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, 0); // Fetch counters - List counters = new ArrayList(); + List counters = new ArrayList(); int offset = 0; while (offset < mszCounterList.size()) { String s = null; @@ -128,57 +128,57 @@ public static List PdhEnumObjectItemCounters(String szDataSource, String break; } counters.add(s); - // Increment for string + null terminator + // Increment for string + null terminator offset += (s.length() + 1) * charToBytes; } - return counters; - } - - /** - * Utility method to call Pdh's PdhEnumObjectItems that allocates the - * required memory for the mszInstanceList parameters based on the type - * mapping used, calls to PdhEnumObjectItems, and returns the received lists - * of strings. - * - * @param szDataSource - * String that specifies the name of the log file used to - * enumerate the counter and instance names. If NULL, the - * function uses the computer specified in the szMachineName - * parameter to enumerate the names. - * @param szMachineName - * String that specifies the name of the computer that contains - * the counter and instance names that you want to enumerate. - * Include the leading slashes in the computer name, for example, - * \\computername. If the szDataSource parameter is NULL, you can - * set szMachineName to NULL to specify the local computer. - * @param szObjectName - * String that specifies the name of the object whose counter and - * instance names you want to enumerate. - * @param dwDetailLevel - * Detail level of the performance items to return. All items - * that are of the specified detail level or less will be - * returned. - * @return Returns a Lists of Strings of the instances of the object. - */ - public static List PdhEnumObjectItemInstances(String szDataSource, String szMachineName, - String szObjectName, int dwDetailLevel) { - int charToBytes = Boolean.getBoolean("w32.ascii") ? 1 : Native.WCHAR_SIZE; - - // Call once to get string lengths - DWORDByReference pcchCounterListLength = new DWORDByReference(new DWORD(0)); - DWORDByReference pcchInstanceListLength = new DWORDByReference(new DWORD(0)); - Pdh.INSTANCE.PdhEnumObjectItems(szDataSource, szMachineName, szObjectName, null, pcchCounterListLength, null, - pcchInstanceListLength, dwDetailLevel, 0); - - // Allocate memory and call again to populate strings - Memory mszCounterList = new Memory(pcchCounterListLength.getValue().intValue() * charToBytes); - Memory mszInstanceList = new Memory(pcchInstanceListLength.getValue().intValue() * charToBytes); - Pdh.INSTANCE.PdhEnumObjectItems(szDataSource, szMachineName, szObjectName, mszCounterList, - pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, 0); - - List instances = new ArrayList(); - int offset = 0; + return counters; + } + + /** + * Utility method to call Pdh's PdhEnumObjectItems that allocates the + * required memory for the mszInstanceList parameters based on the type + * mapping used, calls to PdhEnumObjectItems, and returns the received lists + * of strings. + * + * @param szDataSource + * String that specifies the name of the log file used to + * enumerate the counter and instance names. If NULL, the + * function uses the computer specified in the szMachineName + * parameter to enumerate the names. + * @param szMachineName + * String that specifies the name of the computer that contains + * the counter and instance names that you want to enumerate. + * Include the leading slashes in the computer name, for example, + * \\computername. If the szDataSource parameter is NULL, you can + * set szMachineName to NULL to specify the local computer. + * @param szObjectName + * String that specifies the name of the object whose counter and + * instance names you want to enumerate. + * @param dwDetailLevel + * Detail level of the performance items to return. All items + * that are of the specified detail level or less will be + * returned. + * @return Returns a Lists of Strings of the instances of the object. + */ + public static List PdhEnumObjectItemInstances(String szDataSource, String szMachineName, + String szObjectName, int dwDetailLevel) { + int charToBytes = Boolean.getBoolean("w32.ascii") ? 1 : Native.WCHAR_SIZE; + + // Call once to get string lengths + DWORDByReference pcchCounterListLength = new DWORDByReference(new DWORD(0)); + DWORDByReference pcchInstanceListLength = new DWORDByReference(new DWORD(0)); + Pdh.INSTANCE.PdhEnumObjectItems(szDataSource, szMachineName, szObjectName, null, pcchCounterListLength, null, + pcchInstanceListLength, dwDetailLevel, 0); + + // Allocate memory and call again to populate strings + Memory mszCounterList = new Memory(pcchCounterListLength.getValue().intValue() * charToBytes); + Memory mszInstanceList = new Memory(pcchInstanceListLength.getValue().intValue() * charToBytes); + Pdh.INSTANCE.PdhEnumObjectItems(szDataSource, szMachineName, szObjectName, mszCounterList, + pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, 0); + + List instances = new ArrayList(); + int offset = 0; while (offset < mszInstanceList.size()) { String s = null; if (charToBytes == 1) { @@ -195,6 +195,6 @@ public static List PdhEnumObjectItemInstances(String szDataSource, Strin offset += (s.length() + 1) * charToBytes; } - return instances; + return instances; } }