blob: f0eff445eace49a89f23e5a39b0a5b024a5a6f13 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2013 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
David Zeuthenf413fe52013-04-22 14:04:39 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#include "update_engine/common/clock.h"
David Zeuthenf413fe52013-04-22 14:04:39 -070018
19#include <time.h>
20
21namespace chromeos_update_engine {
22
23base::Time Clock::GetWallclockTime() {
24 return base::Time::Now();
25}
26
27base::Time Clock::GetMonotonicTime() {
28 struct timespec now_ts;
29 if (clock_gettime(CLOCK_MONOTONIC_RAW, &now_ts) != 0) {
30 // Avoid logging this as an error as call-sites may call this very
David Zeuthen3c55abd2013-10-14 12:48:03 -070031 // often and we don't want to fill up the disk. Note that this
32 // only fails if running on ancient kernels (CLOCK_MONOTONIC_RAW
33 // was added in Linux 2.6.28) so it never fails on a ChromeOS
34 // device.
35 return base::Time();
36 }
37 struct timeval now_tv;
38 now_tv.tv_sec = now_ts.tv_sec;
39 now_tv.tv_usec = now_ts.tv_nsec/base::Time::kNanosecondsPerMicrosecond;
40 return base::Time::FromTimeVal(now_tv);
41}
42
43base::Time Clock::GetBootTime() {
44 struct timespec now_ts;
45 if (clock_gettime(CLOCK_BOOTTIME, &now_ts) != 0) {
46 // Avoid logging this as an error as call-sites may call this very
47 // often and we don't want to fill up the disk. Note that this
48 // only fails if running on ancient kernels (CLOCK_BOOTTIME was
49 // added in Linux 2.6.39) so it never fails on a ChromeOS device.
David Zeuthenf413fe52013-04-22 14:04:39 -070050 return base::Time();
51 }
52 struct timeval now_tv;
53 now_tv.tv_sec = now_ts.tv_sec;
54 now_tv.tv_usec = now_ts.tv_nsec/base::Time::kNanosecondsPerMicrosecond;
55 return base::Time::FromTimeVal(now_tv);
56}
57
58} // namespace chromeos_update_engine