Skip to content

Commit 5ec9eeb

Browse files
committed
Merge pull request #547 from dbwiddis/master
Add GetSystemTimes() to Kernel32
2 parents b975cc1 + 4b4fc88 commit 5ec9eeb

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Features
1717
* [#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).
1818
* [#535](https://github.com/java-native-access/jna/pull/535): Added `GetDesktopWindow` to `com.sun.jna.platform.win32.User32` - [@mlfreeman2](https://github.com/mlfreeman2).
1919
* [#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).
20+
* [#547](https://github.com/java-native-access/jna/pull/547): Added `GetSystemTimes` to `com.sun.jna.platform.win32.Kernel32` - [@dbwiddis](https://github.com/dbwiddis).
2021

2122
Bug Fixes
2223
---------

contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java

+26
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,32 @@ boolean ReadFile(HANDLE hFile, byte[] lpBuffer, int nNumberOfBytesToRead,
181181
*/
182182
boolean SetLocalTime(SYSTEMTIME lpSystemTime);
183183

184+
/**
185+
* Retrieves system timing information. On a multiprocessor system, the
186+
* values returned are the sum of the designated times across all
187+
* processors.
188+
*
189+
* @param lpIdleTime
190+
* A pointer to a {@link WinBase.FILETIME} structure that
191+
* receives the amount of time that the system has been idle.
192+
* @param lpKernelTime
193+
* A pointer to a {@link WinBase.FILETIME} structure that
194+
* receives the amount of time that the system has spent
195+
* executing in Kernel mode (including all threads in all
196+
* processes, on all processors). This time value also includes
197+
* the amount of time the system has been idle.
198+
* @param lpUserTime
199+
* A pointer to a {@link WinBase.FILETIME} structure that
200+
* receives the amount of time that the system has spent
201+
* executing in User mode (including all threads in all
202+
* processes, on all processors).
203+
* @return {@code true} if the function succeeds, {@code false} otherwise.
204+
* If the function fails, call {@link #GetLastError()} to get extended error
205+
* information.
206+
* @see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724400(v=vs.85).aspx">GetSystemTimes documentation</a>
207+
*/
208+
boolean GetSystemTimes(WinBase.FILETIME lpIdleTime, WinBase.FILETIME lpKernelTime, WinBase.FILETIME lpUserTime);
209+
184210
/**
185211
* The GetTickCount function retrieves the number of milliseconds that have
186212
* elapsed since the system was started, up to 49.7 days.

contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java

+16
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,22 @@ public void testGetSystemInfo() {
384384
assertTrue(lpSystemInfo.dwNumberOfProcessors.intValue() > 0);
385385
}
386386

387+
public void testGetSystemTimes() {
388+
Kernel32 kernel = Kernel32.INSTANCE;
389+
WinBase.FILETIME lpIdleTime = new WinBase.FILETIME();
390+
WinBase.FILETIME lpKernelTime = new WinBase.FILETIME();
391+
WinBase.FILETIME lpUserTime = new WinBase.FILETIME();
392+
boolean succ = kernel.GetSystemTimes(lpIdleTime, lpKernelTime, lpUserTime);
393+
assertTrue(succ);
394+
long idleTime = WinBase.FILETIME.dateToFileTime(lpIdleTime.toDate());
395+
long kernelTime = WinBase.FILETIME.dateToFileTime(lpKernelTime.toDate());
396+
long userTime = WinBase.FILETIME.dateToFileTime(lpUserTime.toDate());
397+
// All should be >= 0. kernel includes idle.
398+
assertTrue(idleTime >= 0);
399+
assertTrue(kernelTime >= idleTime);
400+
assertTrue(userTime >= 0);
401+
}
402+
387403
public void testIsWow64Process() {
388404
try {
389405
IntByReference isWow64 = new IntByReference(42);

0 commit comments

Comments
 (0)