diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index 483c01d0a..a626704cc 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp @@ -212,10 +212,8 @@ void RecordInitBootTimeProp( BootEventRecordStore* boot_event_store, const char* property) { std::string value = GetProperty(property); - int32_t time_in_ns; - if (android::base::ParseInt(value, &time_in_ns)) { - static constexpr int32_t kNanosecondsPerMillisecond = 1e6; - int32_t time_in_ms = static_cast(time_in_ns / kNanosecondsPerMillisecond); + int32_t time_in_ms; + if (android::base::ParseInt(value, &time_in_ms)) { boot_event_store->AddBootEventWithValue(property, time_in_ms); } } diff --git a/init/init.cpp b/init/init.cpp index 1ce3c35fc..e7772e773 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -178,7 +178,7 @@ static int wait_for_coldboot_done_action(const std::vector& args) { panic(); } - property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration_ns()).c_str()); + property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration_ms()).c_str()); return 0; } @@ -576,7 +576,7 @@ static void selinux_initialize(bool in_kernel_domain) { } // init's first stage can't set properties, so pass the time to the second stage. - setenv("INIT_SELINUX_TOOK", std::to_string(t.duration_ns()).c_str(), 1); + setenv("INIT_SELINUX_TOOK", std::to_string(t.duration_ms()).c_str(), 1); } else { selinux_init_all_handles(); } @@ -757,8 +757,9 @@ int main(int argc, char** argv) { setenv("INIT_SECOND_STAGE", "true", 1); - uint64_t start_ns = start_time.time_since_epoch().count(); - setenv("INIT_STARTED_AT", StringPrintf("%" PRIu64, start_ns).c_str(), 1); + static constexpr uint32_t kNanosecondsPerMillisecond = 1e6; + uint64_t start_ms = start_time.time_since_epoch().count() / kNanosecondsPerMillisecond; + setenv("INIT_STARTED_AT", StringPrintf("%" PRIu64, start_ms).c_str(), 1); char* path = argv[0]; char* args[] = { path, nullptr }; diff --git a/init/property_service.cpp b/init/property_service.cpp index d323425fb..7e11ff076 100644 --- a/init/property_service.cpp +++ b/init/property_service.cpp @@ -276,7 +276,7 @@ class SocketConnection { while (*timeout_ms > 0) { Timer timer; int nr = poll(ufds, 1, *timeout_ms); - uint64_t millis = timer.duration_ns()/1000000; + uint64_t millis = timer.duration_ms(); *timeout_ms = (millis > *timeout_ms) ? 0 : *timeout_ms - millis; if (nr > 0) { diff --git a/init/util.h b/init/util.h index 009413d7d..5c38dc3c9 100644 --- a/init/util.h +++ b/init/util.h @@ -55,8 +55,8 @@ class Timer { return std::chrono::duration_cast(boot_clock::now() - start_).count(); } - int64_t duration_ns() const { - return (boot_clock::now() - start_).count(); + int64_t duration_ms() const { + return std::chrono::duration_cast(boot_clock::now() - start_).count(); } private: