summaryrefslogtreecommitdiff
path: root/shared/perf.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:11:09 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:11:09 +0200
commit9cc790869ed3905c78c7eeeb0bb44f800b3f2af4 (patch)
tree1c085bbf2302be294866c4fc6e0d225f8abbc346 /shared/perf.h
parent3.14 (diff)
downloadFreeFileSync-9cc790869ed3905c78c7eeeb0bb44f800b3f2af4.tar.gz
FreeFileSync-9cc790869ed3905c78c7eeeb0bb44f800b3f2af4.tar.bz2
FreeFileSync-9cc790869ed3905c78c7eeeb0bb44f800b3f2af4.zip
3.15
Diffstat (limited to 'shared/perf.h')
-rw-r--r--shared/perf.h31
1 files changed, 22 insertions, 9 deletions
diff --git a/shared/perf.h b/shared/perf.h
index 1ad4650d..641eee2b 100644
--- a/shared/perf.h
+++ b/shared/perf.h
@@ -8,13 +8,15 @@
#define DEBUG_PERF_HEADER
#include <sstream>
+
+#ifdef __WXWINDOWS__
+#include <wx/msw/wrapwin.h> //includes "windows.h"
+#else
//#define WIN32_LEAN_AND_MEAN -> not in a header
-/*
#include <windows.h>
#undef max
#undef min
-*/
-#include <wx/msw/wrapwin.h> //includes "windows.h"
+#endif
#ifdef __MINGW32__
@@ -28,37 +30,48 @@ class CpuTimer
public:
class TimerError {};
- DEPRECATED(CpuTimer()) : resultWasShown(false), startTime(), frequency()
+ DEPRECATED(CpuTimer()) : frequency(), startTime(), resultShown(false)
{
+ SetThreadAffinity dummy;
if (!::QueryPerformanceFrequency(&frequency)) throw TimerError();
if (!::QueryPerformanceCounter (&startTime)) throw TimerError();
}
~CpuTimer()
{
- if (!resultWasShown)
+ if (!resultShown)
showResult();
}
void showResult()
{
+ SetThreadAffinity dummy;
LARGE_INTEGER currentTime = {};
if (!::QueryPerformanceCounter(&currentTime)) throw TimerError();
- const long delta = 1000.0 * (currentTime.QuadPart - startTime.QuadPart) / frequency.QuadPart;
+ const long delta = static_cast<long>(1000.0 * (currentTime.QuadPart - startTime.QuadPart) / frequency.QuadPart);
std::ostringstream ss;
ss << delta << " ms";
::MessageBoxA(NULL, ss.str().c_str(), "Timer", 0);
- resultWasShown = true;
+ resultShown = true;
if (!::QueryPerformanceCounter(&startTime)) throw TimerError(); //don't include call to MessageBox()!
}
private:
- bool resultWasShown;
- LARGE_INTEGER startTime;
+ class SetThreadAffinity
+ {
+ public:
+ SetThreadAffinity() : oldmask(::SetThreadAffinityMask(::GetCurrentThread(), 1)) { if (oldmask == 0) throw TimerError(); }
+ ~SetThreadAffinity() { ::SetThreadAffinityMask(::GetCurrentThread(), oldmask); }
+ private:
+ const DWORD_PTR oldmask;
+ };
+
LARGE_INTEGER frequency;
+ LARGE_INTEGER startTime;
+ bool resultShown;
};
//two macros for quick performance measurements
bgstack15