| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/time.h" | 5 #include "base/time.h" |
| 6 | 6 |
| 7 #include <sys/time.h> | 7 #include <sys/time.h> |
| 8 #include <time.h> | 8 #include <time.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 #else // _POSIX_MONOTONIC_CLOCK | 222 #else // _POSIX_MONOTONIC_CLOCK |
| 223 #error No usable tick clock function on this platform. | 223 #error No usable tick clock function on this platform. |
| 224 #endif // _POSIX_MONOTONIC_CLOCK | 224 #endif // _POSIX_MONOTONIC_CLOCK |
| 225 | 225 |
| 226 // static | 226 // static |
| 227 TimeTicks TimeTicks::HighResNow() { | 227 TimeTicks TimeTicks::HighResNow() { |
| 228 return Now(); | 228 return Now(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 #if defined(OS_POSIX) && defined(CLOCK_SYSTEM_TRACE) |
| 232 |
| 233 // static |
| 234 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 235 uint64_t absolute_micro; |
| 236 |
| 237 struct timespec ts; |
| 238 if (clock_gettime(CLOCK_SYSTEM_TRACE, &ts) != 0) { |
| 239 NOTREACHED() << "clock_gettime(CLOCK_SYSTEM_TRACE) failed."; |
| 240 return HighResNow(); |
| 241 } |
| 242 |
| 243 absolute_micro = |
| 244 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
| 245 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
| 246 |
| 247 return TimeTicks(absolute_micro); |
| 248 } |
| 249 |
| 250 #else // !(defined(OS_POSIX) && defined(CLOCK_SYSTEM_TRACE)) |
| 251 |
| 252 // static |
| 253 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 254 return HighResNow(); |
| 255 } |
| 256 |
| 257 #endif // defined(OS_POSIX) && defined(CLOCK_SYSTEM_TRACE) |
| 258 |
| 231 #endif // !OS_MACOSX | 259 #endif // !OS_MACOSX |
| 232 | 260 |
| 233 struct timeval Time::ToTimeVal() const { | 261 struct timeval Time::ToTimeVal() const { |
| 234 struct timeval result; | 262 struct timeval result; |
| 235 int64 us = us_ - kTimeTToMicrosecondsOffset; | 263 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 236 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 264 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 237 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 265 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
| 238 return result; | 266 return result; |
| 239 } | 267 } |
| 240 | 268 |
| 241 } // namespace base | 269 } // namespace base |
| OLD | NEW |