From 2980f57f2c3da88139342b394f685c2c505c96c5 Mon Sep 17 00:00:00 2001 From: Luis Hector Chavez Date: Wed, 11 Apr 2018 15:35:44 -0700 Subject: [PATCH] init: Use android::base::boot_clock instead of /proc/uptime /proc/uptime internally uses whatever would be returned by clock_gettime(CLOCK_BOOTTIME), so use android::base::boot_clock instead which avoids parsing strings and rounding errors. Bug: 77273909 Test: CtsBootStatsTestCases Change-Id: Ic162eefcf226073949a18cca55db3c2324b98749 --- init/bootchart.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/init/bootchart.cpp b/init/bootchart.cpp index 379b4fa84..c2cf57399 100644 --- a/init/bootchart.cpp +++ b/init/bootchart.cpp @@ -32,12 +32,14 @@ #include #include +#include #include #include #include #include using android::base::StringPrintf; +using android::base::boot_clock; using namespace std::chrono_literals; namespace android { @@ -50,9 +52,9 @@ static std::condition_variable g_bootcharting_finished_cv; static bool g_bootcharting_finished; static long long get_uptime_jiffies() { - std::string uptime; - if (!android::base::ReadFileToString("/proc/uptime", &uptime)) return 0; - return 100LL * strtod(uptime.c_str(), NULL); + constexpr int64_t kNanosecondsPerJiffy = 10000000; + boot_clock::time_point uptime = boot_clock::now(); + return uptime.time_since_epoch().count() / kNanosecondsPerJiffy; } static std::unique_ptr fopen_unique(const char* filename,