summaryrefslogtreecommitdiff
path: root/libartbase/base/time_utils.h
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2025-03-21 03:40:36 -0700
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2025-03-21 03:40:36 -0700
commita7652079683fc97ef40b793312c39a613523262c (patch)
tree55ac1df9ea1d449630016889fbf480dfb528777c /libartbase/base/time_utils.h
parent09ac8285d7ad56b01982c02fdcc81741a3697ade (diff)
parentaa405ccd29b7317dfe499fa63cc9fdaef2f049fb (diff)
Add an artd method to create an SDC file. am: aa405ccd29
Original change: https://android-review.googlesource.com/c/platform/art/+/3540979 Change-Id: I37d556aa308550170f8cf8ec8a0e8ccd2b99944e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'libartbase/base/time_utils.h')
-rw-r--r--libartbase/base/time_utils.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/libartbase/base/time_utils.h b/libartbase/base/time_utils.h
index dd73b1c951..ddabb1289f 100644
--- a/libartbase/base/time_utils.h
+++ b/libartbase/base/time_utils.h
@@ -26,6 +26,8 @@
#include <cstdint>
#include <string>
+#include "android-base/logging.h"
+
namespace art {
enum TimeUnit {
@@ -123,6 +125,13 @@ void NanoSleep(uint64_t ns);
// time corresponding to the indicated clock value plus the supplied offset.
void InitTimeSpec(bool absolute, int clock, int64_t ms, int32_t ns, timespec* ts);
+// Converts `timespec` to nanoseconds. The return value can be negative, which should be interpreted
+// as a time before the epoch.
+static constexpr int64_t TimeSpecToNs(timespec ts) {
+ DCHECK_GE(ts.tv_nsec, 0); // According to POSIX.
+ return static_cast<int64_t>(ts.tv_sec) * INT64_C(1000000000) + ts.tv_nsec;
+}
+
} // namespace art
#endif // ART_LIBARTBASE_BASE_TIME_UTILS_H_