Merge "boottime/init: Report ro.boottime.init* properties in milliseconds."
am: 7dde4fa4e2

Change-Id: I085194f0af3dc42ea90ca31865c42bc41036cdc6
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 483c01d..a626704 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -212,10 +212,8 @@
     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<int32_t>(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 1ce3c35..e7772e7 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -178,7 +178,7 @@
         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 @@
         }
 
         // 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 @@
 
         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 d323425..7e11ff0 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -276,7 +276,7 @@
     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 009413d..5c38dc3 100644
--- a/init/util.h
+++ b/init/util.h
@@ -55,8 +55,8 @@
     return std::chrono::duration_cast<double_duration>(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<std::chrono::milliseconds>(boot_clock::now() - start_).count();
   }
 
  private: