diff options
author | Elliott Hughes <enh@google.com> | 2016-11-10 17:43:47 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-11-12 11:17:40 -0800 |
commit | 9605a945f7a497c0307b512b9cd762f2d23973ca (patch) | |
tree | d78bab11c11aba3c79c6b66a944699fb591a39dd /init/util.cpp | |
parent | 8cbc89527cbeb677d24698aca6d5302764db1775 (diff) | |
download | system_core-9605a945f7a497c0307b512b9cd762f2d23973ca.tar.gz system_core-9605a945f7a497c0307b512b9cd762f2d23973ca.tar.bz2 system_core-9605a945f7a497c0307b512b9cd762f2d23973ca.zip |
init start time tracking.
With this change, init sets a property "init.start" to show the
CLOCK_BOOTTIME time at which init itself started, and for each service
an "init.svc.<name>.start" property to show the CLOCK_BOOTTIME time at
which that service was most recently started.
These times can be used by tools like bootstat to track boot time.
As part of this change, move init over to std::chrono. Also, rather than
make the command-line argument handling more complex, I've switched to
using an environment variable for communication between first- and
second-stage init, and added another environment variable to pass the
start time of the first stage through to the second stage.
Bug: http://b/32780225
Test: manual
Change-Id: Ia65a623e1866ea688b9a5433d6507926ce301dfe
Diffstat (limited to 'init/util.cpp')
-rw-r--r-- | init/util.cpp | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/init/util.cpp b/init/util.cpp index ff46e4f42..bde4efb62 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -258,16 +258,11 @@ int write_file(const char* path, const char* content) { return result; } -time_t gettime() { - timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - return now.tv_sec; -} - -uint64_t gettime_ns() { - timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec; +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)); } int mkdir_recursive(const char *pathname, mode_t mode) @@ -325,16 +320,15 @@ void sanitize(char *s) } } -int wait_for_file(const char *filename, int timeout) -{ - struct stat info; - uint64_t timeout_time_ns = gettime_ns() + timeout * UINT64_C(1000000000); - int ret = -1; +int wait_for_file(const char* filename, std::chrono::nanoseconds timeout) { + boot_clock::time_point timeout_time = boot_clock::now() + timeout; + while (boot_clock::now() < timeout_time) { + struct stat sb; + if (stat(filename, &sb) != -1) return 0; - while (gettime_ns() < timeout_time_ns && ((ret = stat(filename, &info)) < 0)) usleep(10000); - - return ret; + } + return -1; } void import_kernel_cmdline(bool in_qemu, |