UsbDkUtil: Introduce CStopWatch class

This class does elapsed time measurement.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit is contained in:
Dmitry Fleytman 2017-02-19 10:41:34 +02:00
parent 2f54f6e20f
commit 435ea8de58
2 changed files with 34 additions and 0 deletions

View file

@ -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;
}

View file

@ -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);