Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Unified Diff: src/base/platform/time.h

Issue 1977983003: [base] Implement CPU time on Windows. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/base/cpu.cc ('k') | src/base/platform/time.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/platform/time.h
diff --git a/src/base/platform/time.h b/src/base/platform/time.h
index e17fc1d716dd85e54440f9eeced6ff7f65b3bf1b..be62014f91db7e0535d47cc7aa25737d9c1801f9 100644
--- a/src/base/platform/time.h
+++ b/src/base/platform/time.h
@@ -12,6 +12,9 @@
#include "src/base/bits.h"
#include "src/base/macros.h"
#include "src/base/safe_math.h"
+#if V8_OS_WIN
+#include "src/base/win32-headers.h"
+#endif
// Forward declarations.
extern "C" {
@@ -380,17 +383,42 @@ class ThreadTicks final : public time_internal::TimeBase<ThreadTicks> {
// Returns true if ThreadTicks::Now() is supported on this system.
static bool IsSupported();
+ // Waits until the initialization is completed. Needs to be guarded with a
+ // call to IsSupported().
+ static void WaitUntilInitialized() {
+#if V8_OS_WIN
+ WaitUntilInitializedWin();
+#endif
+ }
+
// Returns thread-specific CPU-time on systems that support this feature.
// Needs to be guarded with a call to IsSupported(). Use this timer
// to (approximately) measure how much time the calling thread spent doing
// actual work vs. being de-scheduled. May return bogus results if the thread
// migrates to another CPU between two calls. Returns an empty ThreadTicks
- // object until the initialization is completed.
+ // object until the initialization is completed. If a clock reading is
+ // absolutely needed, call WaitUntilInitialized() before this method.
static ThreadTicks Now();
+#if V8_OS_WIN
+ // Similar to Now() above except this returns thread-specific CPU time for an
+ // arbitrary thread. All comments for Now() method above apply apply to this
+ // method as well.
+ static ThreadTicks GetForThread(const HANDLE& thread_handle);
+#endif
+
private:
- // This is for internal use and testing. Ticks are in microseconds.
+ // Please use Now() or GetForThread() to create a new object. This is for
+ // internal use and testing. Ticks are in microseconds.
explicit ThreadTicks(int64_t ticks) : TimeBase(ticks) {}
+
+#if V8_OS_WIN
+ // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't
+ // been measured yet. Needs to be guarded with a call to IsSupported().
+ static double TSCTicksPerSecond();
+ static bool IsSupportedWin();
+ static void WaitUntilInitializedWin();
+#endif
};
} // namespace base
« no previous file with comments | « src/base/cpu.cc ('k') | src/base/platform/time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698