Skip to content

Commit

Permalink
Add or extend structures needed to read HKEY_PERFORMANCE_DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
widdisd authored and dbwiddis committed Jun 29, 2018
1 parent 5d54515 commit 91a852d
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 121 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Features
* [#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 `c.s.j.platform.win32.Pdh` and a `c.s.j.platform.win32.PdhUtil` class to access them - [@dbwiddis](https://github.com/dbwiddis).
* [#980](https://github.com/java-native-access/jna/issues/980): Added `PERF_OBJECT_TYPE`, `PERF_COUNTER_BLOCK`, and `PERF_COUNTER_DEFINITION` to `c.s.j.platform.win32.WinPerf` and added `Pointer` constructors to ``PERF_INSTANCE_DEFINITION` and `PERF_DATA_BLOCK` - [@dbwiddis](https://github.com/dbwiddis).

Bug Fixes
---------
Expand Down
238 changes: 119 additions & 119 deletions contrib/platform/src/com/sun/jna/platform/win32/Pdh.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,125 +279,125 @@ public class PDH_TIME_INFO extends Structure {
*/
int PdhSetQueryTimeRange(HANDLE hQuery, PDH_TIME_INFO pInfo);

/**
* Returns the specified object's counter and instance names that exist on
* the specified computer or in the specified log file.
*
* @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 mszCounterList
* Caller-allocated buffer that receives a list of
* null-terminated counter names provided by the specified
* object. The list contains unique counter names. The list is
* terminated by two NULL characters. Set to NULL if the
* pcchCounterListLengthparameter is zero.
* @param pcchCounterListLength
* Size of the mszCounterList buffer, in TCHARs. If zero on input
* and the object exists, the function returns PDH_MORE_DATA and
* sets this parameter to the required buffer size. If the buffer
* is larger than the required size, the function sets this
* parameter to the actual size of the buffer that was used. If
* the specified size on input is greater than zero but less than
* the required size, you should not rely on the returned size to
* reallocate the buffer.
* @param mszInstanceList
* Caller-allocated buffer that receives a list of
* null-terminated instance names provided by the specified
* object. The list contains unique instance names. The list is
* terminated by two NULL characters. Set to NULL if
* pcchInstanceListLength is zero.
* @param pcchInstanceListLength
* Size of the mszInstanceList buffer, in TCHARs. If zero on
* input and the object exists, the function returns
* PDH_MORE_DATA and sets this parameter to the required buffer
* size. If the buffer is larger than the required size, the
* function sets this parameter to the actual size of the buffer
* that was used. If the specified size on input is greater than
* zero but less than the required size, you should not rely on
* the returned size to reallocate the buffer. If the specified
* object does not support variable instances, then the returned
* value will be zero. If the specified object does support
* variable instances, but does not currently have any instances,
* then the value returned is 2, which is the size of an empty
* MULTI_SZ list string.
* @param dwDetailLevel
* Detail level of the performance items to return. All items
* that are of the specified detail level or less will be
* returned.
* @param dwFlags
* This parameter must be zero.
* @return If the function succeeds, it returns ERROR_SUCCESS. If the
* function fails, the return value is a system error code or a PDH
* error code.
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa372677(v=vs.85).aspx">PdhEnumObjectItems</A>
*/
int PdhEnumObjectItems(String szDataSource, String szMachineName, String szObjectName, Pointer mszCounterList,
DWORDByReference pcchCounterListLength, Pointer mszInstanceList, DWORDByReference pcchInstanceListLength,
int dwDetailLevel, int dwFlags);
/**
* Returns the specified object's counter and instance names that exist on
* the specified computer or in the specified log file.
*
* @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 mszCounterList
* Caller-allocated buffer that receives a list of
* null-terminated counter names provided by the specified
* object. The list contains unique counter names. The list is
* terminated by two NULL characters. Set to NULL if the
* pcchCounterListLengthparameter is zero.
* @param pcchCounterListLength
* Size of the mszCounterList buffer, in TCHARs. If zero on input
* and the object exists, the function returns PDH_MORE_DATA and
* sets this parameter to the required buffer size. If the buffer
* is larger than the required size, the function sets this
* parameter to the actual size of the buffer that was used. If
* the specified size on input is greater than zero but less than
* the required size, you should not rely on the returned size to
* reallocate the buffer.
* @param mszInstanceList
* Caller-allocated buffer that receives a list of
* null-terminated instance names provided by the specified
* object. The list contains unique instance names. The list is
* terminated by two NULL characters. Set to NULL if
* pcchInstanceListLength is zero.
* @param pcchInstanceListLength
* Size of the mszInstanceList buffer, in TCHARs. If zero on
* input and the object exists, the function returns
* PDH_MORE_DATA and sets this parameter to the required buffer
* size. If the buffer is larger than the required size, the
* function sets this parameter to the actual size of the buffer
* that was used. If the specified size on input is greater than
* zero but less than the required size, you should not rely on
* the returned size to reallocate the buffer. If the specified
* object does not support variable instances, then the returned
* value will be zero. If the specified object does support
* variable instances, but does not currently have any instances,
* then the value returned is 2, which is the size of an empty
* MULTI_SZ list string.
* @param dwDetailLevel
* Detail level of the performance items to return. All items
* that are of the specified detail level or less will be
* returned.
* @param dwFlags
* This parameter must be zero.
* @return If the function succeeds, it returns ERROR_SUCCESS. If the
* function fails, the return value is a system error code or a PDH
* error code.
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa372677(v=vs.85).aspx">PdhEnumObjectItems</A>
*/
int PdhEnumObjectItems(String szDataSource, String szMachineName, String szObjectName, Pointer mszCounterList,
DWORDByReference pcchCounterListLength, Pointer mszInstanceList, DWORDByReference pcchInstanceListLength,
int dwDetailLevel, int dwFlags);

/**
* Returns the counter index corresponding to the specified counter name.
*
* @param szMachineName
* Null-terminated string that specifies the name of the computer
* where the specified counter is located. The computer name can
* be specified by the DNS name or the IP address. If NULL, the
* function uses the local computer.
* @param szNameBuffer
* Null-terminated string that contains the counter name.
* @param pdwIndex
* Index of the counter.
* @return If the function succeeds, it returns ERROR_SUCCESS. If the
* function fails, the return value is a system error code or a PDH
* error code.
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa372647(v=vs.85).aspx">PdhLookupPerfIndexByName</A>
*/
int PdhLookupPerfIndexByName(String szMachineName, String szNameBuffer, DWORDByReference pdwIndex);
/**
* Returns the counter index corresponding to the specified counter name.
*
* @param szMachineName
* Null-terminated string that specifies the name of the computer
* where the specified counter is located. The computer name can
* be specified by the DNS name or the IP address. If NULL, the
* function uses the local computer.
* @param szNameBuffer
* Null-terminated string that contains the counter name.
* @param pdwIndex
* Index of the counter.
* @return If the function succeeds, it returns ERROR_SUCCESS. If the
* function fails, the return value is a system error code or a PDH
* error code.
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa372647(v=vs.85).aspx">PdhLookupPerfIndexByName</A>
*/
int PdhLookupPerfIndexByName(String szMachineName, String szNameBuffer, DWORDByReference pdwIndex);

/**
* Returns the performance object name or counter name corresponding to the
* specified index.
*
* @param szMachineName
* Null-terminated string that specifies the name of the computer
* where the specified performance object or counter is located.
* The computer name can be specified by the DNS name or the IP
* address. If NULL, the function uses the local computer.
* @param dwNameIndex
* Index of the performance object or counter.
* @param szNameBuffer
* Caller-allocated buffer that receives the null-terminated name
* of the performance object or counter. Set to NULL if
* pcchNameBufferSize is zero.
* @param pcchNameBufferSize
* Size of the szNameBuffer buffer, in TCHARs. If zero on input,
* the function returns PDH_MORE_DATA and sets this parameter to
* the required buffer size. If the buffer is larger than the
* required size, the function sets this parameter to the actual
* size of the buffer that was used. If the specified size on
* input is greater than zero but less than the required size,
* you should not rely on the returned size to reallocate the
* buffer.
* @return If the function succeeds, it returns ERROR_SUCCESS. If the
* function fails, the return value is a system error code or a PDH
* error code.
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa372648(v=vs.85).aspx">PdhLookupPerfNameByIndex</A>
*/
int PdhLookupPerfNameByIndex(String szMachineName, int dwNameIndex, Pointer szNameBuffer,
DWORDByReference pcchNameBufferSize);
/**
* Returns the performance object name or counter name corresponding to the
* specified index.
*
* @param szMachineName
* Null-terminated string that specifies the name of the computer
* where the specified performance object or counter is located.
* The computer name can be specified by the DNS name or the IP
* address. If NULL, the function uses the local computer.
* @param dwNameIndex
* Index of the performance object or counter.
* @param szNameBuffer
* Caller-allocated buffer that receives the null-terminated name
* of the performance object or counter. Set to NULL if
* pcchNameBufferSize is zero.
* @param pcchNameBufferSize
* Size of the szNameBuffer buffer, in TCHARs. If zero on input,
* the function returns PDH_MORE_DATA and sets this parameter to
* the required buffer size. If the buffer is larger than the
* required size, the function sets this parameter to the actual
* size of the buffer that was used. If the specified size on
* input is greater than zero but less than the required size,
* you should not rely on the returned size to reallocate the
* buffer.
* @return If the function succeeds, it returns ERROR_SUCCESS. If the
* function fails, the return value is a system error code or a PDH
* error code.
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa372648(v=vs.85).aspx">PdhLookupPerfNameByIndex</A>
*/
int PdhLookupPerfNameByIndex(String szMachineName, int dwNameIndex, Pointer szNameBuffer,
DWORDByReference pcchNameBufferSize);
}
113 changes: 111 additions & 2 deletions contrib/platform/src/com/sun/jna/platform/win32/WinPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package com.sun.jna.platform.win32;

import java.util.List;

import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.Structure.FieldOrder;
import com.sun.jna.platform.win32.WinBase.SYSTEMTIME;
Expand Down Expand Up @@ -60,6 +60,15 @@ public class PERF_DATA_BLOCK extends Structure {
public LARGE_INTEGER PerfTime100nSec = new LARGE_INTEGER();
public int SystemNameLength;
public int SystemNameOffset;

public PERF_DATA_BLOCK() {
super();
}

public PERF_DATA_BLOCK(Pointer p) {
super(p);
read();
}
};

/**
Expand All @@ -75,6 +84,106 @@ public class PERF_INSTANCE_DEFINITION extends Structure {
public int UniqueID;
public int NameOffset;
public int NameLength;

public PERF_INSTANCE_DEFINITION() {
super();
}

public PERF_INSTANCE_DEFINITION(Pointer p) {
super(p);
read();
}
}

/**
* Describes object-specific performance information, for example, the
* number of instances of the object and the number of counters that the
* object defines.
*
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa373160(v=vs.85).aspx">
* PERF_OBJECT_TYPE</A>
*/
@FieldOrder({ "TotalByteLength", "DefinitionLength", "HeaderLength", "ObjectNameTitleIndex", "ObjectNameTitle",
"ObjectHelpTitleIndex", "ObjectHelpTitle", "DetailLevel", "NumCounters", "DefaultCounter", "NumInstances",
"CodePage", "PerfTime", "PerfFreq" })
public class PERF_OBJECT_TYPE extends Structure {
public int TotalByteLength;
public int DefinitionLength;
public int HeaderLength;
public int ObjectNameTitleIndex;
public int ObjectNameTitle; // always 32 bit
public int ObjectHelpTitleIndex;
public int ObjectHelpTitle; // always 32 bit
public int DetailLevel;
public int NumCounters;
public int DefaultCounter;
public int NumInstances;
public int CodePage;
public LARGE_INTEGER PerfTime;
public LARGE_INTEGER PerfFreq;

public PERF_OBJECT_TYPE() {
super();
}

public PERF_OBJECT_TYPE(Pointer p) {
super(p);
read();
}
}

/**
* Describes a performance counter.
*
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa373150(v=vs.85).aspx">
* PERF_COUNTER_DEFINITION</A>
*/
@FieldOrder({ "ByteLength", "CounterNameTitleIndex", "CounterNameTitle", "CounterHelpTitleIndex",
"CounterHelpTitle", "DefaultScale", "DetailLevel", "CounterType", "CounterSize", "CounterOffset" })
public class PERF_COUNTER_DEFINITION extends Structure {
public int ByteLength;
public int CounterNameTitleIndex;
public int CounterNameTitle; // always 32 bit
public int CounterHelpTitleIndex;
public int CounterHelpTitle; // always 32 bit
public NativeLong DefaultScale;
public int DetailLevel;
public int CounterType;
public int CounterSize;
public int CounterOffset;

public PERF_COUNTER_DEFINITION() {
super();
}

public PERF_COUNTER_DEFINITION(Pointer p) {
super(p);
read();
}
}

/**
* Describes the block of memory that contains the raw performance counter
* data for an object's counters.
*
* @see <A HREF=
* "https://msdn.microsoft.com/en-us/library/windows/desktop/aa373147(v=vs.85).aspx">
* PERF_COUNTER_BLOCK</A>
*/
@FieldOrder({ "ByteLength" })
public class PERF_COUNTER_BLOCK extends Structure {
public int ByteLength;

public PERF_COUNTER_BLOCK() {
super();
}

public PERF_COUNTER_BLOCK(Pointer p) {
super(p);
read();
}
}

int PERF_NO_INSTANCES = -1; // no instances (see NumInstances above)
Expand Down
Loading

0 comments on commit 91a852d

Please sign in to comment.