summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Cherry2017-07-06 16:20:11 -0500
committerTom Cherry2017-07-10 11:28:24 -0500
commitede0d538501dfc78c741fb3b0645406636d1d1fd (patch)
tree8b00e4bc64471d59a20d762345683721b0214e62 /base/include/android-base/chrono_utils.h
parentc31963b5c255d57e162f4666f80b438ac74413ac (diff)
downloadplatform-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.h17
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
23using namespace std::chrono_literals;
21 24
22namespace android { 25namespace android {
23namespace base { 26namespace base {
@@ -31,6 +34,20 @@ class boot_clock {
31 static time_point now(); 34 static time_point now();
32}; 35};
33 36
37class 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
49std::ostream& operator<<(std::ostream& os, const Timer& t);
50
34} // namespace base 51} // namespace base
35} // namespace android 52} // namespace android
36 53