diff options
author | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
---|---|---|
committer | dotnet-bot <dotnet-bot@microsoft.com> | 2015-01-30 14:14:42 -0800 |
commit | ef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch) | |
tree | dee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/inc/cycletimer.h | |
download | coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2 coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip |
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/inc/cycletimer.h')
-rw-r--r-- | src/inc/cycletimer.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/inc/cycletimer.h b/src/inc/cycletimer.h new file mode 100644 index 0000000000..910bacd97e --- /dev/null +++ b/src/inc/cycletimer.h @@ -0,0 +1,57 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +// +// CycleTimer has methods related to getting cycle timer values. +// It uses an all-statics class as a namespace mechanism. +// + +#ifndef _CYCLETIMER_H_ +#define _CYCLETIMER_H_ + +#include "windef.h" + +class CycleTimer +{ + // This returns the value of the *non-thread-virtualized* cycle counter. + static unsigned __int64 GetCycleCount64(); + + + // This wraps GetCycleCount64 in the signature of QueryThreadCycleTime -- but note + // that it ignores the "thrd" argument. + static BOOL WINAPI DefaultQueryThreadCycleTime(__in HANDLE thrd, __out PULONG64 cyclesPtr); + + // The function pointer type for QueryThreadCycleTime. + typedef BOOL (WINAPI *QueryThreadCycleTimeSig)(__in HANDLE, __out PULONG64); + + // Returns a function pointer for QueryThreadCycleTime, or else BadFPtr. + static QueryThreadCycleTimeSig GetQueryThreadCycleTime(); + + // Initialized once from NULL to either BadFPtr or QueryThreadCycleTime. + static QueryThreadCycleTimeSig s_QueryThreadCycleTimeFPtr; + + public: + + // This method computes the number of cycles/sec for the current machine. The cycles are those counted + // by GetThreadCycleTime; we assume that these are of equal duration, though that is not necessarily true. + // If any OS interaction fails, returns 0.0. + static double CyclesPerSecond(); + + // Does a large number of queries, and returns the average of their overhead, so other measurements + // can adjust for this. + static unsigned __int64 QueryOverhead(); + + // There's no "native" atomic add for 64 bit, so we have this convenience function. + static void InterlockedAddU64(unsigned __int64* loc, unsigned __int64 amount); + + // Attempts to query the cycle counter of the current thread. If successful, returns "true" and sets + // *cycles to the cycle counter value. Otherwise, returns false. Note that the value returned is (currently) + // virtualized to the current thread only on Windows; on non-windows x86/x64 platforms, directly reads + // the cycle counter and returns that value. + static bool GetThreadCyclesS(unsigned __int64* cycles); +}; + +#endif // _CYCLETIMER_H_ + |