Skip to content

Commit

Permalink
Add GetSystemTimes() to Kernel32
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Nov 30, 2015
1 parent 7fe56b6 commit 27a1872
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Features
* [#535](https://github.com/java-native-access/jna/pull/535): Added `SHEmptyRecycleBin`, `ShellExecuteEx` to `com.sun.jna.platform.win32.Shell32` - [@mlfreeman2](https://github.com/mlfreeman2).
* [#535](https://github.com/java-native-access/jna/pull/535): Added `GetDesktopWindow` to `com.sun.jna.platform.win32.User32` - [@mlfreeman2](https://github.com/mlfreeman2).
* [#543](https://github.com/java-native-access/jna/pull/543): Added `ProcessIdToSessionId`, `LoadLibraryEx`, `FreeLibrary` and `Find/Load/Lock/SizeofResource` to `com.sun.jna.platform.win32.Kernel32` - [@mlfreeman2](https://github.com/mlfreeman2).
* [#547](https://github.com/java-native-access/jna/pull/547): Added `GetSystemTimes` to `com.sun.jna.platform.win32.Kernel32` - [@dbwiddis](https://github.com/dbwiddis).

Bug Fixes
---------
Expand Down
26 changes: 26 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,32 @@ boolean ReadFile(HANDLE hFile, byte[] lpBuffer, int nNumberOfBytesToRead,
*/
boolean SetLocalTime(SYSTEMTIME lpSystemTime);

/**
* Retrieves system timing information. On a multiprocessor system, the
* values returned are the sum of the designated times across all
* processors.
*
* @param lpIdleTime
* A pointer to a {@link WinBase.FILETIME} structure that
* receives the amount of time that the system has been idle.
* @param lpKernelTime
* A pointer to a {@link WinBase.FILETIME} structure that
* receives the amount of time that the system has spent
* executing in Kernel mode (including all threads in all
* processes, on all processors). This time value also includes
* the amount of time the system has been idle.
* @param lpUserTime
* A pointer to a {@link WinBase.FILETIME} structure that
* receives the amount of time that the system has spent
* executing in User mode (including all threads in all
* processes, on all processors).
* @return {@code true} if the function succeeds, {@code false} otherwise.
* If the function fails, call {@link #GetLastError()} to get extended error
* information.
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724400(v=vs.85).aspx">GetSystemTimes documentation</a>
*/
boolean GetSystemTimes(WinBase.FILETIME lpIdleTime, WinBase.FILETIME lpKernelTime, WinBase.FILETIME lpUserTime);

/**
* The GetTickCount function retrieves the number of milliseconds that have
* elapsed since the system was started, up to 49.7 days.
Expand Down
16 changes: 16 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,22 @@ public void testGetSystemInfo() {
assertTrue(lpSystemInfo.dwNumberOfProcessors.intValue() > 0);
}

public void testGetSystemTimes() {
Kernel32 kernel = Kernel32.INSTANCE;
WinBase.FILETIME lpIdleTime = new WinBase.FILETIME();
WinBase.FILETIME lpKernelTime = new WinBase.FILETIME();
WinBase.FILETIME lpUserTime = new WinBase.FILETIME();
boolean succ = kernel.GetSystemTimes(lpIdleTime, lpKernelTime, lpUserTime);
assertTrue(succ);
long idleTime = WinBase.FILETIME.dateToFileTime(lpIdleTime.toDate());
long kernelTime = WinBase.FILETIME.dateToFileTime(lpKernelTime.toDate());
long userTime = WinBase.FILETIME.dateToFileTime(lpUserTime.toDate());
// All should be >= 0. kernel includes idle.
assertTrue(idle >= 0);
assertTrue(kernel >= idle);
assertTrue(user >= 0);
}

public void testIsWow64Process() {
try {
IntByReference isWow64 = new IntByReference(42);
Expand Down

0 comments on commit 27a1872

Please sign in to comment.