Skip to content

Commit

Permalink
UsbDkUtil: Introduce CStopWatch class
Browse files Browse the repository at this point in the history
This class does elapsed time measurement.

Signed-off-by: Dmitry Fleytman <[email protected]>
  • Loading branch information
Dmitry Fleytman committed Feb 19, 2017
1 parent 2f54f6e commit 435ea8d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions UsbDk/UsbDkUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
21 changes: 21 additions & 0 deletions UsbDk/UsbDkUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 435ea8d

Please sign in to comment.