diff options
author | James Hawkins <jhawkins@google.com> | 2017-02-13 15:47:21 -0800 |
---|---|---|
committer | James Hawkins <jhawkins@google.com> | 2017-02-13 15:47:21 -0800 |
commit | 7c92e484503f239000ef97ef5b067907fbeaa4a6 (patch) | |
tree | 1bdbaa087da8202bd1eb6a97bdfcf0aa67f2e1ec /init/util.cpp | |
parent | a3e4977325763b4a6fd290ee01b9ce133df8ab93 (diff) | |
download | system_core-7c92e484503f239000ef97ef5b067907fbeaa4a6.tar.gz system_core-7c92e484503f239000ef97ef5b067907fbeaa4a6.tar.bz2 system_core-7c92e484503f239000ef97ef5b067907fbeaa4a6.zip |
bootstat: Refactor init/utils/boot_clock into base/chrono_utils.
Use this for bootstat and init. This replaces the custom uptime parser in
bootstat.
This is a reland of aosp/332854 with a fix for Darwin.
Bug: 34352037
Test: chrono_utils_test
Change-Id: Ib2567d8df0e460ab59753ac1c053dd7f9f1008a7
Diffstat (limited to 'init/util.cpp')
-rw-r--r-- | init/util.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/init/util.cpp b/init/util.cpp index 888a36652..f59ba82e1 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -51,6 +51,8 @@ #include "property_service.h" #include "util.h" +using android::base::boot_clock; + static unsigned int do_decode_uid(const char *s) { unsigned int v; @@ -199,11 +201,16 @@ bool write_file(const char* path, const char* content) { return success; } -boot_clock::time_point boot_clock::now() { - timespec ts; - clock_gettime(CLOCK_BOOTTIME, &ts); - return boot_clock::time_point(std::chrono::seconds(ts.tv_sec) + - std::chrono::nanoseconds(ts.tv_nsec)); +Timer::Timer() : start_(boot_clock::now()) { +} + +double Timer::duration_s() const { + typedef std::chrono::duration<double> double_duration; + return std::chrono::duration_cast<double_duration>(boot_clock::now() - start_).count(); +} + +int64_t Timer::duration_ms() const { + return std::chrono::duration_cast<std::chrono::milliseconds>(boot_clock::now() - start_).count(); } int mkdir_recursive(const char *pathname, mode_t mode) |