diff --git a/UsbDk/UsbDkUtil.cpp b/UsbDk/UsbDkUtil.cpp index 6f67cbd..aed6a88 100644 --- a/UsbDk/UsbDkUtil.cpp +++ b/UsbDk/UsbDkUtil.cpp @@ -180,3 +180,16 @@ UsbDkCreateCurrentProcessHandle(HANDLE &Handle) return status; } + +CStopWatch& CStopWatch::operator= (const CStopWatch& Other) +{ + m_StartTime = Other.m_StartTime; + return *this; +} + +LONGLONG CStopWatch::Time100Ns() const +{ + LARGE_INTEGER Now; + KeQueryTickCount(&Now); + return (Now.QuadPart - m_StartTime.QuadPart) * m_TimeIncrement; +} diff --git a/UsbDk/UsbDkUtil.h b/UsbDk/UsbDkUtil.h index 36a4843..6a042be 100644 --- a/UsbDk/UsbDkUtil.h +++ b/UsbDk/UsbDkUtil.h @@ -632,5 +632,26 @@ LONGLONG MillisecondsTo100Nanoseconds(LONGLONG Milliseconds) return Milliseconds * 10 * 1000; } +static inline +LONGLONG HundredNsToMilliseconds(LONGLONG HundredNs) +{ + return HundredNs / (10 * 1000); +} + +class CStopWatch +{ +public: + CStopWatch() {} + CStopWatch(const CStopWatch& Other) : CStopWatch() { *this = Other; } + CStopWatch& operator= (const CStopWatch& Other); + + void Start() { KeQueryTickCount(&m_StartTime); } + LONGLONG Time100Ns() const; + LONGLONG TimeMs() const { return HundredNsToMilliseconds(Time100Ns()); } +private: + const ULONG m_TimeIncrement = KeQueryTimeIncrement(); + LARGE_INTEGER m_StartTime = {}; +}; + NTSTATUS UsbDkCreateCurrentProcessHandle(HANDLE &Handle);