summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
Diffstat (limited to 'init')
-rw-r--r--init/Android.mk2
-rw-r--r--init/init.cpp4
-rw-r--r--init/service.cpp2
-rw-r--r--init/service.h6
-rw-r--r--init/util.cpp17
-rw-r--r--init/util.h26
6 files changed, 29 insertions, 28 deletions
diff --git a/init/Android.mk b/init/Android.mk
index 53ef2d07c..9e61fb2f6 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -36,7 +36,7 @@ LOCAL_MODULE := init_parser_tests
LOCAL_SRC_FILES := \
parser/tokenizer_test.cpp \
-LOCAL_STATIC_LIBRARIES := libbase libinit_parser
+LOCAL_STATIC_LIBRARIES := libinit_parser
LOCAL_CLANG := true
include $(BUILD_HOST_NATIVE_TEST)
endif
diff --git a/init/init.cpp b/init/init.cpp
index 4af0656c0..43f601f69 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -40,7 +40,6 @@
#include <selinux/label.h>
#include <selinux/android.h>
-#include <android-base/chrono_utils.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
@@ -69,7 +68,6 @@
#include "util.h"
#include "watchdogd.h"
-using android::base::boot_clock;
using android::base::StringPrintf;
struct selabel_handle *sehandle;
@@ -752,7 +750,7 @@ int main(int argc, char** 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.
umask(0);
diff --git a/init/service.cpp b/init/service.cpp
index cbdc4a8f8..e186f27a8 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -32,7 +32,6 @@
#include <selinux/selinux.h>
-#include <android-base/chrono_utils.h>
#include <android-base/file.h>
#include <android-base/parseint.h>
#include <android-base/stringprintf.h>
@@ -48,7 +47,6 @@
#include "property_service.h"
#include "util.h"
-using android::base::boot_clock;
using android::base::ParseInt;
using android::base::StringPrintf;
using android::base::WriteStringToFile;
diff --git a/init/service.h b/init/service.h
index 3dc0e53a2..013e65f04 100644
--- a/init/service.h
+++ b/init/service.h
@@ -25,8 +25,6 @@
#include <string>
#include <vector>
-#include <android-base/chrono_utils.h>
-
#include "action.h"
#include "capabilities.h"
#include "descriptors.h"
@@ -137,8 +135,8 @@ private:
unsigned flags_;
pid_t pid_;
- android::base::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_started_; // time of last start
+ boot_clock::time_point time_crashed_; // first crash within inspection window
int crash_count_; // number of times crashed within window
uid_t uid_;
diff --git a/init/util.cpp b/init/util.cpp
index f59ba82e1..888a36652 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -51,8 +51,6 @@
#include "property_service.h"
#include "util.h"
-using android::base::boot_clock;
-
static unsigned int do_decode_uid(const char *s)
{
unsigned int v;
@@ -201,16 +199,11 @@ bool write_file(const char* path, const char* content) {
return success;
}
-Timer::Timer() : start_(boot_clock::now()) {
-}
-
-double Timer::duration_s() const {
- typedef std::chrono::duration<double> double_duration;
- 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();
+boot_clock::time_point boot_clock::now() {
+ timespec ts;
+ clock_gettime(CLOCK_BOOTTIME, &ts);
+ return boot_clock::time_point(std::chrono::seconds(ts.tv_sec) +
+ std::chrono::nanoseconds(ts.tv_nsec));
}
int mkdir_recursive(const char *pathname, mode_t mode)
diff --git a/init/util.h b/init/util.h
index 4444427ea..5c38dc3c9 100644
--- a/init/util.h
+++ b/init/util.h
@@ -25,8 +25,6 @@
#include <ostream>
#include <string>
-#include <android-base/chrono_utils.h>
-
#define COLDBOOT_DONE "/dev/.coldboot_done"
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 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 {
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:
- android::base::boot_clock::time_point start_;
+ boot_clock::time_point start_;
};
std::ostream& operator<<(std::ostream& os, const Timer& t);