Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 | 5 |
| 6 // Windows Timer Primer | 6 // Windows Timer Primer |
| 7 // | 7 // |
| 8 // A good article: http://www.ddj.com/windows/184416651 | 8 // A good article: http://www.ddj.com/windows/184416651 |
| 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 | 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 |
| 10 // | 10 // |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 #include <windows.h> | 36 #include <windows.h> |
| 37 #include <mmsystem.h> | 37 #include <mmsystem.h> |
| 38 #include <stdint.h> | 38 #include <stdint.h> |
| 39 | 39 |
| 40 #include "base/bit_cast.h" | 40 #include "base/bit_cast.h" |
| 41 #include "base/cpu.h" | 41 #include "base/cpu.h" |
| 42 #include "base/lazy_instance.h" | 42 #include "base/lazy_instance.h" |
| 43 #include "base/logging.h" | 43 #include "base/logging.h" |
| 44 #include "base/synchronization/lock.h" | 44 #include "base/synchronization/lock.h" |
| 45 #include "base/threading/platform_thread.h" | |
| 45 | 46 |
| 46 using base::ThreadTicks; | 47 using base::ThreadTicks; |
| 47 using base::Time; | 48 using base::Time; |
| 48 using base::TimeDelta; | 49 using base::TimeDelta; |
| 49 using base::TimeTicks; | 50 using base::TimeTicks; |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 // From MSDN, FILETIME "Contains a 64-bit value representing the number of | 54 // From MSDN, FILETIME "Contains a 64-bit value representing the number of |
| 54 // 100-nanosecond intervals since January 1, 1601 (UTC)." | 55 // 100-nanosecond intervals since January 1, 1601 (UTC)." |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 } | 512 } |
| 512 | 513 |
| 513 // static | 514 // static |
| 514 TimeTicks::Clock TimeTicks::GetClock() { | 515 TimeTicks::Clock TimeTicks::GetClock() { |
| 515 return IsHighResolution() ? | 516 return IsHighResolution() ? |
| 516 Clock::WIN_QPC : Clock::WIN_ROLLOVER_PROTECTED_TIME_GET_TIME; | 517 Clock::WIN_QPC : Clock::WIN_ROLLOVER_PROTECTED_TIME_GET_TIME; |
| 517 } | 518 } |
| 518 | 519 |
| 519 // static | 520 // static |
| 520 ThreadTicks ThreadTicks::Now() { | 521 ThreadTicks ThreadTicks::Now() { |
| 522 return ThreadTicks::Now(PlatformThread::CurrentHandle()); | |
| 523 } | |
| 524 | |
| 525 // static | |
| 526 ThreadTicks ThreadTicks::Now(const base::PlatformThreadHandle& thread_handle) { | |
| 521 DCHECK(IsSupported()); | 527 DCHECK(IsSupported()); |
| 522 | 528 |
| 523 // Get the number of TSC ticks used by the current thread. | 529 // Get the number of TSC ticks used by the current thread. |
| 524 ULONG64 thread_cycle_time = 0; | 530 ULONG64 thread_cycle_time = 0; |
| 525 GetQueryThreadCycleTimeFunction()(::GetCurrentThread(), &thread_cycle_time); | 531 GetQueryThreadCycleTimeFunction()(thread_handle.platform_handle(), |
|
fdoray
2016/04/21 21:08:37
We can call ::QueryThreadCycleTime() directly and
stanisc
2016/04/22 01:11:45
OK, I've removed GetQueryThreadCycleTimeFunction()
| |
| 532 &thread_cycle_time); | |
| 526 | 533 |
| 527 // Get the frequency of the TSC. | 534 // Get the frequency of the TSC. |
| 528 double tsc_ticks_per_second = TSCTicksPerSecond(); | 535 double tsc_ticks_per_second = TSCTicksPerSecond(); |
| 529 if (tsc_ticks_per_second == 0) | 536 if (tsc_ticks_per_second == 0) |
| 530 return ThreadTicks(); | 537 return ThreadTicks(); |
| 531 | 538 |
| 532 // Return the CPU time of the current thread. | 539 // Return the CPU time of the current thread. |
| 533 double thread_time_seconds = thread_cycle_time / tsc_ticks_per_second; | 540 double thread_time_seconds = thread_cycle_time / tsc_ticks_per_second; |
| 534 return ThreadTicks( | 541 return ThreadTicks( |
| 535 static_cast<int64_t>(thread_time_seconds * Time::kMicrosecondsPerSecond)); | 542 static_cast<int64_t>(thread_time_seconds * Time::kMicrosecondsPerSecond)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { | 619 TimeTicks TimeTicks::FromQPCValue(LONGLONG qpc_value) { |
| 613 return TimeTicks() + QPCValueToTimeDelta(qpc_value); | 620 return TimeTicks() + QPCValueToTimeDelta(qpc_value); |
| 614 } | 621 } |
| 615 | 622 |
| 616 // TimeDelta ------------------------------------------------------------------ | 623 // TimeDelta ------------------------------------------------------------------ |
| 617 | 624 |
| 618 // static | 625 // static |
| 619 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { | 626 TimeDelta TimeDelta::FromQPCValue(LONGLONG qpc_value) { |
| 620 return QPCValueToTimeDelta(qpc_value); | 627 return QPCValueToTimeDelta(qpc_value); |
| 621 } | 628 } |
| OLD | NEW |