Loading base/Android.bp +4 −21 Original line number Original line Diff line number Diff line Loading @@ -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: [ Loading Loading @@ -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"], Loading base/chrono_utils_test.cppdeleted 100644 → 0 +0 −47 Original line number Original line Diff line number Diff line /* * 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 No newline at end of file bootstat/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -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 { Loading bootstat/boot_event_record_store.cpp +2 −8 Original line number Original line Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 Loading bootstat/boot_event_record_store_test.cpp +3 −12 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading @@ -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() { Loading Loading @@ -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"); Loading @@ -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"); Loading Loading
base/Android.bp +4 −21 Original line number Original line Diff line number Diff line Loading @@ -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: [ Loading Loading @@ -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"], Loading
base/chrono_utils_test.cppdeleted 100644 → 0 +0 −47 Original line number Original line Diff line number Diff line /* * 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 No newline at end of file
bootstat/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -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 { Loading
bootstat/boot_event_record_store.cpp +2 −8 Original line number Original line Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 Loading
bootstat/boot_event_record_store_test.cpp +3 −12 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading @@ -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() { Loading Loading @@ -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"); Loading @@ -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"); Loading