| ... | ... | @@ -10849,9 +10849,40 @@ fn nowWindows(clock: Io.Clock) Io.Clock.Error!Io.Timestamp { |
| 10849 | 10849 | const result = (@as(u96, qpc) * scale) >> 32; |
| 10850 | 10850 | return .{ .nanoseconds = @intCast(result) }; |
| 10851 | 10851 | }, |
| 10852 | | .cpu_process, |
| 10853 | | .cpu_thread, |
| 10854 | | => return error.UnsupportedClock, |
| 10852 | .cpu_process => { |
| 10853 | const handle = windows.GetCurrentProcess(); |
| 10854 | var times: windows.KERNEL_USER_TIMES = undefined; |
| 10855 | |
| 10856 | // https://github.com/reactos/reactos/blob/master/ntoskrnl/ps/query.c#L442-L485 |
| 10857 | if (windows.ntdll.NtQueryInformationProcess( |
| 10858 | handle, |
| 10859 | windows.PROCESSINFOCLASS.Times, |
| 10860 | &times, |
| 10861 | @sizeOf(windows.KERNEL_USER_TIMES), |
| 10862 | null, |
| 10863 | ) != .SUCCESS) |
| 10864 | return error.Unexpected; |
| 10865 | |
| 10866 | const sum = @as(i96, times.UserTime) + @as(i96, times.KernelTime); |
| 10867 | return .{ .nanoseconds = sum * 100 }; |
| 10868 | }, |
| 10869 | .cpu_thread => { |
| 10870 | const handle = windows.GetCurrentThread(); |
| 10871 | var times: windows.KERNEL_USER_TIMES = undefined; |
| 10872 | |
| 10873 | // https://github.com/reactos/reactos/blob/master/ntoskrnl/ps/query.c#L2971-L3019 |
| 10874 | if (windows.ntdll.NtQueryInformationThread( |
| 10875 | handle, |
| 10876 | windows.THREADINFOCLASS.Times, |
| 10877 | &times, |
| 10878 | @sizeOf(windows.KERNEL_USER_TIMES), |
| 10879 | null, |
| 10880 | ) != .SUCCESS) |
| 10881 | return error.Unexpected; |
| 10882 | |
| 10883 | const sum = @as(i96, times.UserTime) + @as(i96, times.KernelTime); |
| 10884 | return .{ .nanoseconds = sum * 100 }; |
| 10885 | }, |
| 10855 | 10886 | } |
| 10856 | 10887 | } |
| 10857 | 10888 | |