From 16e84cc1e1c8e1b02f646226e38cdc091c3f9a1a Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Thu, 14 Apr 2016 14:13:20 -0700 Subject: [PATCH] bootstat: Calculate and log the time_since_last_boot metric. Bug: 28163811 Change-Id: I2e1350531f6a0fc891c270cfdfca6c8ad63f8040 (cherry picked from commit 2d8b3e66c6fd298bc8f4dc4e8205bb469a89a6f8) --- bootstat/bootstat.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index 26e0ffc53..d547c1955 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp @@ -169,7 +169,19 @@ std::string CalculateBootCompletePrefix() { void RecordBootComplete() { BootEventRecordStore boot_event_store; BootEventRecordStore::BootEventRecord record; + time_t uptime = bootstat::ParseUptime(); + time_t current_time_utc = time(nullptr); + + if (boot_event_store.GetBootEvent("last_boot_time_utc", &record)) { + time_t last_boot_time_utc = record.second; + time_t time_since_last_boot = difftime(current_time_utc, + last_boot_time_utc); + boot_event_store.AddBootEventWithValue("time_since_last_boot", + time_since_last_boot); + } + + boot_event_store.AddBootEventWithValue("last_boot_time_utc", current_time_utc); // The boot_complete metric has two variants: boot_complete and // ota_boot_complete. The latter signifies that the device is booting after