blob: ac8945b61f335ec78d7a5d6fc47a95a8ddc9681b [file] [log] [blame]
David Zeuthenf413fe52013-04-22 14:04:39 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "update_engine/clock.h"
6
7#include <time.h>
8
9namespace chromeos_update_engine {
10
11base::Time Clock::GetWallclockTime() {
12 return base::Time::Now();
13}
14
15base::Time Clock::GetMonotonicTime() {
16 struct timespec now_ts;
17 if (clock_gettime(CLOCK_MONOTONIC_RAW, &now_ts) != 0) {
18 // Avoid logging this as an error as call-sites may call this very
David Zeuthen3c55abd2013-10-14 12:48:03 -070019 // often and we don't want to fill up the disk. Note that this
20 // only fails if running on ancient kernels (CLOCK_MONOTONIC_RAW
21 // was added in Linux 2.6.28) so it never fails on a ChromeOS
22 // device.
23 return base::Time();
24 }
25 struct timeval now_tv;
26 now_tv.tv_sec = now_ts.tv_sec;
27 now_tv.tv_usec = now_ts.tv_nsec/base::Time::kNanosecondsPerMicrosecond;
28 return base::Time::FromTimeVal(now_tv);
29}
30
31base::Time Clock::GetBootTime() {
32 struct timespec now_ts;
33 if (clock_gettime(CLOCK_BOOTTIME, &now_ts) != 0) {
34 // Avoid logging this as an error as call-sites may call this very
35 // often and we don't want to fill up the disk. Note that this
36 // only fails if running on ancient kernels (CLOCK_BOOTTIME was
37 // added in Linux 2.6.39) so it never fails on a ChromeOS device.
David Zeuthenf413fe52013-04-22 14:04:39 -070038 return base::Time();
39 }
40 struct timeval now_tv;
41 now_tv.tv_sec = now_ts.tv_sec;
42 now_tv.tv_usec = now_ts.tv_nsec/base::Time::kNanosecondsPerMicrosecond;
43 return base::Time::FromTimeVal(now_tv);
44}
45
46} // namespace chromeos_update_engine