From 26f40c04c3ad80e2bc449990010d39d1c1b9a5f0 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Mon, 6 Feb 2017 10:46:54 -0800 Subject: bootstat: Remove custom uptime parser in favor of elapsedRealtime. Refactored init/utils/boot_clock into base/chrono_utils. Bug: 34352037 Test: none Change-Id: Ied0c00867336b85922369d7ff37520e3d28fc61e --- init/util.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'init/util.cpp') 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_duration; + return std::chrono::duration_cast(boot_clock::now() - start_).count(); +} + +int64_t Timer::duration_ms() const { + return std::chrono::duration_cast(boot_clock::now() - start_).count(); } int mkdir_recursive(const char *pathname, mode_t mode) -- cgit v1.2.3