| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_BASE_PLATFORM_TIME_H_ | 5 #ifndef V8_BASE_PLATFORM_TIME_H_ |
| 6 #define V8_BASE_PLATFORM_TIME_H_ | 6 #define V8_BASE_PLATFORM_TIME_H_ |
| 7 | 7 |
| 8 #include <ctime> | 8 #include <ctime> |
| 9 #include <iosfwd> | 9 #include <iosfwd> |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "src/base/bits.h" | 12 #include "src/base/bits.h" |
| 13 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
| 14 #include "src/base/safe_math.h" | 14 #include "src/base/safe_math.h" |
| 15 #if V8_OS_WIN |
| 16 #include "src/base/win32-headers.h" |
| 17 #endif |
| 15 | 18 |
| 16 // Forward declarations. | 19 // Forward declarations. |
| 17 extern "C" { | 20 extern "C" { |
| 18 struct _FILETIME; | 21 struct _FILETIME; |
| 19 struct mach_timespec; | 22 struct mach_timespec; |
| 20 struct timespec; | 23 struct timespec; |
| 21 struct timeval; | 24 struct timeval; |
| 22 } | 25 } |
| 23 | 26 |
| 24 namespace v8 { | 27 namespace v8 { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 376 |
| 374 // Represents a clock, specific to a particular thread, than runs only while the | 377 // Represents a clock, specific to a particular thread, than runs only while the |
| 375 // thread is running. | 378 // thread is running. |
| 376 class ThreadTicks final : public time_internal::TimeBase<ThreadTicks> { | 379 class ThreadTicks final : public time_internal::TimeBase<ThreadTicks> { |
| 377 public: | 380 public: |
| 378 ThreadTicks() : TimeBase(0) {} | 381 ThreadTicks() : TimeBase(0) {} |
| 379 | 382 |
| 380 // Returns true if ThreadTicks::Now() is supported on this system. | 383 // Returns true if ThreadTicks::Now() is supported on this system. |
| 381 static bool IsSupported(); | 384 static bool IsSupported(); |
| 382 | 385 |
| 386 // Waits until the initialization is completed. Needs to be guarded with a |
| 387 // call to IsSupported(). |
| 388 static void WaitUntilInitialized() { |
| 389 #if V8_OS_WIN |
| 390 WaitUntilInitializedWin(); |
| 391 #endif |
| 392 } |
| 393 |
| 383 // Returns thread-specific CPU-time on systems that support this feature. | 394 // Returns thread-specific CPU-time on systems that support this feature. |
| 384 // Needs to be guarded with a call to IsSupported(). Use this timer | 395 // Needs to be guarded with a call to IsSupported(). Use this timer |
| 385 // to (approximately) measure how much time the calling thread spent doing | 396 // to (approximately) measure how much time the calling thread spent doing |
| 386 // actual work vs. being de-scheduled. May return bogus results if the thread | 397 // actual work vs. being de-scheduled. May return bogus results if the thread |
| 387 // migrates to another CPU between two calls. Returns an empty ThreadTicks | 398 // migrates to another CPU between two calls. Returns an empty ThreadTicks |
| 388 // object until the initialization is completed. | 399 // object until the initialization is completed. If a clock reading is |
| 400 // absolutely needed, call WaitUntilInitialized() before this method. |
| 389 static ThreadTicks Now(); | 401 static ThreadTicks Now(); |
| 390 | 402 |
| 403 #if V8_OS_WIN |
| 404 // Similar to Now() above except this returns thread-specific CPU time for an |
| 405 // arbitrary thread. All comments for Now() method above apply apply to this |
| 406 // method as well. |
| 407 static ThreadTicks GetForThread(const HANDLE& thread_handle); |
| 408 #endif |
| 409 |
| 391 private: | 410 private: |
| 392 // This is for internal use and testing. Ticks are in microseconds. | 411 // Please use Now() or GetForThread() to create a new object. This is for |
| 412 // internal use and testing. Ticks are in microseconds. |
| 393 explicit ThreadTicks(int64_t ticks) : TimeBase(ticks) {} | 413 explicit ThreadTicks(int64_t ticks) : TimeBase(ticks) {} |
| 414 |
| 415 #if V8_OS_WIN |
| 416 // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't |
| 417 // been measured yet. Needs to be guarded with a call to IsSupported(). |
| 418 static double TSCTicksPerSecond(); |
| 419 static bool IsSupportedWin(); |
| 420 static void WaitUntilInitializedWin(); |
| 421 #endif |
| 394 }; | 422 }; |
| 395 | 423 |
| 396 } // namespace base | 424 } // namespace base |
| 397 } // namespace v8 | 425 } // namespace v8 |
| 398 | 426 |
| 399 #endif // V8_BASE_PLATFORM_TIME_H_ | 427 #endif // V8_BASE_PLATFORM_TIME_H_ |
| OLD | NEW |