summaryrefslogtreecommitdiff
path: root/UsbDk
diff options
context:
space:
mode:
authorDmitry Fleytman <dfleytma@redhat.com>2017-02-19 10:41:34 +0200
committerDmitry Fleytman <dfleytma@redhat.com>2017-02-19 11:13:42 +0200
commit435ea8de58857c0999261cbae0721d8bdc7b948e (patch)
tree9e96cd9de4d4fda9ed62b68e05feb18feb24bbf4 /UsbDk
parent2f54f6e20ffba8044234cf38384fe4fc94cf7170 (diff)
UsbDkUtil: Introduce CStopWatch class
This class does elapsed time measurement. Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Diffstat (limited to 'UsbDk')
-rw-r--r--UsbDk/UsbDkUtil.cpp13
-rw-r--r--UsbDk/UsbDkUtil.h21
2 files changed, 34 insertions, 0 deletions
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);