diff options
author | Tom Cherry | 2017-07-06 16:20:11 -0500 |
---|---|---|
committer | Tom Cherry | 2017-07-10 11:28:24 -0500 |
commit | ede0d538501dfc78c741fb3b0645406636d1d1fd (patch) | |
tree | 8b00e4bc64471d59a20d762345683721b0214e62 /base/include/android-base/chrono_utils.h | |
parent | c31963b5c255d57e162f4666f80b438ac74413ac (diff) | |
download | platform-system-core-ede0d538501dfc78c741fb3b0645406636d1d1fd.tar.gz platform-system-core-ede0d538501dfc78c741fb3b0645406636d1d1fd.tar.xz platform-system-core-ede0d538501dfc78c741fb3b0645406636d1d1fd.zip |
Move Timer from init to libbase
Test: boot bullhead
Test: new libbase unit tests
Change-Id: Ic398a1daa1fe92c10ea7bc1e6ac3f781cee9a5b5
Diffstat (limited to 'base/include/android-base/chrono_utils.h')
-rw-r--r-- | base/include/android-base/chrono_utils.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/base/include/android-base/chrono_utils.h b/base/include/android-base/chrono_utils.h index 0086425e5..7679d4c94 100644 --- a/base/include/android-base/chrono_utils.h +++ b/base/include/android-base/chrono_utils.h | |||
@@ -18,6 +18,9 @@ | |||
18 | #define ANDROID_BASE_CHRONO_UTILS_H | 18 | #define ANDROID_BASE_CHRONO_UTILS_H |
19 | 19 | ||
20 | #include <chrono> | 20 | #include <chrono> |
21 | #include <sstream> | ||
22 | |||
23 | using namespace std::chrono_literals; | ||
21 | 24 | ||
22 | namespace android { | 25 | namespace android { |
23 | namespace base { | 26 | namespace base { |
@@ -31,6 +34,20 @@ class boot_clock { | |||
31 | static time_point now(); | 34 | static time_point now(); |
32 | }; | 35 | }; |
33 | 36 | ||
37 | class Timer { | ||
38 | public: | ||
39 | Timer() : start_(boot_clock::now()) {} | ||
40 | |||
41 | std::chrono::milliseconds duration() const { | ||
42 | return std::chrono::duration_cast<std::chrono::milliseconds>(boot_clock::now() - start_); | ||
43 | } | ||
44 | |||
45 | private: | ||
46 | boot_clock::time_point start_; | ||
47 | }; | ||
48 | |||
49 | std::ostream& operator<<(std::ostream& os, const Timer& t); | ||
50 | |||
34 | } // namespace base | 51 | } // namespace base |
35 | } // namespace android | 52 | } // namespace android |
36 | 53 | ||