Merge "Revert "bootstat: Remove custom uptime parser in favor of elapsedRealtime.""
am: 23f4e6b0a5
Change-Id: Ibef66ccd1a1fe362692ee45cb86cd9c0212c1f85
This commit is contained in:
commit
cefdacef3c
14 changed files with 73 additions and 154 deletions
|
|
@ -42,31 +42,21 @@ cc_library {
|
||||||
srcs: [
|
srcs: [
|
||||||
"errors_unix.cpp",
|
"errors_unix.cpp",
|
||||||
"properties.cpp",
|
"properties.cpp",
|
||||||
"chrono_utils.cpp",
|
|
||||||
],
|
],
|
||||||
cppflags: ["-Wexit-time-destructors"],
|
cppflags: ["-Wexit-time-destructors"],
|
||||||
},
|
},
|
||||||
darwin: {
|
darwin: {
|
||||||
srcs: [
|
srcs: ["errors_unix.cpp"],
|
||||||
"errors_unix.cpp",
|
|
||||||
],
|
|
||||||
cppflags: ["-Wexit-time-destructors"],
|
cppflags: ["-Wexit-time-destructors"],
|
||||||
},
|
},
|
||||||
linux_bionic: {
|
linux_bionic: {
|
||||||
srcs: [
|
srcs: ["errors_unix.cpp"],
|
||||||
"chrono_utils.cpp",
|
|
||||||
"errors_unix.cpp",
|
|
||||||
],
|
|
||||||
cppflags: ["-Wexit-time-destructors"],
|
cppflags: ["-Wexit-time-destructors"],
|
||||||
enabled: true,
|
enabled: true,
|
||||||
},
|
},
|
||||||
linux: {
|
linux: {
|
||||||
srcs: [
|
srcs: ["errors_unix.cpp"],
|
||||||
"chrono_utils.cpp",
|
|
||||||
"errors_unix.cpp",
|
|
||||||
],
|
|
||||||
cppflags: ["-Wexit-time-destructors"],
|
cppflags: ["-Wexit-time-destructors"],
|
||||||
host_ldlibs: ["-lrt"],
|
|
||||||
},
|
},
|
||||||
windows: {
|
windows: {
|
||||||
srcs: [
|
srcs: [
|
||||||
|
|
@ -98,14 +88,7 @@ cc_test {
|
||||||
],
|
],
|
||||||
target: {
|
target: {
|
||||||
android: {
|
android: {
|
||||||
srcs: [
|
srcs: ["properties_test.cpp"],
|
||||||
"chrono_utils_test.cpp",
|
|
||||||
"properties_test.cpp"
|
|
||||||
],
|
|
||||||
},
|
|
||||||
linux: {
|
|
||||||
srcs: ["chrono_utils_test.cpp"],
|
|
||||||
host_ldlibs: ["-lrt"],
|
|
||||||
},
|
},
|
||||||
windows: {
|
windows: {
|
||||||
srcs: ["utf8_test.cpp"],
|
srcs: ["utf8_test.cpp"],
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "android-base/chrono_utils.h"
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
namespace android {
|
|
||||||
namespace base {
|
|
||||||
|
|
||||||
std::chrono::seconds GetBootTimeSeconds() {
|
|
||||||
struct timespec now;
|
|
||||||
clock_gettime(CLOCK_BOOTTIME, &now);
|
|
||||||
|
|
||||||
auto now_tp = boot_clock::time_point(
|
|
||||||
std::chrono::seconds(now.tv_sec) + std::chrono::nanoseconds(now.tv_nsec));
|
|
||||||
return std::chrono::duration_cast<std::chrono::seconds>(
|
|
||||||
now_tp.time_since_epoch());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests (at least) the seconds accuracy of the boot_clock::now() method.
|
|
||||||
TEST(ChronoUtilsTest, BootClockNowSeconds) {
|
|
||||||
auto now = GetBootTimeSeconds();
|
|
||||||
auto boot_seconds = std::chrono::duration_cast<std::chrono::seconds>(
|
|
||||||
boot_clock::now().time_since_epoch());
|
|
||||||
EXPECT_EQ(now, boot_seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace base
|
|
||||||
} // namespace android
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
bootstat_lib_src_files = [
|
bootstat_lib_src_files = [
|
||||||
"boot_event_record_store.cpp",
|
"boot_event_record_store.cpp",
|
||||||
"histogram_logger.cpp",
|
"histogram_logger.cpp",
|
||||||
|
"uptime_parser.cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
cc_defaults {
|
cc_defaults {
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,14 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <android-base/chrono_utils.h>
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/parseint.h>
|
#include <android-base/parseint.h>
|
||||||
|
|
||||||
#include "histogram_logger.h"
|
#include "histogram_logger.h"
|
||||||
|
#include "uptime_parser.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
@ -60,9 +56,7 @@ BootEventRecordStore::BootEventRecordStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BootEventRecordStore::AddBootEvent(const std::string& event) {
|
void BootEventRecordStore::AddBootEvent(const std::string& event) {
|
||||||
auto uptime = std::chrono::duration_cast<std::chrono::seconds>(
|
AddBootEventWithValue(event, bootstat::ParseUptime());
|
||||||
android::base::boot_clock::now().time_since_epoch());
|
|
||||||
AddBootEventWithValue(event, uptime.count());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The implementation of AddBootEventValue makes use of the mtime file
|
// The implementation of AddBootEventValue makes use of the mtime file
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,15 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <android-base/chrono_utils.h>
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/test_utils.h>
|
#include <android-base/test_utils.h>
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
#include "uptime_parser.h"
|
||||||
|
|
||||||
using testing::UnorderedElementsAreArray;
|
using testing::UnorderedElementsAreArray;
|
||||||
|
|
||||||
|
|
@ -92,12 +89,6 @@ void DeleteDirectory(const std::string& path) {
|
||||||
rmdir(path.c_str());
|
rmdir(path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the time in seconds since boot.
|
|
||||||
time_t GetUptimeSeconds() {
|
|
||||||
return std::chrono::duration_cast<std::chrono::seconds>(
|
|
||||||
android::base::boot_clock::now().time_since_epoch()).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
class BootEventRecordStoreTest : public ::testing::Test {
|
class BootEventRecordStoreTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
BootEventRecordStoreTest() {
|
BootEventRecordStoreTest() {
|
||||||
|
|
@ -135,7 +126,7 @@ TEST_F(BootEventRecordStoreTest, AddSingleBootEvent) {
|
||||||
BootEventRecordStore store;
|
BootEventRecordStore store;
|
||||||
store.SetStorePath(GetStorePathForTesting());
|
store.SetStorePath(GetStorePathForTesting());
|
||||||
|
|
||||||
time_t uptime = GetUptimeSeconds();
|
time_t uptime = bootstat::ParseUptime();
|
||||||
ASSERT_NE(-1, uptime);
|
ASSERT_NE(-1, uptime);
|
||||||
|
|
||||||
store.AddBootEvent("cenozoic");
|
store.AddBootEvent("cenozoic");
|
||||||
|
|
@ -150,7 +141,7 @@ TEST_F(BootEventRecordStoreTest, AddMultipleBootEvents) {
|
||||||
BootEventRecordStore store;
|
BootEventRecordStore store;
|
||||||
store.SetStorePath(GetStorePathForTesting());
|
store.SetStorePath(GetStorePathForTesting());
|
||||||
|
|
||||||
time_t uptime = GetUptimeSeconds();
|
time_t uptime = bootstat::ParseUptime();
|
||||||
ASSERT_NE(-1, uptime);
|
ASSERT_NE(-1, uptime);
|
||||||
|
|
||||||
store.AddBootEvent("cretaceous");
|
store.AddBootEvent("cretaceous");
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
@ -32,7 +31,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
#include <android-base/chrono_utils.h>
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/parseint.h>
|
#include <android-base/parseint.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
|
|
@ -40,6 +38,7 @@
|
||||||
|
|
||||||
#include "boot_event_record_store.h"
|
#include "boot_event_record_store.h"
|
||||||
#include "histogram_logger.h"
|
#include "histogram_logger.h"
|
||||||
|
#include "uptime_parser.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
@ -248,8 +247,7 @@ void RecordBootComplete() {
|
||||||
BootEventRecordStore boot_event_store;
|
BootEventRecordStore boot_event_store;
|
||||||
BootEventRecordStore::BootEventRecord record;
|
BootEventRecordStore::BootEventRecord record;
|
||||||
|
|
||||||
auto uptime = std::chrono::duration_cast<std::chrono::seconds>(
|
time_t uptime = bootstat::ParseUptime();
|
||||||
android::base::boot_clock::now().time_since_epoch());
|
|
||||||
time_t current_time_utc = time(nullptr);
|
time_t current_time_utc = time(nullptr);
|
||||||
|
|
||||||
if (boot_event_store.GetBootEvent("last_boot_time_utc", &record)) {
|
if (boot_event_store.GetBootEvent("last_boot_time_utc", &record)) {
|
||||||
|
|
@ -276,22 +274,22 @@ void RecordBootComplete() {
|
||||||
// Log the amount of time elapsed until the device is decrypted, which
|
// Log the amount of time elapsed until the device is decrypted, which
|
||||||
// includes the variable amount of time the user takes to enter the
|
// includes the variable amount of time the user takes to enter the
|
||||||
// decryption password.
|
// decryption password.
|
||||||
boot_event_store.AddBootEventWithValue("boot_decryption_complete", uptime.count());
|
boot_event_store.AddBootEventWithValue("boot_decryption_complete", uptime);
|
||||||
|
|
||||||
// Subtract the decryption time to normalize the boot cycle timing.
|
// Subtract the decryption time to normalize the boot cycle timing.
|
||||||
std::chrono::seconds boot_complete = std::chrono::seconds(uptime.count() - record.second);
|
time_t boot_complete = uptime - record.second;
|
||||||
boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_post_decrypt",
|
boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_post_decrypt",
|
||||||
boot_complete.count());
|
boot_complete);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_no_encryption",
|
boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_no_encryption",
|
||||||
uptime.count());
|
uptime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the total time from device startup to boot complete, regardless of
|
// Record the total time from device startup to boot complete, regardless of
|
||||||
// encryption state.
|
// encryption state.
|
||||||
boot_event_store.AddBootEventWithValue(boot_complete_prefix, uptime.count());
|
boot_event_store.AddBootEventWithValue(boot_complete_prefix, uptime);
|
||||||
|
|
||||||
RecordInitBootTimeProp(&boot_event_store, "ro.boottime.init");
|
RecordInitBootTimeProp(&boot_event_store, "ro.boottime.init");
|
||||||
RecordInitBootTimeProp(&boot_event_store, "ro.boottime.init.selinux");
|
RecordInitBootTimeProp(&boot_event_store, "ro.boottime.init.selinux");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
* Copyright (C) 2016 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -14,24 +14,25 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ANDROID_BASE_CHRONO_UTILS_H
|
#include "uptime_parser.h"
|
||||||
#define ANDROID_BASE_CHRONO_UTILS_H
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <time.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <string>
|
||||||
|
#include <android-base/file.h>
|
||||||
|
#include <android-base/logging.h>
|
||||||
|
|
||||||
namespace android {
|
namespace bootstat {
|
||||||
namespace base {
|
|
||||||
|
|
||||||
// A std::chrono clock based on CLOCK_BOOTTIME.
|
time_t ParseUptime() {
|
||||||
class boot_clock {
|
std::string uptime_str;
|
||||||
public:
|
if (!android::base::ReadFileToString("/proc/uptime", &uptime_str)) {
|
||||||
typedef std::chrono::nanoseconds duration;
|
PLOG(ERROR) << "Failed to read /proc/uptime";
|
||||||
typedef std::chrono::time_point<boot_clock, duration> time_point;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static time_point now();
|
// Cast intentionally rounds down.
|
||||||
};
|
return static_cast<time_t>(strtod(uptime_str.c_str(), NULL));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace base
|
} // namespace bootstat
|
||||||
} // namespace android
|
|
||||||
|
|
||||||
#endif // ANDROID_BASE_CHRONO_UTILS_H
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
* Copyright (C) 2016 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -14,19 +14,16 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "android-base/chrono_utils.h"
|
#ifndef UPTIME_PARSER_H_
|
||||||
|
#define UPTIME_PARSER_H_
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
namespace android {
|
namespace bootstat {
|
||||||
namespace base {
|
|
||||||
|
|
||||||
boot_clock::time_point boot_clock::now() {
|
// Returns the number of seconds the system has been on since reboot.
|
||||||
timespec ts;
|
time_t ParseUptime();
|
||||||
clock_gettime(CLOCK_BOOTTIME, &ts);
|
|
||||||
return boot_clock::time_point(std::chrono::seconds(ts.tv_sec) +
|
|
||||||
std::chrono::nanoseconds(ts.tv_nsec));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace base
|
} // namespace bootstat
|
||||||
} // namespace android
|
|
||||||
|
#endif // UPTIME_PARSER_H_
|
||||||
|
|
@ -36,7 +36,7 @@ LOCAL_MODULE := init_parser_tests
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
parser/tokenizer_test.cpp \
|
parser/tokenizer_test.cpp \
|
||||||
|
|
||||||
LOCAL_STATIC_LIBRARIES := libbase libinit_parser
|
LOCAL_STATIC_LIBRARIES := libinit_parser
|
||||||
LOCAL_CLANG := true
|
LOCAL_CLANG := true
|
||||||
include $(BUILD_HOST_NATIVE_TEST)
|
include $(BUILD_HOST_NATIVE_TEST)
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@
|
||||||
#include <selinux/label.h>
|
#include <selinux/label.h>
|
||||||
#include <selinux/android.h>
|
#include <selinux/android.h>
|
||||||
|
|
||||||
#include <android-base/chrono_utils.h>
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
|
|
@ -69,7 +68,6 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "watchdogd.h"
|
#include "watchdogd.h"
|
||||||
|
|
||||||
using android::base::boot_clock;
|
|
||||||
using android::base::StringPrintf;
|
using android::base::StringPrintf;
|
||||||
|
|
||||||
struct selabel_handle *sehandle;
|
struct selabel_handle *sehandle;
|
||||||
|
|
@ -752,7 +750,7 @@ int main(int argc, char** argv) {
|
||||||
return watchdogd_main(argc, argv);
|
return watchdogd_main(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_clock::time_point start_time = android::base::boot_clock::now();
|
boot_clock::time_point start_time = boot_clock::now();
|
||||||
|
|
||||||
// Clear the umask.
|
// Clear the umask.
|
||||||
umask(0);
|
umask(0);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
#include <selinux/selinux.h>
|
#include <selinux/selinux.h>
|
||||||
|
|
||||||
#include <android-base/chrono_utils.h>
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/parseint.h>
|
#include <android-base/parseint.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
|
|
@ -48,7 +47,6 @@
|
||||||
#include "property_service.h"
|
#include "property_service.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using android::base::boot_clock;
|
|
||||||
using android::base::ParseInt;
|
using android::base::ParseInt;
|
||||||
using android::base::StringPrintf;
|
using android::base::StringPrintf;
|
||||||
using android::base::WriteStringToFile;
|
using android::base::WriteStringToFile;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <android-base/chrono_utils.h>
|
|
||||||
|
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#include "descriptors.h"
|
#include "descriptors.h"
|
||||||
|
|
@ -137,8 +135,8 @@ private:
|
||||||
|
|
||||||
unsigned flags_;
|
unsigned flags_;
|
||||||
pid_t pid_;
|
pid_t pid_;
|
||||||
android::base::boot_clock::time_point time_started_; // time of last start
|
boot_clock::time_point time_started_; // time of last start
|
||||||
android::base::boot_clock::time_point time_crashed_; // first crash within inspection window
|
boot_clock::time_point time_crashed_; // first crash within inspection window
|
||||||
int crash_count_; // number of times crashed within window
|
int crash_count_; // number of times crashed within window
|
||||||
|
|
||||||
uid_t uid_;
|
uid_t uid_;
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,6 @@
|
||||||
#include "property_service.h"
|
#include "property_service.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
using android::base::boot_clock;
|
|
||||||
|
|
||||||
static unsigned int do_decode_uid(const char *s)
|
static unsigned int do_decode_uid(const char *s)
|
||||||
{
|
{
|
||||||
unsigned int v;
|
unsigned int v;
|
||||||
|
|
@ -201,16 +199,11 @@ bool write_file(const char* path, const char* content) {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer::Timer() : start_(boot_clock::now()) {
|
boot_clock::time_point boot_clock::now() {
|
||||||
}
|
timespec ts;
|
||||||
|
clock_gettime(CLOCK_BOOTTIME, &ts);
|
||||||
double Timer::duration_s() const {
|
return boot_clock::time_point(std::chrono::seconds(ts.tv_sec) +
|
||||||
typedef std::chrono::duration<double> double_duration;
|
std::chrono::nanoseconds(ts.tv_nsec));
|
||||||
return std::chrono::duration_cast<double_duration>(boot_clock::now() - start_).count();
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t Timer::duration_ms() const {
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(boot_clock::now() - start_).count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mkdir_recursive(const char *pathname, mode_t mode)
|
int mkdir_recursive(const char *pathname, mode_t mode)
|
||||||
|
|
|
||||||
26
init/util.h
26
init/util.h
|
|
@ -25,8 +25,6 @@
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <android-base/chrono_utils.h>
|
|
||||||
|
|
||||||
#define COLDBOOT_DONE "/dev/.coldboot_done"
|
#define COLDBOOT_DONE "/dev/.coldboot_done"
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
@ -37,16 +35,32 @@ int create_socket(const char *name, int type, mode_t perm,
|
||||||
bool read_file(const char* path, std::string* content);
|
bool read_file(const char* path, std::string* content);
|
||||||
bool write_file(const char* path, const char* content);
|
bool write_file(const char* path, const char* content);
|
||||||
|
|
||||||
|
// A std::chrono clock based on CLOCK_BOOTTIME.
|
||||||
|
class boot_clock {
|
||||||
|
public:
|
||||||
|
typedef std::chrono::nanoseconds duration;
|
||||||
|
typedef std::chrono::time_point<boot_clock, duration> time_point;
|
||||||
|
static constexpr bool is_steady = true;
|
||||||
|
|
||||||
|
static time_point now();
|
||||||
|
};
|
||||||
|
|
||||||
class Timer {
|
class Timer {
|
||||||
public:
|
public:
|
||||||
Timer();
|
Timer() : start_(boot_clock::now()) {
|
||||||
|
}
|
||||||
|
|
||||||
double duration_s() const;
|
double duration_s() const {
|
||||||
|
typedef std::chrono::duration<double> double_duration;
|
||||||
|
return std::chrono::duration_cast<double_duration>(boot_clock::now() - start_).count();
|
||||||
|
}
|
||||||
|
|
||||||
int64_t duration_ms() const;
|
int64_t duration_ms() const {
|
||||||
|
return std::chrono::duration_cast<std::chrono::milliseconds>(boot_clock::now() - start_).count();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
android::base::boot_clock::time_point start_;
|
boot_clock::time_point start_;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Timer& t);
|
std::ostream& operator<<(std::ostream& os, const Timer& t);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue