| 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 // Time represents an absolute point in coordinated universal time (UTC), | 5 // Time represents an absolute point in coordinated universal time (UTC), |
| 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch | 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch |
| 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are | 7 // (1601-01-01 00:00:00 UTC). System-dependent clock interface routines are |
| 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump | 8 // defined in time_PLATFORM.cc. Note that values for Time may skew and jump |
| 9 // around as the operating system makes adjustments to synchronize (e.g., with | 9 // around as the operating system makes adjustments to synchronize (e.g., with |
| 10 // NTP servers). Thus, client code that uses the Time class must account for | 10 // NTP servers). Thus, client code that uses the Time class must account for |
| 11 // this. | 11 // this. |
| 12 // | 12 // |
| 13 // TimeDelta represents a duration of time, internally represented in | 13 // TimeDelta represents a duration of time, internally represented in |
| 14 // microseconds. | 14 // microseconds. |
| 15 // | 15 // |
| 16 // TimeTicks, ThreadTicks, and TraceTicks represent an abstract time that is | 16 // TimeTicks and ThreadTicks represent an abstract time that is most of the time |
| 17 // most of the time incrementing, for use in measuring time durations. | 17 // incrementing, for use in measuring time durations. Internally, they are |
| 18 // Internally, they are represented in microseconds. They can not be converted | 18 // represented in microseconds. They can not be converted to a human-readable |
| 19 // to a human-readable time, but are guaranteed not to decrease (unlike the Time | 19 // time, but are guaranteed not to decrease (unlike the Time class). Note that |
| 20 // class). Note that TimeTicks may "stand still" (e.g., if the computer is | 20 // TimeTicks may "stand still" (e.g., if the computer is suspended), and |
| 21 // suspended), and ThreadTicks will "stand still" whenever the thread has been | 21 // ThreadTicks will "stand still" whenever the thread has been de-scheduled by |
| 22 // de-scheduled by the operating system. | 22 // the operating system. |
| 23 // | 23 // |
| 24 // All time classes are copyable, assignable, and occupy 64-bits per | 24 // All time classes are copyable, assignable, and occupy 64-bits per |
| 25 // instance. Thus, they can be efficiently passed by-value (as opposed to | 25 // instance. Thus, they can be efficiently passed by-value (as opposed to |
| 26 // by-reference). | 26 // by-reference). |
| 27 // | 27 // |
| 28 // Definitions of operator<< are provided to make these types work with | 28 // Definitions of operator<< are provided to make these types work with |
| 29 // DCHECK_EQ() and other log macros. For human-readable formatting, see | 29 // DCHECK_EQ() and other log macros. For human-readable formatting, see |
| 30 // "base/i18n/time_formatting.h". | 30 // "base/i18n/time_formatting.h". |
| 31 // | 31 // |
| 32 // So many choices! Which time class should you use? Examples: | 32 // So many choices! Which time class should you use? Examples: |
| 33 // | 33 // |
| 34 // Time: Interpreting the wall-clock time provided by a remote | 34 // Time: Interpreting the wall-clock time provided by a remote |
| 35 // system. Detecting whether cached resources have | 35 // system. Detecting whether cached resources have |
| 36 // expired. Providing the user with a display of the current date | 36 // expired. Providing the user with a display of the current date |
| 37 // and time. Determining the amount of time between events across | 37 // and time. Determining the amount of time between events across |
| 38 // re-boots of the machine. | 38 // re-boots of the machine. |
| 39 // | 39 // |
| 40 // TimeTicks: Tracking the amount of time a task runs. Executing delayed | 40 // TimeTicks: Tracking the amount of time a task runs. Executing delayed |
| 41 // tasks at the right time. Computing presentation timestamps. | 41 // tasks at the right time. Computing presentation timestamps. |
| 42 // Synchronizing audio and video using TimeTicks as a common | 42 // Synchronizing audio and video using TimeTicks as a common |
| 43 // reference clock (lip-sync). Measuring network round-trip | 43 // reference clock (lip-sync). Measuring network round-trip |
| 44 // latency. | 44 // latency. |
| 45 // | 45 // |
| 46 // ThreadTicks: Benchmarking how long the current thread has been doing actual | 46 // ThreadTicks: Benchmarking how long the current thread has been doing actual |
| 47 // work. | 47 // work. |
| 48 // | |
| 49 // TraceTicks: This is only meant to be used by the event tracing | |
| 50 // infrastructure, and by outside code modules in special | |
| 51 // circumstances. Please be sure to consult a | |
| 52 // base/trace_event/OWNER before committing any new code that | |
| 53 // uses this. | |
| 54 | 48 |
| 55 #ifndef BASE_TIME_TIME_H_ | 49 #ifndef BASE_TIME_TIME_H_ |
| 56 #define BASE_TIME_TIME_H_ | 50 #define BASE_TIME_TIME_H_ |
| 57 | 51 |
| 58 #include <time.h> | 52 #include <time.h> |
| 59 | 53 |
| 60 #include <iosfwd> | 54 #include <iosfwd> |
| 61 | 55 |
| 62 #include "base/base_export.h" | 56 #include "base/base_export.h" |
| 63 #include "base/basictypes.h" | 57 #include "base/basictypes.h" |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 static double TSCTicksPerSecond(); | 771 static double TSCTicksPerSecond(); |
| 778 | 772 |
| 779 static bool IsSupportedWin(); | 773 static bool IsSupportedWin(); |
| 780 static void WaitUntilInitializedWin(); | 774 static void WaitUntilInitializedWin(); |
| 781 #endif | 775 #endif |
| 782 }; | 776 }; |
| 783 | 777 |
| 784 // For logging use only. | 778 // For logging use only. |
| 785 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); | 779 BASE_EXPORT std::ostream& operator<<(std::ostream& os, ThreadTicks time_ticks); |
| 786 | 780 |
| 787 // TraceTicks ---------------------------------------------------------------- | |
| 788 | |
| 789 // Represents high-resolution system trace clock time. | |
| 790 class BASE_EXPORT TraceTicks : public time_internal::TimeBase<TraceTicks> { | |
| 791 public: | |
| 792 // We define this even without OS_CHROMEOS for seccomp sandbox testing. | |
| 793 #if defined(OS_LINUX) | |
| 794 // Force definition of the system trace clock; it is a chromeos-only api | |
| 795 // at the moment and surfacing it in the right place requires mucking | |
| 796 // with glibc et al. | |
| 797 static const clockid_t kClockSystemTrace = 11; | |
| 798 #endif | |
| 799 | |
| 800 TraceTicks() : TimeBase(0) { | |
| 801 } | |
| 802 | |
| 803 // Returns the current system trace time or, if not available on this | |
| 804 // platform, a high-resolution time value; or a low-resolution time value if | |
| 805 // neither are avalable. On systems where a global trace clock is defined, | |
| 806 // timestamping TraceEvents's with this value guarantees synchronization | |
| 807 // between events collected inside chrome and events collected outside | |
| 808 // (e.g. kernel, X server). | |
| 809 // | |
| 810 // On some platforms, the clock source used for tracing can vary depending on | |
| 811 // hardware and/or kernel support. Do not make any assumptions without | |
| 812 // consulting the documentation for this functionality in the time_win.cc, | |
| 813 // time_posix.cc, etc. files. | |
| 814 // | |
| 815 // NOTE: This is only meant to be used by the event tracing infrastructure, | |
| 816 // and by outside code modules in special circumstances. Please be sure to | |
| 817 // consult a base/trace_event/OWNER before committing any new code that uses | |
| 818 // this. | |
| 819 static TraceTicks Now(); | |
| 820 | |
| 821 private: | |
| 822 friend class time_internal::TimeBase<TraceTicks>; | |
| 823 | |
| 824 // Please use Now() to create a new object. This is for internal use | |
| 825 // and testing. | |
| 826 explicit TraceTicks(int64 us) : TimeBase(us) { | |
| 827 } | |
| 828 }; | |
| 829 | |
| 830 // For logging use only. | |
| 831 BASE_EXPORT std::ostream& operator<<(std::ostream& os, TraceTicks time_ticks); | |
| 832 | |
| 833 } // namespace base | 781 } // namespace base |
| 834 | 782 |
| 835 #endif // BASE_TIME_TIME_H_ | 783 #endif // BASE_TIME_TIME_H_ |
| OLD | NEW |