summaryrefslogtreecommitdiff
path: root/src/ToolBox/superpmi/superpmi/cycletimer.cpp
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
commit4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch)
tree98110734c91668dfdbb126fcc0e15ddbd93738ca /src/ToolBox/superpmi/superpmi/cycletimer.cpp
parentfa45f57ed55137c75ac870356a1b8f76c84b229c (diff)
downloadcoreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/ToolBox/superpmi/superpmi/cycletimer.cpp')
-rw-r--r--src/ToolBox/superpmi/superpmi/cycletimer.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/ToolBox/superpmi/superpmi/cycletimer.cpp b/src/ToolBox/superpmi/superpmi/cycletimer.cpp
new file mode 100644
index 0000000000..de0e19b935
--- /dev/null
+++ b/src/ToolBox/superpmi/superpmi/cycletimer.cpp
@@ -0,0 +1,60 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+#include "standardpch.h"
+#include "cycletimer.h"
+
+CycleTimer::CycleTimer()
+{
+ start = 0;
+ stop = 0;
+ overhead = QueryOverhead();
+}
+
+CycleTimer::~CycleTimer()
+{
+}
+
+void CycleTimer::Start()
+{
+ BOOL retVal = QueryThreadCycleTime(GetCurrentThread(), &start);
+
+ if(retVal == FALSE)
+ {
+ LogError("CycleTimer::Start unable to QPC. error was 0x%08x", ::GetLastError());
+ ::__debugbreak();
+ }
+}
+
+void CycleTimer::Stop()
+{
+ BOOL retVal = QueryThreadCycleTime(GetCurrentThread(), &stop);
+
+ if(retVal == FALSE)
+ {
+ LogError("CycleTimer::Stop unable to QPC. error was 0x%08x", ::GetLastError());
+ ::__debugbreak();
+ }
+}
+
+unsigned __int64 CycleTimer::GetCycles()
+{
+ return stop - start - overhead;
+}
+
+unsigned __int64 CycleTimer::QueryOverhead()
+{
+ unsigned __int64 tot = 0;
+ unsigned __int64 startCycles;
+ unsigned __int64 endCycles;
+ const int N = 1000;
+ for (int i = 0; i < N; i++)
+ {
+ QueryThreadCycleTime(GetCurrentThread(), &startCycles);
+ QueryThreadCycleTime(GetCurrentThread(), &endCycles);
+ tot += (endCycles-startCycles);
+ }
+ return tot/N;
+} \ No newline at end of file